a,b,c=map(int,raw_input().split('^')) print(pow(pow(a,b,M),c,M),pow(a,pow(b,c,M),M))