import copy

N=int(eval(input()))

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



a=max(A)

k=A.count(a)#リストの最大数の個数をカウント

if k>=2:

  for i in range(N):

    print(a)

else:

  b=A.index(a)

  for i in range(N):

    if i != b:

      print(a)

    else:

      s=sorted(A)

      print((s[N-2]))
import copy



def main():

  N=int(eval(input()))

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



  a=max(A)

  k=A.count(a)#リストの最大数の個数をカウント

  if k>=2:

    for i in range(N):

      print(a)

  else:

    b=A.index(a)

    for i in range(N):

      if i != b:

        print(a)

      else:

        s=sorted(A)

        print((s[N-2]))



if __name__ == "__main__":

    main()
import copy

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
a = max(A)
k = A.count(a)  # リストの最大数の個数をカウント
if k >= 2:
    for i in range(N):
        print(a)
else:
    b = A.index(a)
    for i in range(N):
        if i != b:
            print(a)
        else:
            s = sorted(A)
            print((s[N - 2]))

import copy


def main():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]
    a = max(A)
    k = A.count(a)  # リストの最大数の個数をカウント
    if k >= 2:
        for i in range(N):
            print(a)
    else:
        b = A.index(a)
        for i in range(N):
            if i != b:
                print(a)
            else:
                s = sorted(A)
                print((s[N - 2]))


if __name__ == "__main__":
    main()

-N = int(eval(input())) -A = [int(eval(input())) for _ in range(N)] -a = max(A) -k = A.count(a)  # リストの最大数の個数をカウント -if k >= 2: -    for i in range(N): -        print(a) -else: -    b = A.index(a) -    for i in range(N): -        if i != b: + +def main(): +    N = int(eval(input())) +    A = [int(eval(input())) for _ in range(N)] +    a = max(A) +    k = A.count(a)  # リストの最大数の個数をカウント +    if k >= 2: +        for i in range(N): -        else: -            s = sorted(A) -            print((s[N - 2])) +    else: +        b = A.index(a) +        for i in range(N): +            if i != b: +                print(a) +            else: +                s = sorted(A) +                print((s[N - 2])) + + +if __name__ == "__main__": +    main()