N = int(eval(input()))

A = [0]*N

for i in range(N):

  A[i] = int(eval(input()))

#print(A)

M = max(A)

ind = A.index(M)

#print(ind)

A.pop(ind)

m = max(A)

for i in range(N):

  #print(i)

  if i != ind:

    print(M)

  else:

    print(m)

    
def solve():

    N = int(input())

    A = [int(input()) for _ in range(N)]

    B = sorted(A)

    m = B[-1]

    m2 = B[-2]

    ans = []

    for a in A:

        if a!=m:

            ans.append(m)

        else:

            ans.append(m2)

    return ans

print(*solve(),sep='\n')

N = int(eval(input()))
A = [0] * N
for i in range(N):
    A[i] = int(eval(input()))
# print(A)
M = max(A)
ind = A.index(M)
# print(ind)
A.pop(ind)
m = max(A)
for i in range(N):
    # print(i)
    if i != ind:
        print(M)
    else:
        print(m)

def solve():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    B = sorted(A)
    m = B[-1]
    m2 = B[-2]
    ans = []
    for a in A:
        if a != m:
            ans.append(m)
        else:
            ans.append(m2)
    return ans


print(*solve(), sep="\n")

-N = int(eval(input())) -A = [0] * N -for i in range(N): -    A[i] = int(eval(input())) -# print(A) -M = max(A) -ind = A.index(M) -# print(ind) -A.pop(ind) -m = max(A) -for i in range(N): -    # print(i) -    if i != ind: -        print(M) -    else: -        print(m) +def solve(): +    N = int(input()) +    A = [int(input()) for _ in range(N)] +    B = sorted(A) +    m = B[-1] +    m2 = B[-2] +    ans = [] +    for a in A: +        if a != m: +            ans.append(m) +        else: +            ans.append(m2) +    return ans + + +print(*solve(), sep="\n")