inp = input().split("^") a = int(inp[0]) b = int(inp[1]) c = int(inp[2]) M = 1000000007 print(pow(pow(a, b, M), c, M), pow(a, pow(b, c), M))