import copy

n=int(eval(input()))

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

t=copy.deepcopy(a)

t.sort()

for i in a:

  if i==t[-1]:

    print((t[-2]))

    

  else:

    print((t[-1]))
n=int(eval(input()))

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

sa=sorted(a)



for i in a:

  if sa[-1]==i:

    print((sa[-2]))

  else:

    print((sa[-1]))
import copy

n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
t = copy.deepcopy(a)
t.sort()
for i in a:
    if i == t[-1]:
        print((t[-2]))
    else:
        print((t[-1]))

n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
sa = sorted(a)
for i in a:
    if sa[-1] == i:
        print((sa[-2]))
    else:
        print((sa[-1]))

-import copy - -t = copy.deepcopy(a) -t.sort() +sa = sorted(a) -    if i == t[-1]: -        print((t[-2])) +    if sa[-1] == i: +        print((sa[-2])) -        print((t[-1])) +        print((sa[-1]))