Problem:
 Score : 300 points    Problem Statement 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 1 3
1
4
3      Sample Output 1 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 .        Sample Input 2 2
5
5      Sample Output 2 5
5

Solution (Python):
N = int(input())
A = []
dicA = {}

for i in range(N):
    tmp = int(input())
    dicA[tmp] = dicA.get(tmp, 0) + 1
    A.append(tmp)

sortA = sorted(dicA.items(), key=lambda x: x[0], reverse=True)

for ai in A:
    if ai != sortA[0][0] or sortA[0][1] != 1:
        print(sortA[0][0])
    else:
        print(sortA[1][0])

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


n = I()
a = [I() for _ in range(n)]

def max_index(l, value):
    return [i for i, x in enumerate(l) if x == value]

a_sort = sorted(a,reverse=True)


max_indexs = max_index(a,a_sort[0])
max_indexs = set(max_indexs)

for i in range(n):
    if i in max_indexs:
        print(a_sort[1])
    else:
        print(a_sort[0])

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

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

Solution (Python):
n = int(input())
lst = [int(input()) for _ in range(n)]

lst2 = sorted(lst)
saidai = max(lst2)

for i in range(n):
    if lst[i] != saidai:
        print(lst2[-1])
    else:
        print(lst2[-2])

Solution (Python):
n=int(input())
a=[]
for _ in range(n):
    a.append(int(input()))
sort_a=sorted(a,reverse=True)
for i in range(n):
    if a[i]==sort_a[0]:
        print(sort_a[1])
    else:
        print(sort_a[0])

Solution (Python):
N = int(input())

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

max1 = max(A)
max1_ind = A.index(max1)

A.remove(max1)

max2 = max(A)

for i in range(N):
    if i != max1_ind:
        print(max1)
    else:
        print(max2)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
A_ = sorted(A)
max1 = A_[-1]
max2 = A_[-2]

for i in range(N):
    if A[i] == max1:
        print(max2)
    else:
        print(max1)

Solution (Python):
n=int(input())
a=[int(input()) for _ in range(n)]
from collections import Counter
ca=Counter(a)
ma=max(a)
if ca[ma]>1:
  ans=[ma]*n
  print(*ans,sep='\n')
else:
  ks=set(ca.keys())
  ks.discard(ma)
  maa=max(ks)
  for x in a:
    if x==ma:
      print(maa)
    else:
      print(ma)

Solution (Python):
def solve():
    from bisect import bisect_left
    import sys
    n, *s = map(int, sys.stdin.read().split())
    t = sorted(s)
    for ss in s:
        x = bisect_left(t, ss)
        if x == n - 1:
            print(t[-2])
        else:
            print(t[-1])



solve()

Solution (Python):
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])

Solution (Python):
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
m=max(a)
b=sorted(a)
m2=b[-2]
for i in range(n):
    if a[i]==m:
        print(m2)
    else:
        print(m)

Solution (Python):
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
m=max(a)
b=sorted(a)
m2=b[-2]
for i in range(n):
    if a[i]==m:
        print(m2)
    else:
        print(m)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
m = max(A)
if A.count(m) > 1:
    [print(m) for a in A]
else:
    [print(m) if a != m else print(sorted(A)[-2]) for a in A]

Solution (Python):
n = int(input())
A = [int(input()) for _ in range(n)]
S = sorted(A)

for a in A:
    print(S[-1] if a != S[-1] else S[-2])

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

B = A.copy()
B.sort(reverse=True)
for i in range(N):
    if A[i] != B[0]:
        print(B[0])
    else:
        print(B[1])

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
a_sorted = sorted(A,reverse=True)
for i in range(N):
    if A[i] != a_sorted[0]:
        print(a_sorted[0])
    elif A[i] == a_sorted[0]:
        print(a_sorted[1])

Solution (Python):
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())
b=sorted(a)
l=len(b)
for i in range(n):
    if a[i]==b[l-1]:
        print(b[l-2])
    else:
        print(b[l-1])

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)


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

Solution (Python):
N=int(input())
A=[int(input()) for _ in range(N)]
s=sorted(A)
for a in A:
    print(s[-1] if a!=s[-1] else s[-2])

Solution (Python):
N = int(input())
A = [int(input())for _ in range(N)]
ra = sorted(A,reverse = True)

for i in A:
    if i != ra[0]:
        print(ra[0])
    else:
        print(ra[1])

Solution (Python):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = []
for _ in range(n):
    A.append(inint())

sorted_A = sorted(A)[::-1]

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

Solution (Python):
n = int(input())
A = [int(input()) for _ in range(n)]
ma_1 = max(A)
ma_2 = sorted(A)[-2]
for a in A:
    if a == ma_1:
        print(ma_2)
    else:
        print(ma_1)

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]

sign = a.index(max(a))
M = max(a)

a.remove(M)

S = max(a)

for i in range(n):
    if i != sign:
        print(M)
    else:
        print(S)

Solution (Python):
import copy

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

aa = copy.deepcopy(A)
aa.sort()

first = aa[-1]
second = aa[-2]

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

Solution (Python):
import copy

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

first = 0
second = 0

aa = copy.deepcopy(A)
aa.sort()

for a in aa:
    if a >= first:
        second = first
        first = a

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

Solution (Python):
N = int(input())
A = [int(input()) for n in range(N)]
B = sorted(A)[::-1]
a1 = B[0]
a2 = B[1]

for n in range(N):
  if A[n]==a1:
    print(a2)
  else:
    print(a1)

Solution (Python):
N = int(input())
A = [int(input()) for n in range(N)]
B = sorted(A)[::-1]
a1 = B[0]
a2 = B[1]

if a1==a2:
  for n in range(N):
    print(a1)
else:
  for n in range(N):
    if A[n]==a1:
      print(a2)
    else:
      print(a1)

Solution (Python):
import copy
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
c = a.count(max(a))
a_2 = copy.copy(a)
t = max(a)

if c > 1:
    for i in range(n):
        print(t)
else:
    a_2.remove(t)
    t_2 = max(a_2)
    for i in a:
        if i == t:
            print(t_2)
        else:
            print(t)

Solution (Python):
n = int(input())
a = list(int(input()) for _ in range(n))

max_a = max(a)

cnt = 0

for b in a:
  if b == max_a:
    cnt += 1
    
if cnt >= 2:
  for _ in range(n):
    print(max_a)
    
elif cnt == 1:
  for i in range(n):
    if a[i] != max_a:
      print(max_a)
    else:
      b = sorted(set(a))
      print(b[-2])

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
sa = sorted(a)
am, asl = sa[-1], sa[-2]
print(*[asl if ai == am else am for ai in a], sep='\n')

Solution (Python):
import sys
N = int(input())
A = [int(sys.stdin.readline()) for _ in range(N)]
sortedA = sorted(A, reverse=True)
for a in A:
    if a == sortedA[0]:
        print(sortedA[1])
    else:
        print(sortedA[0])

Solution (Python):
import numpy as np
n = int(input())
a = np.array([int(input()) for _ in range(n)])
a1n = a.argmax()
a_s = sorted(a)
a1 = a_s[-1]
a2 = a_s[-2]
for i in range(n):
    if i == a1n:
        print(a2)
    else:
        print(a1)

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

asort = sorted(a)

import bisect
for i in range(n):
    if bisect.bisect_left(asort,a[i]) < n-1:
        print(asort[-1])
    elif bisect.bisect_left(asort,a[i]) == n-1:
        print(asort[-2])

Solution (Python):
n = int(input())

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

if a_sorted[0] == a_sorted[1]:
    for i in range(n):
        print(a_sorted[0])
else:
    for i in range(n):
        if a[i] != a_sorted[0]:
            print(a_sorted[0])
        else:
            print(a_sorted[1])

Solution (Python):
n = int(input())
A = [int(input()) for _ in range(n)]
SA = sorted(A, reverse=True)
ma = max(A)
for a in A:
    if a == ma:
        print(SA[1])
    else:
        print(ma)

Solution (Python):
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
b=sorted(a,reverse=True)

c=a.index(b[0])
d=b.index(b[1])
for i in range(n):
  if i==c:
    print(b[1])
  else:
    print(b[0])

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

maximum = max(A)
count_max = A.count(maximum)
if count_max > 1:
    for i in range(N):
        print(maximum)
else:
    for i in range(N):
        if A[i] != maximum:
            print(maximum)
        else:
            num = A[i]
            A[i] = 0
            print(max(A))
            A[i] = num

Solution (Python):
n = int(input())

cnt = {}
A = []
for i in range(n):
    x = int(input())
    A.append(x)

A_sort = sorted(A, reverse=True)

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

Solution (Python):

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

if n == 2:
    print(a[1])
    print(a[0])
    exit()

b = [0] * n
for i in range(n):
    b[i] = a[i]

b.sort()
b.reverse()

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

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

max1 = max(A)
n_max1 = A.count(max1)


if n_max1 > 1:
    for _ in range(N):
        print(max1)
    exit()


else:
    max2 = sorted(list(set(A)))[-2]
    for i in range(N):
        if A[i] != max1:
            print(max1)
        else:
            print(max2)

Solution (Python):
n = int(input())
a = []
top = 1
two = 1
for i in range(n):
    line = int(input())
    a.append(line)
    if line >= top:
        top, two = line, top
    elif line >= two:
        two = line

for i in range(n):
    if a[i] != top:
        print(top)
    else:
        print(two)

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

a_copy = a[::]
a_copy.sort(reverse=True)

for i in range(n):
    if a[i] != a_copy[0]:
        print(a_copy[0])
    else:
        print(a_copy[1])

Solution (Python):
import sys

input = sys.stdin.readline
max_a = 0
big_a = 0
max_index = 0
n = int(input())
for i in range(n):
    a = int(input())
    if max_a < a:
        max_index = i
        big_a = max_a
        max_a = a
    elif max_a == a:
        max_index = -1
    elif big_a < a:
        big_a = a
    else:
        continue

for i in range(n):
    print([max_a, big_a][i == max_index])

Solution (Python):
N=int(input())
l=[]
l.append(int(input()))
l.append(int(input()))
m1=max(l)
m2=min(l)
for _ in range(N-2):
  l.append(int(input()))
  if l[-1] >= m1:
    m2 = m1
    m1 = l[-1]
  elif l[-1] > m2:
    m2 = l[-1]
for i in range(N):
  if l[i] == m1:
    print(m2)
  else:
    print(m1)

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]

sorted_a = sorted(a, reverse=True)

for i in range(n):
    if a[i] == sorted_a[0]:
        print(sorted_a[1])
    else:
        print(sorted_a[0])

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a, reverse=True)
max_a = max(a)
for x in a:
    if x == max_a:
        print(b[1])
    else:
        print(b[0])

Solution (Python):

n = int(input())

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

most = max(a)
most_idx = a.index(most)
second = max(a[:most_idx] + a[most_idx+1:])

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

Solution (Python):
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
b=sorted(a,reverse=True)
a1=b[0]
a2=b[1]
m=a.index(a1)
for i in range(n):
  if i==m:
    print(a2)
  else:
    print(a1)

Solution (Python):
n=[int(input()) for _ in range(int(input()))]
N1,N2=max(n),sorted(n)[-2]
[print(N2) if i==N1 else print(N1) for i in n]

Solution (Python):
n=[int(input()) for _ in range(int(input()))]
N1,N2=max(n),sorted(n)[-2]
for i in n:
  if i<N1: print(N1)
  elif i==N1: print(N2)

Solution (Python):
import copy
n = int(input())
lst =[]
for i in range(n):
    x = int(input())
    lst.append(x)

lst2 = copy.deepcopy(lst)
lst2.sort()
max = max(lst2)
for x in lst:
    if x == max:
        print(lst2[-2])
    else:
        print(max)

Solution (Python):
n=int(input())
s=[int(input()) for _ in range(n)]
lst=sorted(s,reverse=True)
max1=lst[0]
max2=lst[1]
for i in range(n):
    if s[i]==max1:
        print(max2)
    else:
        print(max1)

Solution (Python):
n=int(input())
alist=[]
maxa=0
nextmax=0
maxindex = 573945
for i in range(n):
    tmpa=int(input())
    if tmpa >= maxa:
        nextmax = maxa
        maxa = tmpa
        maxindex = i
    elif tmpa >= nextmax:
        nextmax = tmpa

for j in range(n):
    if j == maxindex:
        print(nextmax)
    else:
        print(maxa)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
top1, top2 = sorted(a, reverse=True)[:2]
for num in a:
    if num==top1:
        print(top2)
    else:
        print(top1)

Solution (Python):
import copy
N = int(input())
A = []
m = 0
S = 0
for i in range(N):
    a = int(input())
    A.append(a)
    if m < a:
        s = m
        m = a
    elif s < a:
        s = a

c = []
mL = 0
mR = 0



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

Solution (Python):
N=int(input())
num1=0
am=0
a2=0
for x in range(N):
  a=int(input())
  if am<a:
    a2=am
    num1=x
    am=a
  elif a2<a:
    a2=a
for y in range(N):
  if y==num1:
    print(a2)
  else:
    print(am)

Solution (Python):
N = int(input())
Nmax1 = [0, 0]
Nmax2 = [0, 0]
A = []
for i in range(N):
    x = int(input())
    if Nmax1[0] <= x:
        Nmax2[0] = Nmax1[0]
        Nmax2[1] = Nmax1[1]
        Nmax1[0] = x
        Nmax1[1] = i
    elif Nmax2[0] < x:
        Nmax2[0] = x
        Nmax2[1] = i

ans = [Nmax1[0]]*N
ans[Nmax1[1]] = Nmax2[0]

for i in ans:
    print(i)

Solution (Python):
n = int(input())
A = [int(input()) for _ in range(n)]
f_num = max(A)
A_c = A.copy()
A_c.remove(f_num)
s_num = max(A_c)

for a in A:
    if a == f_num:
        print(s_num)
    else:
        print(f_num)

Solution (Python):
N=int(input())
A=[]
for i in range(N):A.append(int(input()))
B=sorted(A,reverse=True)
b1,b2=B[0],B[1]
for i in range(N):
  if A[i]==b1:print(b2)
  else:print(b1)

Solution (Python):
N=int(input())
A=[0]*N; B=[0]*N;
for i in range(N):
  A[i]=int(input())
  B[i]=A[i]
B.sort(reverse=True)
for j in range(N):
  if A[j]==B[0] :
    print(B[1])
  else :
    print(B[0])

Solution (Python):
N = int(input())
A = [int(input()) for a in range(N)]
maxnum = max(A)
maxcount = A.count(maxnum)
s = sorted(A,reverse=True)

if maxcount == 1:
  index = A.index(maxnum)
  ans = [maxnum] * N
  ans[index] = s[1]
else:
  ans = [maxnum] * N
for a in ans:
  print(a)

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque, defaultdict


from collections import Counter

from itertools import accumulate,combinations,permutations,product

from heapq import heapify,heappop,heappush

from functools import reduce,lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): 
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    

    N = int(input())
    
    
    A = tuple(int(input()) for i in range(N)) 
    

    left=[]
    cur=0
    for a in A:
        left.append(cur)
        cur=max(cur,a)
        
    cur=0
    right=[]
    for a in reversed(A):
        right.append(cur)
        cur=max(cur,a)
    for i in range(N):
        print(max(left[i],right[-i-1]))
    
    


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
sa = sorted(a)
am, asl = sa[-1], sa[-2]
for i in range(n):
    print(asl if a[i] == am else am)

Solution (Python):
N = int(input())
aaa = [int(input()) for _ in range(N)]
MAX = max(aaa)
NEX = sorted(aaa)[-2]
for a in aaa:
    if a < MAX:
        print(MAX)
    else:
        print(NEX)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
b = a[:]
first = max(a)
idx = b.index(first)
b[idx] = 0
second = max(b)

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

Solution (Python):
def readinput():
    n=int(input())
    a=[]
    for i in range(1,n+1):
        a.append((int(input()),i))
    return n,a

def main(n,a):
    sa=sorted(a,key=lambda x:x[0], reverse=True)
    for i in range(1,n+1):
        if sa[0][1]!=i:
            print(sa[0][0])
        else:
            print(sa[1][0])            

if __name__=='__main__':
    n,a=readinput()
    main(n,a)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
maxa = max(a)

if a.count(maxa) == 1:
    b = sorted(a, reverse=True)

    maxa2 = b[1]
    for i in range(n):
        if a[i] == maxa:
            print(maxa2)
        else:
            print(maxa)

else:
    for i in range(n):
        print(maxa)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
m1 = max(A[0], A[1])
m2 = min(A[0], A[1])
for i in range(2,N):
    if m1 < A[i]:
        m1, m2 = A[i], m1
    elif m2 < A[i]:
        m2 = A[i]
print("\n".join(map(str, [m1 if i != m1 else m2 for i in A])))

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
A_sort = sorted(A)
M_1, M_2 = A_sort[-1], A_sort[-2]
for a in A:
  if a == M_1:
    print(M_2)
  else:
    print(M_1)

Solution (Python):
n = int(input())
A = []
f = 0
s = 0
for _ in range(n):
  a = int(input())
  A.append(a)
  if f <= a:
    s = f
    f = a
  elif s <= a:
    s = a
for a in A:
  if a == f:
    print(s)
  else:
    print(f)

Solution (Python):
N = int(input())
A = []
max1 = 0
max2 = 0

for _ in range(N):
    tmp = int(input())
    A.append(tmp)
    if tmp > max1:
        max1 = tmp
    elif tmp > max2:
        max2 = tmp

for i in range(N):
    if A[i] == max1:
        print(max2)
    else:
        print(max1)

Solution (Python):
N = int(input())
As = []
for i in range(N):
  A = int(input())
  As.append(A)
Ass = sorted(As)
for i in range(N):
  if As[i]<Ass[-1]:
    print(Ass[-1])
  else:
    print(Ass[-2])

Solution (Python):
import sys
from io import StringIO
import unittest


def resolve():
    
    n = int(input())
    a = [int(input()) for _ in range(n)]
    
    aa = sorted(a)

    max_1st = aa[-1]
    max_2nd = aa[-2]

    for i, a_i in enumerate(a):
        if max_1st == a_i:
            print(max_2nd)
        else:
            print(max_1st)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
1
4
3"""
        output = """4
3
4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
5
5"""
        output = """5
5"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

Solution (Python):
import math
N = int(input())
A = [0]*N
B = [0]*N
for i in range(N):
  A[i]= int(input())
B = sorted(A,reverse=True)
for j in range(N):
  if(A[j]==B[0]):
    print(B[1])
  else:
    print(B[0])

Solution (Python):
N = int(input().rstrip())
A = []
mx1 = 0
mx2 = 0
for i in range(N):
    A.append(int(input().rstrip()))
    if A[i] > mx1:
        mx1, mx2 = A[i], mx1
    elif A[i] > mx2:
        mx2 = A[i]
for j in range(N):
    if A[j] == mx1:
        print(mx2)
    else:
        print(mx1)

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

B=sorted(A)

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

Solution (Python):
def main():
    n = int(input())
    inlis = []
    for _ in range(n):
        a = int(input())
        inlis.append(a)
    saidai = max(inlis)
    kosuu = inlis.count(saidai)
    inlis2 = sorted(inlis)
    saidai2 = inlis2[-2]
    for i in range(n):
        if inlis[i] != saidai:
            print(saidai)
        else:
            print(saidai2)

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=[int(input()) for i in range(n)]
A,B=sorted(a,reverse=True)[0:2]
for i in range(n):
    if a[i]==A:
        print(B)
    else:
        print(A)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
a, b = sorted(A, reverse = True)[0: 2]
for i in range(N):
    if A[i] == a:
        print(b)
    else:
        print(a)

Solution (Python):
N = int(input())
number = []
for i in range(N):
    number.append(int(input()))
sorted_number = sorted(number,reverse=True)
max_number = sorted_number[0]
second_number = sorted_number[1]

for i in number:
    if i != max_number:
        print(max_number)
    else:
        print(second_number)

Solution (Python):

import copy
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
    
Max = max(a)
b = copy.copy(a)
b.remove(Max)
sub = max(b)

for i in a:
    if i !=Max:
        print(Max)
    else:
        print(sub)

Solution (Python):
n = int(input())
a = list(int(input()) for i in range(n))
b = list(a)
b.sort(reverse = True)
c = b[0]
for i in range(n):
    if a[i] == c:
        print(b[1])
    else:
        print(c)

Solution (Python):
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))

B = sorted(A, reverse = True)
max1 = B[0]
max2 = B[1]
for a in A:
    print(max2 if a == max1 else max1)

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

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
A_max = 0
for i in range(N):
  A_max = max(A_max,A[i])
cnt = 0
for j in range(N):
  if A_max == A[j]:
    cnt += 1
  if cnt == 2:
    for _ in range(N):
      print(A_max)
    exit()
A[A.index(A_max)] = 0
A_second = 0
for l in range(N):
  A_second = max(A_second,A[l])
for m in range(N):
  print(A_second if A[m] == 0 else A_max)

Solution (Python):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
b = sorted(a,reverse = True)
max1 = b[0]
max2 = b[1]
for i in a:
    print(max2 if i == max1 else max1)

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

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
sorted_list = sorted(a, reverse=True)
a_max = sorted_list[0]
a_sec = sorted_list[1]
for i in range(n) :
    if a[i] != a_max :
        print(a_max)
    else :
        print(a_sec)

Solution (Python):
import math
import collections
def main():
    n = int(input())
    s = []
    dd = collections.defaultdict(int)
    for i in range(n):
        a  = int(input())
        dd[a]+=1
        s.append(a)
    k = max(dd.keys())
    lis = sorted(list(dd.keys()),reverse = True)

    for i in range(n):
        if(s[i]==k and dd[s[i]]==1):
            print(lis[1])
        else:
            print(k)






if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)
for v in a:
  print(b[(v<b[-1])-2])

Solution (Python):
import copy
n = int(input())
a = [int(input()) for _ in range(n)]
b = copy.deepcopy(a)
a.sort(reverse=True)
for v in b:
  if v==a[0]:
    print(a[1])
  else:
    print(a[0])

Solution (Python):
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    sorted_A = sorted(A, reverse=True)
    ans = []
    for a in A:
        if a == sorted_A[0]:
            ans.append(str(sorted_A[1]))
        else:
            ans.append(str(sorted_A[0]))
    print("\n".join(ans))


if __name__ == '__main__':
    main()

Solution (Python):
import copy
n = int(input())
a = [int(input()) for A in range(n)]
max_a,secound_max_a = max(a),0
b = copy.copy(a)
b.sort()
bol = True
for j in range(n,n,-1):
    if b[j] != max(a):
        secound_max_a = b[j]
        bol = False
        break
if bol:
    secound_max_a = b[-2]

for i in range(n):
    if a[i] != max_a:
        print(max_a)
    else:
        print(secound_max_a)

Solution (Python):







__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


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

  B = sorted(A)
  max_ = B[-1]

  for x in A:
    if x == max_:
      print(B[-2])
    else:
      print(max_)


if(__name__ == '__main__'):
  main()

Solution (Python):
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    A = []
    first = (0, 0)
    sec = 0
    for i in range(N):
        a = int(input())
        A.append(a)
        if first[0] <= a:
            sec = first[0]
            first=(a, i)
        elif sec <a:
            sec =a

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


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
l=[]
for _ in range(n):
  l.append(int(input()))
m=max(l)
mc=l.count(m)
tin=set(l)
if len(tin)==1:
  s=m
else:
  s=sorted(tin)[-2]
for i in l:
  if i==m:
    if mc>1:
      print(m)
    else:
      print(s)
  else:
    print(m)

Solution (Python):
from copy import deepcopy
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
b = deepcopy(a)

first_max = max(b)
b.remove(first_max)
second_max = max(b)

for x in a:
    if x == first_max:
        print(second_max)
    else:
        print(first_max)

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

a_sorted = sorted(a)
a_max1 = a_sorted[-1]
a_max2 = a_sorted[-2]
for a_i in a:
    if a_i == a_max1:
        print(a_max2)
    else:
        print(a_max1)

Solution (Python):
from heapq import nlargest

n = int(input())
a = [int(input()) for i in range(n)]
b = nlargest(2, a)
ma = max(a)
for j in a:
  if j == ma:
    print(b[1])
  else:
    print(ma)

Solution (Python):
n=int(input())
arr=[0]*n
for i in range(n):
  arr[i]=int(input())
tmp=sorted(arr,reverse=True)
arrMax=tmp[0]
for i in range(n):
  if arr[i]==arrMax:
    if tmp[0]==tmp[1]:
      print(tmp[0])
    else:
      print(tmp[1])
  else:
    print(tmp[0])

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

B=sorted(A,reverse=True)
A1=B[0]
A2=B[1]

for i in range(N):
  if A[i]==A1:
    print(A2)
  else:
    print(A1)

Solution (Python):
N = int(input())
x = int(input())
y = int(input())
A = [x, y]
if x < y:
    x, y = y, x
for i in range(N - 2):
    a = int(input())
    A.append(a)
    if x <= a:
        y = x
        x = a
    elif y < a:
        y = a
if x == y:
    for i in range(N):
        print(x)
else:
    for a in A:
        if a == x:
            print(y)
        else:
            print(x)

Solution (Python):
import sys, math
from collections import defaultdict
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N = ri()
A = []
for i in range(N):
	A.append(ri())
m = max(A)
if len([a for a in A if a == m]) > 1:
	for i in range(N):
		print(m)
else:
	m2 = -1
	i2 = -1
	for i, a in enumerate(A):
		if a == m:
			continue
		if m2 < a:
			m2 = a
			i2 = i
	for a in A:
		if a == m:
			print(m2)
		else:
			print(m)

Solution (Python):
n=int(input())
a=[int(input()) for _ in range(n)]
max_a=max(a)
index=a.index(max_a)
a.pop(index)
for i in range(n):
    if i ==index:
        print(max(a))
    else:
        print(max_a)

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

Solution (Python):
N = int(input())
A = [int(input()) for j in range(N)]

B = sorted(A)
a = B[-1]
b = B[-2]
c = A.index(a)
for j in range(N):
    if j == c:
        print(b)
        continue
    print(a)

Solution (Python):
n=int(input())
A=[int(input()) for i in range(n)]
B=sorted(A,reverse=True)
amax=B[0]
asec=B[1]
for a in A:
    if a==B[0]:
        print(asec)
    else:
        print(amax)

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