N = gets.strip.to_i
h = Hash.new(0)
ary = []
N.times do |i|
  a = gets.strip.to_i
  ary[i] = a
  h[a] += 1
end

h =  h.sort.reverse

if h.size.eql?(1)
  a = h.first[0]
  N.times { puts a }
else
  a = h[0][0]
  b = h[1][0]
  ary.each { |n| puts n.eql?(a) ? b : a }
end