#include template T in() { abort(); return T(); } template<> std::string in() { std::string str; std::cin >> str; return str; } template<> int in() { int x; scanf("%d", &x); return x; } template void out(T x) { abort(); } template<> void out(std::string x) { std::cout << x << std::endl; } template<> void out(int x) { printf("%d\n", x); } long modpow(long x, long n, long m) { assert( not ( x == 0 and n == 0 ) ); x %= m; if( x == 0 ) return 0; if( n == 0 ) return 1; long res = 1; long p = x; while( n != 0 ) { if( n & 0x01 ) res = (res * p) % m; p = (p * p) % m; n >>= 1; } return res; } constexpr long mod = 1000000007; // (A ^ B) ^ C void solve1(long a, long b, long c) { printf("%ld ", modpow(modpow(a, b, mod), c, mod)); } // A ^ (B ^ C) void solve2(long a, long b, long c) { printf("%ld\n", modpow(a, modpow(b, c, mod - 1), mod)); } int main() { char buf[256]; scanf("%s", buf); long a, b, c; sscanf(buf, "%ld^%ld^%ld", &a, &b, &c); solve1(a, b, c); solve2(a, b, c); return 0; }