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):
from collections import defaultdict
N = int(input())
A_list = [int(input()) for _ in range(N)]
A_cnt = defaultdict(int)
for A in A_list:
    A_cnt[A] += 1
A_set = set(A_cnt)
max_A = max(A_set)
if (A_cnt[max_A] > 1):
    for _ in range(N):
        print(max_A)
else:
    A_set.remove(max_A)
    second_A = max(A_set)
    for A in A_list:
        if (A == max_A):
            print(second_A)
        else:
            print(max_A)

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

a = l.index(max(l))
b = max(l)
l.pop(a)
c = max(l)
for i in range(n):
    if i != a:
        print(b)
    else:
        print(c)

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

x = (int(input().strip()), 0)
y = (int(input().strip()), 1)
if x[0] > y[0]:
  x, y = y, x

for i in range(2, N):
  a = int(input().strip())
  if a > x[0]:
    if a > y[0]:
      x = y
      y = (a, i)
    else:
      x = (a, i)

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

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

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

Solution (Python):
N = int(input())
no_1 = 0
pos_1 = 0
no_2 = 0
for i in range(0, N):
    num = int(input())
    
    if no_1 <= num:
        no_2 = no_1
        no_1 = num
        pos_1 = i
        
    elif no_2 < num:
        no_2 = num
    
for i in range (0, N):
    if i == pos_1:
        print(no_2)
    else:
        print(no_1)

Solution (Python):
import numpy as np

N = int(input())
A = []
for i in range(N):
        a = int(input())
        A.append(a)
 
idx = np.argmax(np.array(A))
idx2 = np.argmax(np.array(A[:idx] + A[idx+1:]))
if idx2 >= idx:
        idx2 += 1

for i in range(N):
        if i != idx:
                print(A[idx])
        else:
                print(A[idx2])

Solution (Python):
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
amax = max(a)
amax_id = int(a.index(amax))
a.pop(amax_id)
amax2 = max(a)
for i in range(n):
  if i == amax_id:
    print(amax2)
  else:
    print(amax)

Solution (Python):
import sys
input = sys.stdin.readline

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

c = sorted(a,reverse = True)

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

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

m = max(a)
m_num = a.count(m)
if m_num > 1:
    for i in range(n):
        print(m)
else:
    ind_m = a.index(m)
    a.pop(ind_m)
    sec_m = max(a)
    for i in range(n):
        print(m) if i != ind_m else print(sec_m)

Solution (Python):
import numpy as np
import copy
  
N = int(input())  
A = np.zeros(N)

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

ans = int(np.max(A))
K = np.where(A == ans)[0]
k = np.where(A == ans)[0][0]

if K.size > 1:
    for i in range(N):
        print(ans)
        
else:
    for i in range(N):
        if i == k:
            B = np.delete(A, i)
            print(int(np.max(B)))
    
        else:
            print(ans)

Solution (Python):
n = int(input())
l = []
for i in range(n):
	l.append(int(input()))
maxnum = max(l)
maxidx = l.index(maxnum)

for i,e in enumerate(l):
	if i == maxidx:
		lwomax = l[:]
		lwomax.pop(maxidx)
		print(max(lwomax))
	else:
		print(maxnum)

Solution (Python):


def solve():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    Amax = max(A)
    A2 = A.copy()
    A2.remove(Amax)
    Asecond = max(A2)
    for a in A:
        if a == Amax:
            print(Asecond)
        else:
            print(Amax)


if __name__ == '__main__':
    solve()

Solution (Python):
n=int(input())
ls=[int(input()) for i in range(n)]
ls_sort=sorted(ls)

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

for i in ls:
    if i==max_1:
        print(max_2)
    else:
        print(max_1)

Solution (Python):
import numpy as np


def main():
	
	N = int(input())
	
	max_num = 0
	sub_max = 0
	index = 0
	for i in range(N):
		num = int(input())
		if num > max_num:
			index = i
			sub_max = max_num
			max_num = num
		elif num > sub_max:
			sub_max = num

	for i in range(N):
		if i == index:
			print(sub_max)
		else:
			print(max_num)

if __name__ == "__main__":
	main()

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

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

saidai1=max(a_list)
saidai1_index=a_list.index(saidai1)
saidai2=max(a_list[:saidai1_index]+a_list[saidai1_index+1:])

for i in range(n):
  if a_list[i]==saidai1:
    print(saidai2)
  else:
    print(saidai1)

Solution (Python):
import sys
sysinput = sys.stdin.readline

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

A_sort = sorted(A)
ans_list =[]
for A_i in A:
  if A_i == A_sort[-1]:
    ans_list.append(A_sort[-2])
  else:
    ans_list.append(A_sort[-1])

for ans in ans_list:
  print(ans)

Solution (Python):
N = int(input())
List = []

for i in range(1,N+1):
  List.append(int(input()))
list1 = List.copy()
List.sort(reverse=True)
MAX = List[0]
SEC_MAX = List[1]
for i in list1:
  if i != MAX:
    print(MAX)
  else:
    print(SEC_MAX)

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

Solution (Python):
import numpy as np
import math

N = int(input())

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


max_a = np.max(A)
max_i = np.argmax(A)

for i in range(N):
   if(i == max_i):
      aa = np.sort(A)
      print(int(aa[-2]))
   else:
      print(int(max_a))

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

a_max=max(a)

if a.count(a_max)>=2:
    for i in range(n):
        print(a_max)
else:
    max_ind=a.index(a_max)
    a.remove(a_max)
    a_2nd=max(a)
    for _ in range(1,max_ind+1):
        print(a_max)
    print(a_2nd)
    for _ in range(max_ind+1,n):
        print(a_max)

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

Solution (Python):
b = []
n = int(input())
m = 0
for i in range(n):
  a = int(input())
  b.append(a)
  if m < a:
    m = a
    c = [i]
  elif m == a:
    c.append(i)

if len(c) != 1:
  for i in range(n):
    print(m)
else:
  del b[c[0]]
  for i in range(n):
    if i == c[0]:
      print(max(b))
    else:
      print(m)

Solution (Python):
n = int(input())
a = []

maxx = 0
submax = 0

for i in range(n):
    k = int(input())
    if k > maxx:
        submax = maxx
        maxx = k
    elif k > submax:
        submax = k

    a.append(k)

for i in range(n):
    if a[i] == maxx:
        print(submax)
    else:
        print(maxx)

Solution (Python):
import copy
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
b=copy.copy(a)
b.sort()
for i in range(n):
    max=b[n-1]
    if(a[i]==max):
        max=b[n-2]
    print(max)

Solution (Python):
n = int(input())
a = []
max1 = 0
max2 = 0
for i in range(n):
    j = int(input())
    a.append(j)
    if j > max1:
        max2 = max1
        max1 = j
    elif j > max2:
        max2 = j
for i in a:
    print(max1 if i != max1 else max2)

Solution (Python):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_sort = list(sorted(a))
a_max = a_sort[-1]
a_second = a_sort[-2]
for i in range(n):
    if a[i] == a_max:
        print(a_second)
    else:
        print(a_max)

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

sorted_A = sorted(A, reverse=True)

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

Solution (Python):
from sys import stdin

if __name__ == '__main__':
    N = int(stdin.readline().rstrip())

    A = []
    for i in range(N):
        A.append(int(stdin.readline().rstrip()))
    B = A.copy()
    A.sort(reverse=True)

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

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

if a_[-1] == a_[-2]:
    for i in range(n):
        print(a_[n-1])
    exit()

b = list(set(a))

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

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

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

L = [0] * (N+1)
R = [0] * (N+2)
A.append(0)

for i in range(1, N+1):
    if i == 1:
        L[1] = 0
        R[N+1] = 0
    L[i] = max(L[i-1], A[i-2])
    R[N-i+1] = max(R[N-i+2], A[N-i+1])

for i in range(1, N+1):
    print(max(L[i], R[i]))

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

b = a[::-1]

amax = [0] * n
bmax = [0] * n

amax[0] = a[0]
bmax[0] = b[0]
for i in range(1, n):
    amax[i] = max(amax[i-1], a[i])
    bmax[i] = max(bmax[i-1], b[i])

bmax = bmax[::-1]

print(bmax[1])
for i in range(1, n-1):
    print(max(amax[i-1], bmax[i+1]))
print(amax[n-2])

Solution (Python):
n=input()
n=int(n)
l=[]
for i in range(n):
    x=input()
    x=int(x)
    l.append(x)
ans=max(l)
x=l.index(ans)
del l[x]
sec=max(l)
for i in range(n):
    if i==x:
        print(sec)
        continue
    print(ans)

Solution (Python):
n=int(input())
a=[0]*n
for i in range(n):
    a[i] = int(input())
import numpy as np
b=np.array(a).argsort()
imax1=b[-1]
amax=a[imax1]
for j in range(n):
    if j==imax1: print(a[b[-2]])
    else:print(amax)

Solution (Python):
n=int(input())
alist=[int(input()) for i in range(n)]
max_value=max(alist)
acount=alist.count(max_value)
if acount!=1:
	for i in range(n):
		print(max_value)
else:
	for i in range(n):
		if alist[i]!=max_value:
			print(max_value)
		else:
			blist=alist[:]
			del blist[i]
			print(max(blist))

Solution (Python):
N = int(input())
A =[]
for _ in range(N):
  A.append(int(input()))
a = max(A)
a2= max(sorted(A)[:-1])
f = False
if(a == a2):
  f = True
for i in range(N):
  if(f):
    print(a)
  elif(A[i] == a):
    print(a2)
  else:
    print(a)

Solution (Python):
n = int(input())
lst = [int(input()) for i in range(n)]
m = max(lst)
tmp = lst[:]
del tmp[tmp.index(max(tmp))]
s = max(tmp)
if lst.count(m) > 1:
  for i in range(n):
    print(m)
else:
  for i in range(n):
    if lst[i]==m:
      print(s)
    else:
      print(m)

Solution (Python):
N=int(input())
A=[]
for _ in range(N):
  A.append(int(input()))
  
B=sorted(A)
M1=B[-1]
M2=B[-2]

if B.count(M1)>1:
    for i in range(N):
        print(M1)
else:
    for i in range(N):
        if A[i] == M1:
            print(M2)
        else:
            print(M1)

Solution (Python):
import fractions
from collections import deque
import numbers as np
import math


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ids = [i for i in range(N)]
    C = list(zip(A, ids))
    sort = sorted(C, key=lambda x: x[0], reverse=True)
    rest = [sort[0][0] for _ in range(N)]
    rest[sort[0][1]] = sort[1][0]
    for i in range(N):
        print(rest[i])


if __name__ == "__main__":
    main()

Solution (Python):
import copy
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())
amax = max(A)
B = copy.copy(A)
B.remove(amax)
nextmax = max(B)


for i in range(N):
    if A[i] == amax:
        print(nextmax)
    else:
        print(amax)

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

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

b_in = a_list.index(max(a_list))
b_max = max(a_list)

a_list.pop(b_in)

c_max = max(a_list)

for i in range(N):
    if b_in != i:
        print(b_max)
    else:
        print(c_max)

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

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

max1 = max(A)
if A.count(max1) >= 2:
    max2 = max1
else:
    max2 = 0
    for num in A:
        if max2 < num and max1 > num:
            max2 = num

for num in A:
    if num == max1:
        print(max2)
    else:
        print(max1)

Solution (Python):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
sorted_A = sorted(A,reverse=True)
m1 = sorted_A[0]
m2 = sorted_A[1]

for Ai in A:
  if Ai != m1:
    print(m1)
  else:
    print(m2)

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
maxa = max(a)
max_index = [i for i, x in enumerate(a) if x == maxa]
if len(max_index) >= 2:
    for i in range(n):
        print(maxa)
else:
    for i in range(n):
        if i == max_index[0]:
            print(sorted(a)[-2])
        else:
            print(maxa)

Solution (Python):
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
max_A = max(A)
max_index = A.index(max_A)
A.pop(max_index)
next_max = max(A)
for i in range(N):
    if i == max_index:
        print(next_max)
    else:
        print(max_A)

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

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

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):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    As = [int(stdin.readline().rstrip()) for _ in range(N)]
    max1 = max(As)
    if len([x for x in As if x == max1]) == 1:
        max2 = max([x for x in As if x != max1])
    else:
        max2 = max1
    for A in As:
        if A == max1:
            print(max2)
        else:
            print(max1)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
ma = max(a)
b = [x for x in a]
b.remove(ma)
ma2 = max(b)
if a.count(ma) > 1:
    for i in range(n):
        print(ma)
else:
    for i in range(n):
        if a[i] == ma:
            print(ma2)
        else:
            print(ma)

Solution (Python):
import sys

def solve():
    pass

def main():
    N = int(input())
    A = [ (i, int(input())) for i in range(N) ]
    A.sort(key=lambda x: x[1], reverse=True)
    
    for i in range(N):
        if i == A[0][0]:
            print(A[1][1])
        else:
            print(A[0][1])

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = []
A_ap = A.append
for i in range(N):
    A_ap(int(input()))
    
max_A = sorted(A)[-1]
max_2A = sorted(A)[-2]
for i in range(N):
    if A[i] != max_A:
        print(max_A)
    else:
        print(max_2A)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)] 
a_sorted = sorted(a,reverse=True)
first = a_sorted[0]
second = a_sorted[1]
for ai in a:
  if ai==first:
    print(second)
  else:
    print(first)

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

first = sorted(A)[-1]
second = sorted(A)[-2]

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

Solution (Python):
import numpy as np
N = int(input())
A=[]
for i in range(N):
    A.append(int(input()))

sec = sorted(A)[-2]
a = np.array(A)
maxA=max(a)
maxIndex = [i for i, x in enumerate(a) if x == maxA]
l=len(maxIndex)
for i in range(N):
    if l !=1:
        print(maxA)
    elif i in maxIndex:
        print(sec)
    else:
        print(maxA)

Solution (Python):
n = int(input())
a_list = [int(input()) for _ in range(n)]
if a_list[0] > a_list[1]:
    i_max = 0
    i_max2 = 1
else:
    i_max = 1
    i_max2 = 0
a_max = a_list[i_max]
a_max2 = a_list[i_max2]
for i, a in enumerate(a_list):
    if i < 2:
        continue
    if a > a_max:
        i_max2 = i_max
        a_max2 = a_max
        i_max = i
        a_max = a
    elif a > a_max2:
        i_max2 = i
        a_max2 = a
for i in range(n):
    if i == i_max:
        print(a_max2)
    else:
        print(a_max)

Solution (Python):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
sortedA = sorted(a)
if sortedA[-1] == sortedA[-2]:
    for j in range(n):
        print(sortedA[-1])
else:
    l = a.index(sortedA[-1])
    for j in range(l):
        print(sortedA[-1])
    print(sortedA[-2])
    for k in range(n-l-1):
        print(sortedA[-1])

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

maximum = max(a)
if a.count(maximum):
    num = a.index(maximum)
    x = max(a[:num]+a[num+1:])
    for _ in range(num):
        print(maximum)

    print(x)

    for _ in range(num+1, n):
        print(maximum)

else:
    for _ in range(n):
        print(maximum)

Solution (Python):
n=int(input())
A=[int(input()) for i in range(n)]
B=sorted(A)
f=B[-1]
s=B[-2]
q=A.index(f)

for i in range(q):
  print(f)
print(s)
for i in range(n-q-1):
  print(f)

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

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

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

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

mx2 = -1
cnt = 0
for i in range(N):
    if A[i] == mx1:
        cnt += 1
    else:
        mx2 = max(mx2, A[i])
    if cnt == 2:
        break
if mx2 == -1:
    mx2 = mx1
for i in range(N):
    if cnt >= 2:
        print(mx1)
    else:
        if A[i] == mx1:
            print(mx2)
        else:
            print(mx1)

Solution (Python):
import sys

def main():
    N = int(input())
    As = list(map(int, sys.stdin.readlines()))

    max_a = max(As)
    max_count = As.count(max_a)

    if max_count > 1:
        for _ in range(N):
            print(max_a)
        sys.exit()
    
    _As = As[:]
    _As.remove(max_a)
    max_a2 = max(_As)

    for i in As:
        if i == max_a:
            print(max_a2)
        else:
            print(max_a)
    
if __name__=='__main__':
    main()

Solution (Python):

import numpy as np

n = int(input())

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

a_s = sorted(a, reverse=True)
a_max = a_s[0]
a_max_2 = a_s[1]

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

Solution (Python):
N=int(input())
fir=0
sec=0
adr=[]
for i in range(N):
  a=int(input())
  if a==fir:
    adr.append(i)
  elif a>fir:
    sec=fir
    fir=a
    adr=[i]
  elif a<fir:
    if a>sec:
      sec=a
if len(adr)==1:
  for i in range(N):
    if i!=adr[0]:
      print(fir)
    else:
      print(sec)
else:
  for i in range(N):
    print(fir)

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

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

Solution (Python):
import numpy as np
N = int(input())
a = []
for i in range(N):
  a.append(int(input()))
aa = np.array(a)
max_a = max(aa)
k = np.argmax(aa)
aa[k] = 0
m = max(aa)


for i in range(N):
  if i == k:
    print(m)
  else:
    print(max_a)

Solution (Python):
n=int(input())
a=[int(input()) for i in range(n)]
max1=sorted(a)[-1]
if n==2:
    print(a[1])
    print(a[0])
elif sorted(a)[-2]!=max1:
    max=sorted(a)
    max2=0
    for i in range(2,n):
        if max[-i]!=max1:
            max2=max[-i]
            break
    for i in range(n):
        if a[i]==max1:
            print(max2)
        else:
            print(max1)
else:
    for i in range(n):
        print(max1)

Solution (Python):
N = int(input())
values = []

for i in range(N):
  values.append(int(input()))
  
a = max(values)

copy_values = [v for v in values]

copy_values.remove(a)

if len(copy_values) == 0:
  b = a
else:
  b = max(copy_values)

for i in range(N):
  if values[i] == a:
    print(b)
  else:
    print(a)

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

firstMax = 0
secondMax = 0
firstMaxIndex = -1

for i in range(N):
    num = int(input())
    if firstMax < num:
        firstMax = num
        firstMaxIndex = i
    elif secondMax < num:
        secondMax = num

for i in range(N):
    if i == firstMaxIndex:
        print(secondMax)
    else:
        print(firstMax)

Solution (Python):
import sys
import copy


def input():
    return sys.stdin.readline()[:-1]


def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    a2 = copy.copy(a)
    a2.sort()
    m = a2[len(a)-1]
    m2 = a2[len(a)-2]

    for i in a:
        if i != m:
            print(m)
        else:
            print(m2)


if __name__ == "__main__":
    main()

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

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

new_list=sorted(A)
second=new_list[N-2]


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

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    N = [int(x) for x in sys.stdin.readline().split()][0]
    a_list = [[int(x) for x in sys.stdin.readline().split()][0]
              for _ in range(N)]

    logger.debug('{} {}'.format(N, a_list))

    max1, max2 = sorted(a_list, reverse=True)[:2]

    for a in a_list:
        if a == max1:
            print(max2)

        else:
            print(max1)


if __name__ == "__main__":
    resolve()





import sys
from io import StringIO
import unittest


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)

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

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


ans = [0]*N
a1 = max(A)
cnt = A.count(a1)

for i in range(N):
    if (A[i]==a1)and(cnt==1):
        B = copy.deepcopy(A)
        del(B[i])
        ans[i]=max(B)
    else:
        ans[i]=a1

for i in range(N):
    print(ans[i])

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

    mx = max(A)
    sec = sorted(A)[-2]
    for i in range(N):
        s = A[i]
        if mx != s:
            print(mx)
        else:
            print(sec)

resolve()

Solution (Python):

from collections import defaultdict
n = int(input())
a_cnt = defaultdict(int)
a_list = [0 for _ in range(n)]
for i in range(n):
    num = int(input())
    a_cnt[num] += 1
    a_list[i] = num

a_sort = sorted(a_cnt.keys(), reverse=True)

largest_num = a_sort[0]
if len(a_sort) == 1:
    second_num = largest_num
else:
    second_num = a_sort[1]

if a_cnt[largest_num] == 1:
    for num in a_list:
        if largest_num == num:
            print(second_num)
        else:
            print(largest_num)
else:
    for _ in a_list:
        print(largest_num)

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



N0 = 2**(N-1).bit_length()
INF = 2**31-1
data = [0]*(2*N0)


def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = max(data[2*k+1], data[2*k+2])


def query(l, r):
    L = l + N0
    R = r + N0
    s = 0
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])

        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1
        R >>= 1
    return s


for i, a in enumerate(A):
    update(i, a)

l, r = 0, 1
for _ in range(N):
    a, b = query(0, l), query(r, N)
    print(max(a, b))
    l += 1
    r += 1

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

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

t = a
a = sorted(a)
memo = a[n-1]

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

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

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

M = max(l)
ind = l.index(M)
if ind==0:
    m = max(l[1:])
elif ind==N-1:
    m = max(l[:N-1])
else:
    m = max(max(l[0:ind]),max(l[ind+1:]))
for i in range(N):
    if i == ind:
        print(m)
    else:
        print(M)

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

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

max_a = max(A)
aa = sorted(A, reverse=True)
second = aa[1]
flag = second == max_a

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

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

if count > 1:
    for n in range(N):
        print(max_a)
else:
    for n in range(N):
        if A[n] == max_a:
            print(max(A[:n] + A[n+1:]))
            continue
        print(max_a)

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

maxNum= 0
maxIndex= -1
secondNum= 0



for i in range(N):
    tmp= int(input())
    if tmp> maxNum :
        secondNum= maxNum
        maxNum= tmp
        maxIndex= i
    elif tmp> secondNum:
        secondNum= tmp



for j in range(N):
    if(j == maxIndex):
        print(secondNum)
    else :
        print(maxNum)

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

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

B = sorted(A)
m, n = B[N - 2], B[N - 1]
tie = False
if m == n:
  tie = True

for i in range(N):
  if A[i] == n:
    if tie:
      print(n)
    else:
      print(m)
  else:
    print(n)

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

b = sorted(a)

t1 = b[-1]
t2 = b[-2]

for i in a:
    if i == t1:
        print(t2)
    else:
        print(t1)

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

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

A_sorted=sorted(A,reverse=True)

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

Solution (Python):
import sys
p = [int(r) for r in  sys.stdin.read().split('\n') if r != '']
N = p[0]
A = p[1:]
b = sorted(A)
m = b[-1]
l = b[-2]
for i, n in enumerate(A):
    print(m if A[i] != m else l)

Solution (Python):
n = int(input())
A = [int(input()) for _ in range(n)]
max_num, second_num = sorted(A, reverse=True)[:2]

for a in A:
  if a==max_num: print(second_num)
  else: print(max_num)

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

Amax = -1
Amax2 = -1
index = -1
index2 = -1

for i in range(N) :
    if Amax < A[i] :
        Amax = A[i]
        index = i

if A.count(Amax) > 1 :
    for i in range(N) :
        print(Amax)
    exit()

for i in range(N) :
    if i == index :
        continue
    if Amax2 < A[i] :
        Amax2 = A[i]
        index2 = i

for i in range(N) :
    if i == index :
        print(Amax2)
    else :
        print(Amax)

Solution (Python):
from sys import stdin

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

    a = sorted(A, reverse=1)
    for i in A:
        if i < a[0]:
            print(a[0])
        else:
            print(a[1])

input = lambda: stdin.readline()
main()

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

A=[]

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

    A.append(d)

A.sort(key=lambda x:x[0])



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

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
sorted_A = sorted(A)
max_num = sorted_A[-1]
for a in A:
    if a == max_num:
        print(sorted_A[-2])
    else:
        print(max_num)

Solution (Python):

N = int(input())
S = [0,0]
index = 0

for i in range(N):
	A = int(input())
	if A > S[0]:
		S[1] = S[0]
		S[0] = A
		index = i
	elif A > S[1]:S[1] = A

for i in range(N):
	if i != index:
		print(S[0])
	else:
		print(S[1])

Solution (Python):
import numpy as np
N = int(input())
A = [int(input()) for _ in range(N)]
MA = max(A)
ans = [MA] * N
MAI = np.argmax(np.array(A))
A[MAI] = 1
MA2 = max(A)
ans[MAI] = MA2
for a in ans :
    print(a)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
B = [0]*(N+2)
C = [0]*(N+2)
for i in range(1,N+1):
    B[i] = max(A[i-1], B[i-1])
    C[-i-1] = max(A[-i], C[-i])
for i in range(1,N+1):
    print(max(B[i-1], C[i+1]))

Solution (Python):
n = int(input())
l = []
for i in range(n):
    l.append([int(input()), i])
l.sort(reverse=True)
m1 = l[0][0]
m2 = l[1][0]
id1 = l[0][1]
for i in range(n):
    if i == id1:
        print(m2)
    else:
        print(m1)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline






















def main():

	N = int(input())
	
	
	

	A = []
	a_max = 0
	for i in range(N):
		tmp = int(input())
		A.append(tmp)
		if a_max < tmp:
			a_max = tmp

	B = copy.deepcopy(A)
	B.sort()
	for i in A:
		if i == a_max:
			print(B[-2])
		else:
			print(a_max)



if __name__ == "__main__":
	main()

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

s = sorted(A)
ans = []

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

Solution (Python):
n = int(input())
A = [int(input()) for _ in range(n)]
A_Sorted = sorted(A)
A_max = A_Sorted[n-1]
A_sec = A_Sorted[n-2]

for i in range(n):
    a = A[i]
    if a == A_max:
        print(A_sec)
    else:
        print(A_max)

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




for i in range(N):
    if A[i] > first_max:
        second_max = first_max
        first_max = A[i]
        
    elif A[i] > second_max:
        second_max = A[i]

for i in range(N):
    if A[i] == first_max:
        print(second_max)
    else:
        print(first_max)