n=int(eval(input()))

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

a.sort()

c=a[-1][0]

d=a[-2][0]

e=a[-1][1]

for i in range(n):

  if i==e:print(d)

  else:print(c)
n=int(eval(input()))

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

b=sorted(a)

m=b[-1]

mm=b[-2]

for i in a:

  if i==m:print(mm)

  else:print(m)
n = int(eval(input()))
a = [[int(eval(input())), i] for i in range(n)]
a.sort()
c = a[-1][0]
d = a[-2][0]
e = a[-1][1]
for i in range(n):
    if i == e:
        print(d)
    else:
        print(c)

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

-a = [[int(eval(input())), i] for i in range(n)] -a.sort() -c = a[-1][0] -d = a[-2][0] -e = a[-1][1] -for i in range(n): -    if i == e: -        print(d) +a = [int(eval(input())) for _ in range(n)] +b = sorted(a) +m = b[-1] +mm = b[-2] +for i in a: +    if i == m: +        print(mm) -        print(c) +        print(m)