n=int(eval(input()))

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

b=sorted(a)

m1=b[-1]

m2=b[-2]

for c in a:

  if c == m1:

    print(m2)

  else:

    print(m1)

  
n,*a=list(map(int,open(0).read().split()))

b=sorted(a)[::-1]

ma1=b[0]

ma2=b[1]

for i in a:

  if ma1==i:

    print(ma2)

  else:

    print(ma1)

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

n, *a = list(map(int, open(0).read().split()))
b = sorted(a)[::-1]
ma1 = b[0]
ma2 = b[1]
for i in a:
    if ma1 == i:
        print(ma2)
    else:
        print(ma1)

-n = int(eval(input())) -a = [int(eval(input())) for i in range(n)] -b = sorted(a) -m1 = b[-1] -m2 = b[-2] -for c in a: -    if c == m1: -        print(m2) +n, *a = list(map(int, open(0).read().split())) +b = sorted(a)[::-1] +ma1 = b[0] +ma2 = b[1] +for i in a: +    if ma1 == i: +        print(ma2) -        print(m1) +        print(ma1)