require'bigdecimal' d=1e9+7 a,b,c=gets.split(?^).map{|i|BigDecimal(i)%d} puts [(a**b%d)**c%d,a**(b**c%d)%d].map{|i|i.to_s ?f}*" "