import copy

n = int(eval(input()))

a = [int(eval(input())) for _ in range(n)]

b = copy.deepcopy(a)

a.sort(reverse=True)

for v in b:

  if v==a[0]:

    print((a[1]))

  else:

    print((a[0]))
n = int(eval(input()))

a = [int(eval(input())) for _ in range(n)]

b = sorted(a)

for v in a:

  print((b[(v<b[-1])-2]))
import copy

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = copy.deepcopy(a)
a.sort(reverse=True)
for v in b:
    if v == a[0]:
        print((a[1]))
    else:
        print((a[0]))

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = sorted(a)
for v in a:
    print((b[(v < b[-1]) - 2]))

-import copy - -b = copy.deepcopy(a) -a.sort(reverse=True) -for v in b: -    if v == a[0]: -        print((a[1])) -    else: -        print((a[0])) +b = sorted(a) +for v in a: +    print((b[(v < b[-1]) - 2]))