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