import Data.List
main = interact $ unlines . return . unwords . map (exchange "apple" "peach") . words
exchange s1 s2 s = rewrite "" s
 where
  rewrite s' s
   | null s = s'
   | isPrefixOf s1 s = rewrite (s' ++ s2) (s \\ s1)
   | isPrefixOf s2 s = rewrite (s' ++ s1) (s \\ s2)
   | otherwise = rewrite (s' ++ [head s]) (tail s)
