while line = gets
  puts line.chomp.split(" ").each_with_index{ |word, idx|
    case true
    when word.include?("apple") then word.sub!(/apple/, "peach")
    when word.include?("peach") then word.sub!(/peach/, "apple")
    end
  }.join(" ")
end