n = int(eval(input()))

l = []

m1 = 0

m2 = 0

for i in range(n):

    num = int(eval(input()))

    l.append(num)

    if num > m1:

        m1 = num

    elif num > m2:

        m2 = num



for i in range(n):

    if l[i] != m1:

        print(m1)

    else:

        print(m2)

import sys

input = sys.stdin.readline



n = int(eval(input()))

l = []

m1 = 0

m2 = 0

for i in range(n):

    num = int(eval(input()))

    l.append(num)

    if num > m1:

        m1 = num

    elif num > m2:

        m2 = num



for i in range(n):

    if l[i] != m1:

        print(m1)

    else:

        print(m2)

n = int(eval(input()))
l = []
m1 = 0
m2 = 0
for i in range(n):
    num = int(eval(input()))
    l.append(num)
    if num > m1:
        m1 = num
    elif num > m2:
        m2 = num
for i in range(n):
    if l[i] != m1:
        print(m1)
    else:
        print(m2)

import sys

input = sys.stdin.readline
n = int(eval(input()))
l = []
m1 = 0
m2 = 0
for i in range(n):
    num = int(eval(input()))
    l.append(num)
    if num > m1:
        m1 = num
    elif num > m2:
        m2 = num
for i in range(n):
    if l[i] != m1:
        print(m1)
    else:
        print(m2)

+import sys + +input = sys.stdin.readline