#include <bits/stdc++.h>
using namespace std;
long long ta(int a, int x)
{
if (x == 0) return 1;
if (x % 2 == 1) return a * ta(a, x-1);
long long t = ta(a, x/2); return t * t;
}
long long tb(int b, int y)
{
if (y == 0) return 1;
if (y % 2 == 1) return b * tb(b, y-1);
long long l = tb(b, y/2); return l * l;
}
int main()
{
int a, x,b,y;
cin >> a >> x;
cin >> b >> y;
cout <<ta(a,x)<<" "<<tb(b,y)<<endl;
if(ta(a,x)>tb(b,y))
cout <<a<<"^"<<x;
else if(ta(a,x)<tb(b,y))
cout <<b<<"^"<<y;
else
cout<<"0";
}