#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
/*
\\\\ \\ \\ \\ \\ \\ \\ \\ || || || || || || // // // // // // // ////
\\\\ \\ \\ \\ \\ \\ \\ _ooOoo_ // // // // // // ////
\\\\ \\ \\ \\ \\ \\ o8888888o // // // // // ////
\\\\ \\ \\ \\ \\ 88" . "88 // // // // ////
\\\\ \\ \\ \\ (| -_- |) // // // ////
\\\\ \\ \\ O\ = /O // // ////
\\\\ \\ ____/`---'\____ // ////
\\\\ .' \\| |// `. ////
//== / \\||| : |||// \ ==\\
//== / _||||| -:- |||||- \ ==\\
//== | | \\\ - /// | | ==\\
//== | \_| ''\---/'' | | ==\\
//== \ .-\__ `-` ___/-. / ==\\
//== ___`. .' /--.--\ `. . ___ ==\\
//== ."" '< `.___\_<|>_/___.' >' "". ==\\
//== | | : `- \`.;`\ _ /`;.`/ - ` : | | \\\\
//// \ \ `-. \_ __\ /__ _/ .-` / / \\\\
//// ========`-.____`-.___\_____/___.-`____.-'======== \\\\
//// `=---=' \\\\
//// // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \\ \\\\
//// // // 佛祖保佑 永无BUG 永不修改 \\ \\ \\\\
//// // // // // // || || || || || || || || || || \\ \\ \\ \\ \\ \\\\
*/
int a[1000010],b[1000010],c[1000010];
int main(){
int x,y;
while(1) {
scanf("%d",&x);
if(x==-1) break;
scanf("%d",&y);
a[x]+=y;
}
while(1) {
scanf("%d",&x);
if(x==-1) break;
scanf("%d",&y);
b[x]+=y;
}
for(int i=0; i<=1000; i++) {
for(int j=0; j<=1000; j++) {
c[i+j]+=(a[i]*b[j]);
}
}
bool flag=0;
for(int i=100010; i>=0; i--) {
if(c[i]==0) continue;
if(c[i]>0&&flag) printf("+");
if(c[i]<0) {
printf("-");
c[i]=-c[i];
}
if(c[i]!=1||c[i]==1&&i==0) {
printf("%d",c[i]);
}
if(i>0) printf("x^%d",i);
flag=1;
}
return 0;
}