n=int(eval(input()))

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

c=sorted(a)

b=max(a)

for i in range(n):

  if a[i]==b:

    print((c[n-2]))

  else:

    print(b)
n=int(eval(input()))

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

b=sorted(a)

if b[n-1]==b[n-2]:

  for i in a:

    print((b[n-1]))

else:

  for i in a:

    if i==b[n-1]:

      print((b[n-2]))

    else:

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

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

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