def main():
  N = int(input())

  max_left = [0] * N
  max_right = [0] * N

  ary = []

  for i in range(N):
    v = int(input())
    ary.append(v)

  for i in range(N - 1):
    max_left[i+1] = max(max_left[i], ary[i])

  for i in range(N - 1, 0, -1):
    max_right[i-1] = max(max_right[i], ary[i])

  for i in range(N):
	v = max(max_left[i], max_right[i])
	print(v)

main()
