#include <iostream>
#include <cmath>
using namespace std;

struct DonThuc {
    int he_so;
    int he_so_mu;
};

class Bai3 {
private:
    DonThuc *arr;
    int sl;

public:
    Bai3(int s = 0) {
        sl = s;
        arr = (sl > 0) ? new DonThuc[sl] : nullptr;
    }
    ~Bai3() {
        delete[] arr;
        arr = nullptr;
        sl = 0;
    }
    void Nhap() {
        cin >> sl;
        delete[] arr;
        arr = new DonThuc[sl];
        for (int i = 0; i < sl; i++) {
            cin >> arr[i].he_so >> arr[i].he_so_mu;
        }
    }
    void Xuat() {
        bool co_so_hang = false;
        for (int i = 0; i < sl; i++) {
            if (arr[i].he_so == 0) continue;
            if (co_so_hang) {
                if (arr[i].he_so > 0) cout << " + ";
                else cout << " - ";
            } else {
                if (arr[i].he_so < 0) cout << "-";
            }
            int h = abs(arr[i].he_so);
            int m = arr[i].he_so_mu;
            if (m == 0) {
                cout << h;
            } else {
                if (h != 1) cout << h;
                cout << "x";
                if (m != 1) {
                    if (m >= 0) cout << "^" << m;
                    else cout << "^(" << m << ")";
                }
            }
            co_so_hang = true;
        }
        if (!co_so_hang) cout << "0";
        cout << "\n";
    }
    void TinhGiaTri(double x) {
        double tong = 0;
        for (int i = 0; i < sl; i++) {
            tong += arr[i].he_so * pow(x, arr[i].he_so_mu);
        }
        cout << "Gia tri cua da thuc tai " << x << " la: " << tong << "\n";
    }
    void DaoHamCap1() {
        bool co_so_hang = false;
        for (int i = 0; i < sl; i++) {
            if (arr[i].he_so_mu == 0 || arr[i].he_so == 0) continue;
            int moi_hs = arr[i].he_so * arr[i].he_so_mu;
            int moi_mu = arr[i].he_so_mu - 1;
            if (co_so_hang) {
                if (moi_hs > 0) cout << " + ";
                else cout << " - ";
            } else {
                if (moi_hs < 0) cout << "-";
            }
            int h = abs(moi_hs);
            if (moi_mu == 0) {
                cout << h;
            } else {
                if (h != 1) cout << h;
                cout << "x";
                if (moi_mu != 1) {
                    if (moi_mu >= 0) cout << "^" << moi_mu;
                    else cout << "^(" << moi_mu << ")";
                }
            }
            co_so_hang = true;
        }
        if (!co_so_hang) cout << "0";
        cout << "\n";
    }
};

int main() {
    Bai3 a;
    a.Nhap();
    a.Xuat();
    double x;
    cin >> x;
    a.TinhGiaTri(x);
    a.DaoHamCap1();
    return 0;
}
