a, b, c = map(int, raw_input().split('^')) mod = 10**9 + 7 x = pow(a**b, c, mod) y = pow(a, b**c, mod) print x, y