def read_line_to_i; read_line.split(" ").map(&.to_i) end

n = read_line_to_i[0]

a_list = [] of Int32

n.times {
  a_list << read_line_to_i[0]
}

biggest_number = 0
second_biggest_number = 0

a_list.each {|e|
  if e > biggest_number
    biggest_number = e
    second_biggest_number = biggest_number
  elsif e > second_biggest_number
    second_biggest_number = biggest_number
  end
}

a_list.each_index {|i|
  p a_list[i] == biggest_number ? second_biggest_number : biggest_number
}

