a,b,c=map(int,raw_input().split('^')) M=10**9+7 print pow(pow(a,b,M),c,M),pow(a,pow(b,c,M-1),M)if a%M else 0