arr = []
gets.chomp.to_i.times do |i|
  arr << gets.chomp.to_i
end

sorted_arr = arr.sort
arr.each_with_index do |i, idx|
  _arr = sorted_arr.dup
  backup = _arr.delete(arr[idx])
  p _arr[-1] || backup
end
