#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Term {
long long c;
string v;
};
Term parseTerm(const string& s) {
long long c = 0;
int sign = 1;
size_t i = 0;
if (i < s.size() && s[i] == '+') i++;
else if (i < s.size() && s[i] == '-') { sign = -1; i++; }
bool has_digit = false;
while(i < s.size() && isdigit(s[i])) {
c = c * 10 + (s[i] - '0');
has_digit = true;
i++;
}
if (!has_digit) c = 1;
c *= sign;
return {c, s.substr(i)};
}
string formatSq(const Term& t, bool isFirst) {
long long c2 = t.c * t.c;
if (c2 == 0) return "";
string res = "";
if (c2 > 0 && !isFirst) res += "+";
if (t.v.empty()) {
res += to_string(c2);
} else {
if (c2 != 1) res += to_string(c2);
res += t.v + "^2";
}
return res;
}
string formatCross(const Term& t1, const Term& t2, bool isFirst) {
long long c = 2 * t1.c * t2.c;
if (c == 0) return "";
string res = "";
if (c > 0 && !isFirst) res += "+";
else if (c < 0) { res += "-"; c = -c; }
if (t1.v.empty() && t2.v.empty()) {
res += to_string(c);
} else {
if (c != 1) res += to_string(c);
res += t1.v + t2.v;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string line;
while (getline(cin, line)) {
string full = "";
for (char c : line) {
if (c != ' ' && c != '\t' && c != '\r') full += c;
}
if (full.empty()) continue;
size_t p1 = full.find('(');
size_t p2 = full.find(')');
if (p1 == string::npos || p2 == string::npos || p2 < p1) {
p1 = -1;
p2 = full.length();
size_t p_sq = full.find("^2");
if(p_sq != string::npos) p2 = p_sq;
}
string in = full.substr(p1 + 1, p2 - p1 - 1);
vector<Term> T;
string current = "";
for(char ch : in) {
if(ch == '+' || ch == '-') {
if(!current.empty()) {
T.push_back(parseTerm(current));
}
current = (ch == '-') ? "-" : "";
} else {
current += ch;
}
}
if(!current.empty()) {
T.push_back(parseTerm(current));
}
if (T.empty()) continue;
string ans = "";
if (T.size() == 2) {
ans += formatSq(T[0], true);
ans += formatCross(T[0], T[1], false);
ans += formatSq(T[1], false);
} else {
bool isFirst = true;
for (size_t i = 0; i < T.size(); i++) {
ans += formatSq(T[i], isFirst);
isFirst = false;
}
for (size_t i = 0; i < T.size(); i++) {
for (size_t j = i + 1; j < T.size(); j++) {
ans += formatCross(T[i], T[j], isFirst);
isFirst = false;
}
}
}
if (full.find("ex:") == 0) {
cout << "res:" << ans << "\n";
} else {
cout << ans << "\n";
}
}
return 0;
}