

def solve():

  n = int(eval(input()))

  maxi = -10

  maxi2 = -10

  place = -1

  for i in range(n):

    a = int(eval(input()))

    if a>maxi:

      maxi2 = maxi

      maxi = a

      place = i

    else:

      maxi2 = max(maxi2,a)

  for j in range(n):

    if place == j:

      print(maxi2)

    else:

      print(maxi)

  

solve()
import sys

input = sys.stdin.readline

  

def solve():

  n = int(eval(input()))

  maxi = -10

  maxi2 = -10

  place = -1

  for i in range(n):

    a = int(eval(input()))

    if a>maxi:

      maxi2 = maxi

      maxi = a

      place = i

    else:

      maxi2 = max(maxi2,a)

  for j in range(n):

    if place == j:

      print(maxi2)

    else:

      print(maxi)

  

solve()
def solve():
    n = int(eval(input()))
    maxi = -10
    maxi2 = -10
    place = -1
    for i in range(n):
        a = int(eval(input()))
        if a > maxi:
            maxi2 = maxi
            maxi = a
            place = i
        else:
            maxi2 = max(maxi2, a)
    for j in range(n):
        if place == j:
            print(maxi2)
        else:
            print(maxi)


solve()

import sys

input = sys.stdin.readline


def solve():
    n = int(eval(input()))
    maxi = -10
    maxi2 = -10
    place = -1
    for i in range(n):
        a = int(eval(input()))
        if a > maxi:
            maxi2 = maxi
            maxi = a
            place = i
        else:
            maxi2 = max(maxi2, a)
    for j in range(n):
        if place == j:
            print(maxi2)
        else:
            print(maxi)


solve()

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