{-# LANGUAGE BangPatterns #-} import Control.Applicative ((<$>)) import Data.Int (Int64) import Data.List.Split (splitOn) modexp :: Integral a => a -> a -> a -> a modexp b ex m | ex == 0 = 1 | even ex = flip mod m $ square $ flip mod m $ modexp b (div ex 2) m | otherwise = flip mod m $ mod b m * mod (modexp b (ex - 1) m) m where square x = x * x p :: Integral a => a p = 10 ^ 9 + 7 main :: IO () main = do ![a, b, c] <- fmap read . splitOn "^" <$> getLine :: IO [Int64] let !x = modexp (modexp a b p) c p let !y = modexp a (modexp b c $ p - 1) p putStrLn . unwords . fmap show $ [x, y]