import Control.Applicative import Control.Monad import Data.List replace x = map (\ c -> if c == x then ' ' else c) modpow x y m | y == 0 = 1 | y `mod` 2 == 0 = modpow ((x * x) `rem` m) (y `quot` 2) m | otherwise = (x * modpow x (y - 1) m) `rem` m solve1 a b c m | a == 0 = 0 | otherwise = modpow (modpow a b m) c m solve2 a b c m | a == 0 = 0 | otherwise = modpow a (modpow b c (m - 1)) m main = do [a, b, c] <- map read . words . replace '^' <$> getLine :: IO [Integer] let m = 10 ^ 9 + 7 putStrLn $ show (solve1 a b c m) ++ " " ++ show (solve2 a b c m)