N = gets.to_i
memo = Hash.new 0
A = N.times.map do
  memo[a = gets.to_i] += 1
  a
end
memo = memo.sort.reverse
A.each do |n|
  puts n < memo[0][0] ? memo[0][0] : memo[0][1] > 1 ? memo[0][0] : memo[1][0]
end