You are given a sequence of length N: A_1, A_2, ..., A_N.
For each integer i between 1 and N (inclusive), answer the following question:
 - Find the maximum value among the N-1 elements other than A_i in the sequence.

-----Constraints-----
 - 2 \leq N \leq 200000
 - 1 \leq A_i \leq 200000
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
A_1
:
A_N

-----Output-----
Print N lines. The i-th line (1 \leq i \leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.

-----Sample Input-----
3
1
4
3

-----Sample Output-----
4
3
4

 - The maximum value among the two elements other than A_1, that is, A_2 = 4 and A_3 = 3, is 4.
 - The maximum value among the two elements other than A_2, that is, A_1 = 1 and A_3 = 3, is 3.
 - The maximum value among the two elements other than A_3, that is, A_1 = 1 and A_2 = 4, is 4.

Difficulty: introductory

Starter code:

Solutions:
import copy
n = int(input())
a = []
for i in range(n):
  s = int(input())
  a.append(s)
b = copy.copy(a)
a.sort(reverse=True)
c = b.index(a[0])
for j in b:
  if j == b[c]:
    print(a[1])
  else:
    print(a[0])

N = int(input())
l = [int(input()) for _ in range(N)]
largest = max(l)
largest_index = l.index(max(l))
second_largest = sorted(l)[-2]
second_largest_index = l.index(second_largest)

for idx, n in enumerate(l):
  if idx == largest_index:
    print(second_largest)
  else:
    print(largest)


arr = []
for _ in range(int(input())):
  arr.append(int(input()))
arr2 = arr.copy()
arr2.sort()
z = arr2[-1]
zz = arr2[-2]
for k in arr:
  if k != z:
    print(z)
  else:
    print(zz)
    


n = int(input())
a_l = [ int(input()) for _ in range(n)]

l = []
r = []
l_max = 0
r_max = 0
for i in range(n):
    l_max = max(l_max, a_l[i])
    r_max = max(r_max, a_l[-i-1])
    l.append(l_max)
    r.append(r_max)
for i in range(n):
    if i == 0:
        t_l = 0
    else:
        t_l = l[i-1]
    if i == n-1:
        t_r = 0
    else:
        t_r = r[-i-2]
    print(max([t_l,t_r]))

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

b = sorted(a)
for i in a:
    print(b[-1] if i != b[-1] else b[-2])

n = int(input())
a = list(int(input()) for _ in range(n))
b = sorted(a, reverse=True)
for i in range(n):
    if a[i] != b[0]:
      print(b[0])
    else: print(b[1])

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

sorted_a = sorted(A, reverse= True)
max_val, next_max_val = sorted_a[:2]
for a in A:
  if a == max_val:
    print(next_max_val)
  else:
    print(max_val)

import copy

N = int(input())
A = []
for i in range(N) :
    A.append(int(input()))

amax = max(A)
amaxindex = A.index(amax)
#print(A,amax,amaxindex)
B = copy.deepcopy(A)
del B[amaxindex]
bmax = max(B)
#print(B,bmax)

#print(amax,bmax)
for i in range(N) :
    if i == amaxindex :
        print(bmax)
    else :
        print(amax)

n = int(input())
a = [int(input()) for i in range(n)]
x = sorted(a)[-1]
y = sorted(a)[-2]
for i in range(n):
    if a[i] != x:
        print(x)
    else:
        print(y)

N = int(input())
ls = []
for i in range(N):
    ls.append(int(input()))
first_val = sorted(ls, reverse=True)[0]
second_val = sorted(ls, reverse=True)[1]
for i in ls:
    if i == first_val:
        print(second_val)
    else:
        print(first_val)

N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())

mx = max(A)
mxidx = A.index(mx)

for i in range(N):
    if i == mxidx:
        B = A[0:i] + A[i+1:N]
        print(max(B))
    else:
        print(mx)

N=int(input())
nums=[]
for i in range(N):
    A=int(input())
    nums.append(A)
    
nums2=sorted(nums,reverse=True)

for i in nums:
    if i==nums2[0]:
        print(nums2[1])
    else:
        print(nums2[0])

import copy
n = int(input())
an = [int(input()) for i in range(n) ]
bn = copy.copy(an)
top = max(an)
an.remove(top)
top2 = max(an)


for x in bn:
  if x == top:
    print(top2)
  else:
    print(top)


import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    N = i_input()
    A = [i_input() for i in range(N)]

    L = list(set(A))
    L.sort()
    m1 = L[-1]
    cnt = A.count(m1)

    if len(L) == 1:
        m2 = m1
    else:
        m2 = L[-2]

    for i in A:
        if i == m1 and cnt == 1:
            print(m2)
        else:
            print(m1)
  
 
 
def __starting_point():
    main()
__starting_point()

n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)
for i in a:
    print(b[-1] if i != b[-1] else b[-2])

import heapq

n = int(input())
A = [int(input()) for _ in range(n)]
m1, m2 = heapq.nlargest(2, A)
print(*[m2 if a == m1 else m1 for a in A], sep='\n')

N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())
sortedA = sorted(A)
if sortedA[N-1] == sortedA[N-2]:
    for _ in range(N):
        print(sortedA[N-1])
else:
    for i in range(N):
        if A[i] != sortedA[N-1]:
            print(sortedA[N-1])
        else:
            print(sortedA[N-2])

n = int(input())
lst = []

for i in range(n):
    x = int(input())
    lst.append(x)

a = max(lst)
b = []
for i in range(n):
    if (lst[i] == a):
        b.append(i)

if (len(b) > 1):
    for i in range(n):
        print(a)

else:
    lst[b[0]] = 0
    c = max(lst)
    for i in range(n):
        if (i == b[0]):
            print(c)
        else:
            print(a)


n=int(input())
a=[int(input()) for i in range(n)]
b=a[:]
p=max(a)
b.remove(p)
q=max(b)

for i in a:
    if i!=p:
        print(p)
    else:
        print(q)

N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)
for i in A:
  if i == B[-1]:
    print(B[-2])
  else:
    print(B[-1])

N = int(input())
b = []
max_num = 0
for i in range(N):
  a = int(input())
  b.append(a)
  max_num = max(a,max_num)
max_num2 = 0  
num = b.count(max_num)
if num >1:
  for i in range(N):
    print(max_num)
elif num ==1:
  for i in b:
    if i == max_num:
      pass
    else:
      max_num2 = max(max_num2,i)
  for i in b:
    if max_num == i:
      print(max_num2)
    else:
      print(max_num)
    
  


import copy
n = int(input())
A = []
for i in range(n):
    A.append(int(input()))
B = copy.copy(A)
B.sort()
A_max = B[-1]
A_max2 = B[-2]

for i in range(n):
    if A[i] < A_max:
        print(A_max)
    elif A[i] == A_max:
        print(A_max2)


n=int(input())
a=[]
for _ in range(n):
    a.append(int(input()))

b=a.copy()

import heapq
#これを加える！！！！
def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt

b = sorted(b,reverse=True)

b1 = _heappop_max(b)
b2 = _heappop_max(b)

for i in range(n):
    if a[i]==b1:
        print(b2)
    else:
        print(b1)


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

for i in a:
  if sa[-1]==i:
    print(sa[-2])
  else:
    print(sa[-1])

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-10 18:27:16 +0900
# LastModified: 2020-09-10 18:35:34 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import Counter


def main():
    n = int(input())
    A = []
    for _ in range(n):
        A.append(int(input()))
    A_cnt = Counter(A)
    flag = 0
    A_max = max(A)
    A_next_max = sorted(A, reverse=True)[1]
    if A_cnt[A_max] > 1:
        flag = 1

    for a in A:
        if a == A_max and flag == 1:
            print(A_max)
        elif a == A_max and flag == 0:
            print(A_next_max)
        else:
            print(A_max)


def __starting_point():
    main()

__starting_point()

import sys
input = sys.stdin.readline

n = int(input())
a = list(int(input()) for _ in range(n))
b = sorted(a, reverse=True)
for i in range(n):
    if a[i] != b[0]:
      print(b[0])
    else: print(b[1])

n = int(input())
list_a = []
for i in range(n):
    list_a.append(int(input()))

from collections import Counter

counter = dict(Counter(list_a))
sorted_counter = sorted(counter, reverse=True)

for item in list_a:
    counter[item] -= 1
    for submax in sorted_counter:
        if counter[submax] == 0:
            continue
        print(submax)
        break
    counter[item] += 1

n = int(input())
max_a = 0
next_a = 0
max_loc = 0
for i in range(n):
    ai = int(input())
    if ai > max_a:
        max_a =ai
        max_loc = i
    elif ai > next_a:
        next_a = ai
if next_a == 0:
    for i in range(n):
        print(max_a)
else:
    for i in range(max_loc):
        print(max_a)
    print(next_a)
    for i in range(n-max_loc-1):
        print(max_a)

n=int(input())
a=[int(input()) for i in range(n)]
b=sorted(a,reverse=True)
first,second=b[0],b[1]

for i in range(n):
  print(second if a[i]==first else first)

n = int(input())
a = [0]
for i in range(n):
  a.append(int(input()))
a.append(0)

l = [0] * (n+2)
l[0] = 0
for i in range(1,n+1):
  l[i] = max(l[i-1], a[i])

r = [0] * (n+2)
r[n] = 0
for i in range(n,0,-1):
  r[i] = max(r[i+1], a[i])

for i in range(1,n+1):
  print(max(l[i-1],r[i+1]))

n = int(input())
L = list(int(input()) for _ in range(n))
SL = sorted(L)
first_max = SL[-1]
second_max = SL[-2]
for l in L:
  if (l == first_max):
    print(second_max)
  else:
    print(first_max)

import sys

input = sys.stdin.readline
N = int(input())

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

for i, a in enumerate(sorted(A, reverse=True)):
    if i == 0:
        first = a
    elif i == 1:
        second = a
    else:
        break
# print(first, second)

for a in A:
    if a == first:
        print(second)
    else:
        print(first)

N,*D=map(int,open(0).read().split())
S=sorted(D,reverse=True)
if S[1]==S[0]:
  [print(S[0]) for i in range(N)]
else:
  import numpy as np
  max_i=np.arange(N)[np.array(D)==S[0]]
  for i in range(N):
    if i==max_i:
      print(S[1])
    else:
      print(S[0])

n = int(input())
L = list(int(input()) for _ in range(n))
SL = sorted(L)
first_max = SL[-1]
second_max = SL[-2]
for l in L:
  if (l != first_max):
    print(first_max)
  else:
    print(second_max)

n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
a_max = max(a)
a_second = sorted(a)[-2]
for i in range(n):
	print(a_max if a[i] != a_max else a_second)

n=int(input())
a=[int(input()) for i in range(0,n)]
b=sorted(a)
for i in range(0,n):
    if b[-1]!=a[i]:
        print((b[-1]))
    else:
        print((b[-2]))


import collections

n = int(input())
a = [int(input()) for i in range(n)]
m = sorted(list(set(a)))
c =collections.Counter(a)

t = [max(a)]*n

if c[max(a)] == 1:
    t[a.index(max(a))] = m[-2]

[print(i) for i in t]


N = int(input())
A = [int(input()) for i in range(N)]
I1 = A.index(max(A))
M1 = A.pop(I1)
M2 = max(A)
for j in range (N):
  if j == I1:
    print(M2)
  else:
    print(M1)

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

sorted_a = sorted(A, reverse= True)
max_val = sorted_a[0]
next_max_val = sorted_a[1]
for a in A:
  if a == max_val:
    print(next_max_val)
  else:
    print(max_val)

n = int(input())
a = [int(input()) for _ in range(n)]
s = sorted(a)
for i in range(n):
    if a[i] != s[-1]:
        print(s[-1])
    else:
        print(s[-2])

N = int(input())
A = [int(input()) for _ in range(N)]
sort_A = sorted(A)
max_val = max(A)
second_val = sort_A[-2]

for i in range(N):
    if A[i] == max_val:
        print(second_val)
    else:
        print(max_val)

n = int(input())
arr = [int(input()) for _ in range(n)]
ar = sorted(arr)
mx = ar[-1]
sc = ar[-2]

for ele in arr:
    if ele == mx:
        print(sc)
    else:
        print(mx)


from collections import Counter
N=int(input())
Alist=[]
maxi=0
n2=0
for _ in range(N):
    A=int(input())
    Alist.append(A)
    if A>maxi:
        n2=maxi
        maxi=A
    elif A>n2:
        n2=A
count=Counter(Alist)
for A in Alist:
    if A!=maxi:
        print(maxi)
    elif A==maxi and count[A]>1:
        print(maxi)
    else:
        print(n2)

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

maxa = max(a)
maxnum = a.count(maxa)

if maxnum > 1:
    for i in range(n):
        print(maxa)
else:
    maxidx = a.index(maxa)
    for i in range(n):
        if i != maxidx:
            print(maxa)
        else:
            a[maxidx] = 0
            print(max(a))

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

Asorted=sorted(A)
Amax1=Asorted[-1]
Amax2=Asorted[-2]

for a in A:
	if a!=Amax1:
		print(Amax1)
	else:
		print(Amax2)


# ABC 134 C
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
B = sorted(A)

if B[-1] != B[-2]:
    t = A.index(B[-1])
    for i in range(N):
        if i == t:
            print(B[-2])
        else:
            print(B[-1])
else:
    for i in range(N):
        print(B[-1])

import bisect

N = int(input())
A = [int(input()) for _ in range(N)]
sort_A = sorted(A)
max_val = max(A)
second_val = sort_A[bisect.bisect_right(sort_A, max_val) - 2]

for i in range(N):
    if A[i] == max_val:
        print(second_val)
    else:
        print(max_val)

import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N = I()
    L = [I() for i in range(N)]
    L2=sorted(L)
    max_n = L2[N-1]
    max_n2 = L2[N-2]
    if max_n==max_n2:
        for i in range(N):
            print(max_n)
    else:
        for i in L:
            if i != max_n:
                print(max_n)
            else:
                print(max_n2)
            

        
    
    
def __starting_point():
    main()
__starting_point()

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

b = copy(a)
c = copy(a)

for i in range(1, n):
    b[i] = max(b[i], b[i - 1])
for i in range(n - 2, -1, -1):
    c[i] = max(c[i], c[i + 1])
b.append(-1)
c.append(-1)

for i in range(n):
    print((max(b[i - 1], c[i + 1])))


N = int(input())
A_ls = []
for i in range(N):
    A_ls.append(int(input()))
sorted_A_ls = sorted(A_ls, reverse=True)
first_val = sorted_A_ls[0]
second_val = sorted_A_ls[1]

for val in A_ls:
    if val == first_val:
        print(second_val)
    else:
        print(first_val)

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import heapq

def main():
    numbers=[]
    n = int(input())
    [numbers.append(int(input().rstrip())) for _ in range(n)]

    max_n=0
    second_n=0

    for i in numbers:
        if i > max_n:
            max_n=i
        elif i > second_n:
            second_n=i
    
    for i in numbers:
        if i==max_n:
            print(second_n)
        else:
            print(max_n)
    

def __starting_point():
    main()
__starting_point()

# -*- coding: utf-8 -*-
"""
Created on Thu Sep 10 00:13:41 2020

@author: liang
"""

N = int(input())
A = [int(input()) for i in range(N)]
B = A.copy()
B.sort()

for i in range(N):
    if A[i] == B[-1]:
        print(B[-2])
    else:
        print(B[-1])

n = int(input())
a = []
for i in range(n):
    A = int(input())
    a.append(A)
a_1 = list(set(a))[-1]
if a.count(a_1) >= 2:
    for i in range(n):
        print(a_1)
else:
    a_2 = list(set(a))[-2]
    for i in range(n):
        if a[i] == a_1:
            print(a_2)
        else:
            print(a_1)

n = int(input())
L = list(int(input()) for _ in range(n))
SL = sorted(L)
first_max = SL[-1]
second_max = SL[-2]
for l in L:
  if (l != first_max):
    print(first_max)
  elif (l == first_max):
    print(second_max)

n =  int(input())
A = []
for i in range(n):
    A.append(int(input()))
ma = max(A)
ma2 = sorted(A)[-2]
for a in A:
    if a == ma:
        print(ma2)
    else:
        print(ma)

n = int(input())
a = list(int(input()) for i in range(n))
aa = sorted(a)
amax = aa[n-1]
asecond = aa[n-2]

for i in a:
    if i != amax:
        print(amax)
    else:
        print(asecond)

n = int(input())
A = [int(input()) for _ in range(n)]
sort_A = sorted(A, reverse=True)

for a in A:
    if a == sort_A[0]:
        print(sort_A[1])
    else:
        print(sort_A[0])

import sys

input = sys.stdin.readline

n = int(input())
A = []
#リストAにappend()を使って格納していく
for _ in range(n):
    A.append(int(input()))


sort_A = sorted(A, reverse=True)
max_1 = sort_A[0]
max_2 = sort_A[1]

if max_1 == max_2:
    for _ in range(n):
        print(max_1)
else:
    for i in range(n):
        if A[i] == max_1:
            print(max_2)
        else:
            print(max_1)

n = int(input())
a = [int(input()) for _ in range(n)]
m1, m2 = -1, -1
for i in range(n):
  if m1 < a[i]:
    m2 = m1
    m1 = a[i]
  elif m2 < a[i]:
    m2 = a[i]
for i in range(n):
  if a[i] == m1:
    print(m2)
  else:
    print(m1)


n=int(input())
a=[]
for _ in range(n):
    a.append(int(input()))
b=a.copy()
b.sort()
a_=max(a)
for i in range(n):
    if a[i]==a_:
        print(b[-2])
    else:
        print(a_)    

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    sortA = sorted(A)
    #print(A,sortA)
    ans = sortA[N-1]
    ans2 = sortA[N-2]
    if ans == ans2:
        flag = 1
    else:
        flag = 0

    for i in range(N):
        if flag == 1:
            print(ans)
        else:
            if A[i] == ans:
                print(ans2)
            else:
                print(ans)

main()


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

m,s = 0,0
for a in A:
    if a > m:
        m = a
    elif a > s:
        s = a

for a in A:
    if a == m:
        print(s)
    else:
        print(m)


n = int(input())
numbers = []
for i in range(n):
  a = int(input())
  numbers.append(a)
b = max(numbers)
max_index = numbers.index(max(numbers))
numbers.remove(b)
for i in range(n):
  if i == max_index:
    print(max(numbers))
  else:
    print(b)

n=int(input())

a=[]
for i in range(n):
    a.append(int(input()))

a_max=max(a)
a_max_cnt=a.count(a_max)

for i in range(n):
    if (a[i]!=a_max or a_max_cnt>1):
        print(a_max)
    else:
        print((max(a[:i]+a[i+1:])))


n = int(input())
a = []
for _ in range(n):
  a.append(int(input()))
a_max = max(a)
flg = False
if a.count(a_max) > 1:
  flg = True
a_s = sorted(a, reverse=True)
for ai in a:
  if ai != a_max:
    print(a_max)
  elif flg:
    print(a_max)
  else:
    print(a_s[1])

#import math
#import itertools
#import numpy as np
#from collections import deque
# sys.setrecursionlimit(10 ** 6)
#mod = 10 ** 9 + 7
#INF = 10 ** 9
#PI = 3.14159265358979323846

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n=INT()
    A=[]
    for i in range(n):
        A.append(INT())
    
    B=sorted(A,reverse=True)
    m1=A.count(B[0])
    m2=A.count(B[1])
    if m1>=2:
        flg=True
    else:
        index=A.index(B[0])
        flg=False

    #print(A,B,index)

    if flg:
        for i in range(n):
            print(B[0])
    else:
        for i in range(n):
            if i!=index:
                print(B[0])
            else:
                print(B[1])


def __starting_point():
    do()
__starting_point()

N=int(input())
A=[int(input()) for _ in range(N)]
B=sorted(A,reverse=True)
for i in range(N):
    if A[i]==B[0]:
        print(B[1])
    else:
        print(B[0])

n=int(input())
A=[int(input()) for _ in range(n)]
sort_A=sorted(A,reverse=True)

for a in A:
  if a==sort_A[0]:
    print(sort_A[1])
  else:
    print(sort_A[0])

import sys
import copy
import math
import itertools
import numpy as np
N = int(input())
A = [int(input()) for c in range(N)]
B = sorted(copy.deepcopy(A),reverse=True)

for i in range(N):
    if A[i] == B[0]:
        print(B[1])
    else:
        print(B[0])

n = int(input())
a = [int(input()) for i in range(n)]
if len(set(a)) == 1:
    for i in range(n):
        print(a[0])
    return
x = sorted(a)[-1]
y = sorted(a)[-2]
for i in range(n):
    if a[i] != x:
        print(x)
    else:
        print(y)

N = int(input())
lsA = [int(input()) for i in range(N)]
maxA = max(lsA)
Akazu = lsA.count(maxA)
for i in range(N):
    if lsA[i] == maxA and Akazu == 1:
        print(max(lsA[:i]+lsA[i+1:]))
    else:
        print(maxA)

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

li = A.copy()
li.sort()

f = li[-1]
s = li[-2]

for i in range(N):
    if f == A[i]:
        print(s)
    else:
        print(f)


# -*- coding:utf-8 -*-
import copy
N = int(input())
A_list=[]

for _ in range(N):
    A_list.append(int(input()))

sort_list = copy.deepcopy(A_list)
sort_list.sort()

a_max = sort_list[-1]
a_max_second = sort_list[-2]

if a_max == a_max_second:
    for _ in range(N):
        print(a_max)
else:
    for i in range(N):
        if A_list[i] == a_max:
            print(a_max_second)
        else:
            print(a_max)



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

for i in range(n):
  if a[i] != q[-1]:
    print((q[-1]))
  else:
    print((q[-2]))


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

M = max(A)
M_index = A.index(M)
sub_M = 0
for i in range(N):
  if i != M_index: sub_M = max(sub_M, A[i])

for i in range(N):
  if i == M_index: print(sub_M)
  else: print(M)

N=int(input())
a=[int(input()) for i in range(N)]
sw=True
b=sorted(a,reverse=True)

if b[0]>b[1]:
    max2=b[1]
    max1=b[0]
    sw=False

if sw==True:
    max1=b[0]
    for k in range(N):
        print(max1)
else:
    for k in range(N):
        if a[k]==max1:
            print(max2)
        else:
            print(max1)


N=int(input())
A=[int(input()) for _ in range(N)]
M1=max(A[0],A[1])
M2=min(A[0],A[1])
for i in range(2,N):
    if A[i]>=M1:
        M2=M1
        M1=A[i]
    else:
        M2=max(M2,A[i])
for i in range(N):
    if A[i]==M1:
        print(M2)
    else:
        print(M1)


N = int(input())
A = [int(input()) for _ in range(N)]
 
M = max(A)
M_index = A.index(M)
sub_M = 0
for i in range(N):
  if i != M_index: sub_M = max(sub_M, A[i])

for i in range(N):
  if i == M_index: print(sub_M)
  else: print(M)

#ABC134 C (再考察)

N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    
AA = sorted(A,reverse = True)
for i in range(N):
    if A[i] != AA[0]:
        print(AA[0])
    else:
        print(AA[1])

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

firstVal = max(A)
firstInd = A.index(firstVal)
secondVal = max(A[0:firstInd] + A[firstInd+1:])

for i in range(firstInd):
    print(firstVal)

print(secondVal)

for i in range(N-firstInd-1):
    print(firstVal)


# C問題
N = int(input())
A = [int(input()) for i in range(N)]

sorted_A = sorted(A, reverse=True)
max_value, next_value = sorted_A[0], sorted_A[1]

for i in A:
    if i == max_value:
        print(next_value)
    else:
        print(max_value)


n = int(input())
alist = [int(input()) for _ in range(n)]

import copy
alist_copy = copy.copy(alist)

alist_copy.sort()
max_value = alist_copy[-1]
next_value = alist_copy[-2]
for a in alist:
    if a == max_value:
        print(next_value)
    else:
        print(max_value)

N = int(input())
A = [int(input()) for _ in range(N)]
sort_A = sorted(A, reverse=True)
ans = []

for i in range(N):
    if sort_A[0] == A[i]:
        ans.append(sort_A[1])
    else:
        ans.append(sort_A[0])

for a in ans:
    print(a)


N = int(input())
L = []
M = []
for i in range(N):
  a = int(input())
  L.append(a)
  M.append(a)
L.sort()
for j in range(N):
  if M[j] == L[len(L) - 1]:
    print(L[len(L) - 2])
  else:
    print(L[len(L) - 1])

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

for i in range(N):
  if S[i] == A[-1]:
    if len(A) > 1:
      print((A[-2]))
    else:
      print((A[-1]))
  else:
    print((A[-1]))



# coding: utf-8

def main():
    N = int(input())
    fir, fir_i, sec, sec_i = 0, 0, 0, 0

    for i in range(N):
        tmp = int(input())
        if tmp > fir:
            sec = fir
            sec_i = fir_i
            fir = tmp
            fir_i = i
        elif tmp > sec:
            sec = tmp
            sec_i = i

    for i in range(N):
        if i != fir_i:
            print(fir)
        else:
            print(sec)


def __starting_point():
    main()

__starting_point()

N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
AA = sorted(A)
most = AA[N-1]
second = AA[N-2]

for i in range(N):
  if A[i] == most:
    print(second)
  else:
    print(most)

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

max_v, next_max_v = sorted(A, reverse=True)[:2]
for a in A:
    print(max_v if a != max_v else next_max_v)

N = int(input())
A = [int(input()) for i in range(N)]
m = max(A)
mindex = A.index(m)
for i in range(N):
    if(i != mindex):
        print(m)
    else:
        pop = A.pop(i)
        print(max(A))
        A.insert(i,pop)

n = int(input())
xlist = [int(input()) for i in range(n)]
ylist = sorted(xlist)
max1 = ylist[-1]
max2 = ylist[-2]
for i in range(n):
  if xlist[i] != max1:
    print(max1)
  else:
    print(max2)

n = int(input())

a = [0] * n

fm, fi = 0, 0
sm, si = 0, 0  
for i in range(n):
    a[i] = int(input())
    if a[i] > fm:
        sm, si = fm, fi
        fm, fi = a[i], i
    elif a[i] > sm:
        sm, si = a[i], i
        
for i in range(n):
    if i != fi:
        print(fm)
    else:
        print(sm)        

import copy

N = int(input())

ary = []
for _ in range(N):
    ary.append(int(input()))

ary_copy = copy.copy(ary)
ary_copy.sort()

max_1 = ary_copy[-1]
max_2 = ary_copy[-2]

for i in ary:
    if i == max_1:
        print(max_2)
    elif i != max_1:
        print(max_1)

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

M = max(A)
i = A.index(M)
M2 = max(A[:i] + A[i+1:])

for a in A:
    print(M if a != M else M2)

import sys
import numpy as np
n = int(input())
a = [int(input()) for _ in range(n)]
mx = str(max(a))
mx_id = a.index(int(mx))
a.remove(int(mx))
mx_sub = str(max(a))
ans = '\n'.join(mx if i != mx_id else mx_sub for i in range(n))

print(ans)

n = int(input())
a = [int(input()) for i in range(n)]
b=sorted(a)
c,d=b[-1],b[-2]
for i in a:
    print(c if i!=c else d)