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):


import numpy as np


def solv(a):
    idx = np.argsort(a)
    top_index = idx[-1]
    top = a[top_index]
    second = a[idx[-2]]
    for i in range(n):
        if i != top_index:
            print(top)
        else:
            print(second)


if __name__ == '__main__':

    n = int(input())
    a = np.empty(n, dtype=np.int)

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

    solv(a)

Solution (Python):
import sys

N=int(sys.stdin.readline().rstrip())
AList=[]
for i in range(N):
  AList.append(int(sys.stdin.readline().rstrip()))
  
Alistsort=sorted(AList,reverse=True)
last=Alistsort[0]
semiLast=Alistsort[1]

for a in AList:
  if a == last:
    print(semiLast)
  else:
    print(last)

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

p = sorted(s)
next = p[-2]

ind = s.index(max)

for j in range(len(s)):
    if j==ind:
        print(next)
    else:
        print(max)

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

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

S = sorted(A)

m1 = max(A)
m2 = S[-2]

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

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

idx = num.index(max(num))
max_a = max(num)

num_c = num
num_c[idx] = 0
idx_2 = num_c.index(max(num_c))
max_a2 = max(num_c)

for i in range(n):
    if i == idx:
        print(max_a2)
    else:
        print(max_a)

Solution (Python):
import copy
N = int(input())
a = [input() for i in range(N)]
a = list(map(int, a))
max_a = sub_max_a = max(a)
count = 0
for i in range(N):
    if max_a == a[i]:
        count += 1
        max_i = i
if count == 1:
    a.pop(max_i)
    sub_max_a = max(a)

for j in range(N):
    if max_i == j:
        print(sub_max_a)
    else:
        print(max_a)

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

max_ = -1
max_2 = -1
for i in range(n):
    if i == 0:
        tmp = a[i]
        a[i] = 0
        max_ = max(a)
        print(max_)
        a[i] = tmp
        if a[0]>=max_:
            max_ = a[0]
        continue
    else:
        if max_<=a[i]:
            if max_2 == -1:
                tmp = a[i]
                a[i] = 0
                max_2 = max(a)
                print(max_2)
                a[i] = tmp
            else:
                print(max_2)
        else:
            print(max_)

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

A = []
max1 = 0
max1i = 0
max2 = 0
max2i = 0

for i in range(N):
  B = int(input())
  if B>max1:
    max1i = i
    max1 = B
  else:
    if B>max2:
      max2 = B
      max2i = i

for i in range(N):
  A.append(max1)
A[max1i] = max2

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

Solution (Python):
n = int(input())
n_1 = -1
n_2 = -1
index1 = -1
index2 = -1
for i in range(n):
    a = int(input())
    if a >= n_1:
        n_1 , n_2 = a ,n_1 
        index1, index2 = i, index1
    elif a >= n_2:
        n_2 = a
        index2 = i
    
for i in range(n):
    if i == index1:
        print(n_2)
    else:
        print(n_1)

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 sorted_a[0] != sorted_a[1]:
		if a[i] != sorted_a[0]:
			print(sorted_a[0])
		else:
			print(sorted_a[1])
	else:
		print(sorted_a[0])

Solution (Python):
import sys
import numpy as np

N = int(sys.stdin.readline())
a = np.fromstring(sys.stdin.read(), dtype=np.uint32, sep=' ')
maxi = np.argmax(a)
max_value = a[maxi]
a[maxi] = 0
mnext = a.max()

for i in range(N):
    if i == maxi:
        print(mnext)
    else:
        print(max_value)

Solution (Python):

import numpy as np
n = int(input())

a = np.zeros((n))
for i in range(n):
    a_tmp = int(input())
    a[i] = a_tmp

f_max = np.zeros((n))
b_max = np.zeros((n))
for i in range(n):
    if i == 0:
        f_max[0] = a[0]
        b_max[n-1] = a[n-1]
    else:
        f_max[i] = max(f_max[i-1],a[i])
        b_max[n-1-i] = max(b_max[n-1-i+1],a[n-1-i])




for i in range(n):
    if i == 0:
        print(int(b_max[1]))
    elif i == (n-1):
        print(int(f_max[n-2]))
    else:
        
        print(int(max(b_max[i+1],f_max[i-1])))

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

m = max(a)
idxs = [i for i, v in enumerate(a) if v == m]

if len(idxs) > 1:
    for i in range(n):
        print(m)

if len(idxs) == 1:
    idx = idxs[0]
    for i in range(n):
        if idx == i:
            _a = a.copy()
            _a.pop(i)
            print(max(_a))
        else:
            print(m)

Solution (Python):
import numpy as np

N = int(input())

A = [0] * N

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

B = np.argsort(A)
A = np.sort(A)

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

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



max_val = max(A)
if len([i for i, x in enumerate(A) if x == max_val]) > 1:
    for i in range(0,N):
        print(max_val)
else:
    max_val_index = A.index(max_val)
    A[max_val_index] = 0
    sec_max_val = max(A)
    for i in range(0,N):
        if i == max_val_index:
            print(sec_max_val)
        else:
            print(max_val)

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

info2=sorted(info,reverse=True)
max1=info2[0]
max2=info2[1]

for i in range(n):
    if info[i]==max1:
        print(max2)
    else:
        print(max1)

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

A_no1 = max(A)
Index_A_no1 = [i for i, x in enumerate(A) if x == A_no1]

if len(Index_A_no1) > 1:
  for n in range(N):
    print(A_no1)

else:
  AA = [a for a in A if a != A_no1]
  A_no2 = max(AA)
  Index_A_no1 = [i for i, x in enumerate(A) if x == A_no1]
  
  for n in range(N):
    if n in Index_A_no1:
      print(A_no2)
    else:
      print(A_no1)

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

Solution (Python):
n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
max1 = max(a)
idx = a.index(max1)
a[idx] = 0
max2 = max(a)

for i in range(n):
	if i != idx:
		print(max1)
	else:
		print(max2)

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

A_list = [int(input()) for i in range(n)]
sort_A = sorted(A_list)
mA =  sort_A[-1]
second = sort_A[-2]
for i in A_list :
  if i == mA :
    print(second)
  else :
    print(mA)

Solution (Python):
N = int(input())
a = [0]*N
b = [0]*N
for i in range(N):
    a[i] = int(input())
    b[i] = a[i]
m = max(b)
b.remove(m)
n = max(b)

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

Solution (Python):
import copy

n = int( input() )

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

max_num = max(a)
semi_max = 0
if a.count(max_num) == 1:
    tmp = copy.copy(a)
    tmp.remove(max_num)
    semi_max = max(tmp)
    for i in range(n):
        if a[i] == max_num:
            print(semi_max)
        else:
            print(max_num)
else:
    for i in range(n):
        print(max_num)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
aa=[]
for i in range(n):
    aa.append(int(input()))
ma = max(aa)
if aa.count(ma) > 1:
    for _ in range(n):
        print(ma)
else:
    for i in range(n):
        if aa[i] != ma:
            print(ma)
        else:
            print(max(aa[:i]+aa[i+1:]))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    a = [INT() for _ in range(n)]
    a_ = a.copy()
    a_.sort()
    m1, m2=a_[-1], a_[-2]

    for x in a:
        if x == m1:
            print(m2)
        else:
            print(m1)

if  __name__=='__main__':
    main()

Solution (Python):
import copy
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
a=max(A)
b=A.index(a)
for j in range(N):
    if j!=b:
        print(a)
    else:
        B=copy.copy(A)
        C=B.pop(j)
        print(max(B))

Solution (Python):
import copy
n = int(input())
ls = []
for i in range(n):
    a = int(input())
    ls.append(a) 
ls2 = copy.copy(ls)
ls.sort()
max1 = ls[-1]
max2 = ls[-2]


for i in ls2:
    if i != max1:
        print(max1)
    else:
        print(max2)

Solution (Python):


import os
import sys

N = int(input())

A = []

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

X = [[A[i], i] for i in range(N)]


X.sort(key = lambda x: x[0], reverse=True)


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

Solution (Python):











n = int(input())
ans = 0
most1 = 0
most2 = 0
ed = False
for i in range(n):
    t = int(input())
    ed = False
    if most1 <= t:
        most2 = most1
        most1 = t
        ans = i
        ed = True
    elif most2 <= t and ed == False:
        most2 = t
for i in range(n):
    if i==ans:print(most2)
    else:print(most1)

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

AL=[A[0]]
AR=[A[-1]]
for i in range(1,N):
    AL.append(max(A[i],AL[i-1]))
    AR.append(max(A[N-i-1],AR[i-1]))
AR.reverse()
del AL[-1]
del AR[0]

print(AR[0])
for i in range(1,N-1):
    print(max(AL[i-1],AR[i]))
print(AL[-1])

Solution (Python):
N=int(input())
maxi=0
smaxi=0
flag=0
ls=[]
x=0
for i in range(N):
  x=int(input())
  ls.append(x)
  if (maxi<x):
    smaxi=maxi
    maxi=x
  elif (maxi==x):
    smaxi=maxi
  elif (smaxi<x):
    smaxi=x
for i in range(N):
  if (ls[i]==maxi):
    print(smaxi)
  else:
    print(maxi)

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

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

a1 = sorted(a, reverse=True)
maxmax = max(a)
max2 = a1[1]

for i in range(n):
    if a[i] == maxmax:
        print(max2)
    else:
        print(maxmax)

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

A_sorted = sorted(A, reverse=True, key=lambda x: x[0])
A_sorted = list(enumerate(A_sorted))
A = sorted(A_sorted, key=lambda x: x[1][1])

for r, t in A:
    a, _ = t
    if r == 0:
        print(A_sorted[1][1][0])
    else:
        print(A_sorted[0][1][0])

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

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

_max = max(a)
max_idx = a.index(_max)
a.remove(_max)
second = max(a)
for i in range(n):
    if i == max_idx:
        print("{}".format(second))
    else:
        print("{}".format(_max))

Solution (Python):


''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N = int(input())

    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)
    ii = A.index(max(A))
    m = max(A)
    A.pop(ii)
    m2 = max(A)
    
    for i in range(N):
        if i == ii:
            print(m2)
        else:
            print(m)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
A = []
for _ in range(n):
  x = int(input())
  A.append(x)
standard = max(A)
counter = A.count(max(A))
for i in range(n):
  if A[i] != standard:
    print(standard)
  elif counter >=2:
    print(standard)
  else:
    temp = 0
    for t in range(n):
      if t != i:
        if A[t] >= temp:
          temp = A[t]
    print(temp)

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

b = sorted(a)
max1 = b[N-1]
max2 = b[N-2]

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

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

for i in range(0, N):
    tmp = int(input())
    A.append(tmp)

MAX = max(A)
MAX_i = numpy.argmax(A)
tmp = A.pop(MAX_i)
MAXsecond = max(A)
A.insert(MAX_i, tmp)

for i in range(0, N):
    if A[i] == MAX:
        print(MAXsecond)
    else:
        print(MAX)

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

A_l = [A[0]] 
A_r = [A[N-1]] 

for i in range(1,N-1):
    A_l.append(max(A_l[i-1],A[i]))

for i in range(1,N-1):
    A_r.append(max(A_r[i-1],A[-(i+1)]))

ans =[]
ans.append(A_r[N-2])
for k in range(N-2):
    ans.append(max(A_l[k],A_r[-(k+2)]))

ans.append(A_l[N-2])

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

Solution (Python):
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
m=max(a)
c=a.count(m)
i=a.index(m)
if(c!=1):
    for j in range(n):
        print(m)
else:
    a.remove(m)
    mm=max(a)
    for j in range(n):
        if(j==i):
            print(mm)
        else:
            print(m)

Solution (Python):


n = int(input())

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

s_A = sorted(A, reverse=True)

max_a, second_a = s_A[0], s_A[1]

for i in range(n):
    if A[i] == max_a:
        print(second_a)
    else:
        print(max_a)

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

suuretu_list = []
kari_list = []

for i in range(a):
    b = int(input())
    suuretu_list.append(b)
    kari_list.append(b)

kari_list = sorted(kari_list)

c = max(suuretu_list)

d = suuretu_list.index(c)

for u in suuretu_list:
    if u != c:
        print(c)
    else:
        print(kari_list[-2])

Solution (Python):
def main():
  number_cnt = int(input())
  max_1 = 0
  max_2 = 0
  max_1_index = 0
  for i in range(number_cnt):
    tmp = int(input())
    if tmp > max_1:
      max_2 = max_1
      max_1 = tmp
      max_1_index = i
    elif tmp > max_2:
      max_2 = tmp
  for i in range(number_cnt):
    if i == max_1_index:
      print(max_2)
    else:
      print(max_1)
    
main()

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
m = max(A)
A_i = A[:]
A_i.remove(m)
m_i = max(A_i)
for i in range(N):
    if A[i] == m:
        print(m_i)
    else:
        print(m)

Solution (Python):
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]

a = list(itertools.accumulate(A, max))
b = list(itertools.accumulate(A[::-1], max))[::-1]

for i in range(len(A)):
    r = 0
    if 0 <= i - 1 < N:
        r = max(r, a[i - 1])
    if 0 <= i + 1 < N:
        r = max(r, b[i + 1])
    print(r)

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

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
a_s = sorted(a)
max1 = a_s[-1]
max2 = a_s[-2]
if max1 == max2:
    for i in range(n):
        print(max1)
else:
    for i in range(n):
        if a[i] == max1:
            print(max2)
        else:
            print(max1)

Solution (Python):
a = [int(input()) for i in range(int(input()))]
sortedA = sorted(a, reverse=True)
for i in range(len(a)):
    if a[i] == sortedA[0]:
        print(sortedA[1])
    else:
        print(sortedA[0])

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

b = sorted(a)

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

Solution (Python):

N = int(input())
A=[]
for i in range(N):
    A.append(int(input()))
max1 = max(A)
max_index = A.index(max1)
A.remove(max1)
max2 = max(A)

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

Solution (Python):
def resolve():
    n = int(input())
    li = [int(input()) for _ in range(n)]

    sorted_li = sorted(li)

    max_index = li.index(sorted_li[-1])

    for i in range(n):

        if i == max_index:
            print(sorted_li[-2])

        else:
            print(sorted_li[-1])

resolve()

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
lmax = [0]
rmax = [0]
for i in range(N-1):
  lmax.append(max(lmax[i],A[i]))
  rmax.append(max(rmax[i],A[N-1-i]))
 
rmax = rmax[::-1]

for i in range(N):
  print (max(lmax[i], rmax[i]))

Solution (Python):
n=int(input())
lst=[int(input()) for x in range(n)]
M=sorted(set(lst))[-1]
num=lst.count(M)
if num>=2:
  for x in lst:
    print(M)
else:
  m=sorted(set(lst))[-2]
  for x in lst:
    if x==M:
      print(m)
    else:
      print(M)

Solution (Python):
N = int(input())
A = [int(input()) for i in [0] * N ]
M = max(A)
m = sorted(A)[-2]
for i in A:
  if i == M:
    print(m)
  else:
    print(M)

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

A1 = 0
A2 = 0
index = -1
for i in range(N):
    if A1 == 0:
        A1 = max(A1,A[i])
        index = i
    else:
        tmp = max(A2,A[i])
        if A1 <= A[i]:
            A2 = A1
            A1 = A[i]
            index = i
        elif A2 <= tmp:
            A2 = tmp

if A1 == A2:
    for i in range(N):
        print(A1)
else:
    for i in range(N):
        if i == index:
            print(A2)
        else:
            print(A1)

Solution (Python):




n = int(input())


a = list()
amax1st = -1
amax2nd = -1
for i in range(n):
    wka = int(input())
    if wka >= amax1st:
        amax2nd = amax1st
        amax1st = wka
    elif wka >= amax2nd:
        amax2nd = wka
        
    a.append(wka)

for i in range(n):
    if a[i] == amax1st:
        ans = amax2nd
    else:
        ans = amax1st
    
    print(ans)

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

max1 = 0
max2 = 0
max1_id = 0
for i, a in enumerate(range(n)):
  a = int(input())
  if a > max1:
    max2 = max1
    max1 = a
    max1_id = i
  elif a > max2:
    max2 = a

for i in range(i+1):
  if i == max1_id:
    print(max2)
  else:
    print(max1)

Solution (Python):
N=int(input())
max1=0
second_max=0
ind=[]
for i in range(N):
  t=int(input())
  if second_max < t:
    if max1<t:
        second_max=max1
        max1=t
        ind.clear()
        ind.append(i)
    elif max1==t:
        second_max=max1
        ind.append(i)
    else:
        second_max=t
if len(ind)==1:
    for i in range(N):
      if i == ind[0]:
        print(second_max)
      else:
          print(max1)
else:
    for i in range(N):
          print(max1)

Solution (Python):
import copy

N = int(input())

A = []

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

max_A = max(A)

B = copy.deepcopy(A)

B.remove(max_A)

second_A = max(B)

for i in range(N):
    if A[i] == max_A:
        print(second_A)
    else:
        print(max_A)

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

Solution (Python):
n = int(input())
a = []
mx12 = [0,0]
for i in range(1,n+1):
    a.append(int(input()))
    if min(mx12) <= a[-1]:
        mx12.sort()
        mx12[0] = mx12[1]
        mx12[1] = a[-1]
mx12.sort()
for j in range(1,n+1):
    if a[j-1] == mx12[1]:
        print(mx12[0])
    else:
        print(mx12[1])

Solution (Python):
from sys import stdin
import heapq

N = int(stdin.readline().rstrip())
A = [int(input()) for i in range(N)]


tmp = heapq.nlargest(2, A)

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

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
A_max = max(A)
A_max_count = A.count(A_max)
if A_max_count != N:
  a_ = A[:]
  a_ = sorted(a_,reverse = True)
  A_next_max = a_[A_max_count]
else:
  A_next_max = A_max_count

for i in range(N):
  tmp = A[i]
  if tmp != A_max:
    print(A_max)
  else:
    if A_max_count == 1:
      print(A_next_max)
    else:
      print(A_max)

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

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

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

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

A_max = max(A)
C = A.count(A_max)

if C>=2:
    for l in range(N):
        print(A_max)
else:
    p = A.index(A_max)
    B = sorted(A,reverse=True)
    for k in range(N):
        if k==p:
            print(B[1])
        else:
            print(A_max)

Solution (Python):

import numpy as np

def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    
    
    
    V = np.argmax(A)
    
    MAX = max(A)
    
    for _ in range(N):
        if _ == V:
            print(max(A[0:V]+A[V+1:N]))
        else:
            print(MAX)
                

    

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
R=[]
max_ = 0
for i in range(N):
    max_ = max(max_, A[i])
    R.append(max_)
L=[]
max_ = 0
for i in reversed(list(range(N))):
    max_ = max(max_, A[i])
    L.append(max_)
L = list(reversed(L))
print(L[1])
for i in range(1, N-1):
    print(max(R[i-1], L[i+1]))
print(R[N-2])

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

for i in range(0, N):
    ai = int(input())
    A.append(ai)
    if max_a < ai:
        max_a = ai
        max_index = i

A.remove(max_a)

for i in range(0, N):
    if i != max_index:
        print(max_a)
    else:
        print(max(A))

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

if A[0] > A[1]:
    max_1, max_2 = A[0],A[1]
else:
    max_1, max_2 = A[1],A[0]

dict = {}
for i, a in enumerate(A):
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1
    if i >= 2:
        if a > max_1:
            max_2 = max_1
            max_1 = a
        elif a > max_2:
            max_2 = a

for a in A:
    if a == max_1:
        if dict[a] >= 2:
            print(max_1)
        else:
            print(max_2)
    else:
        print(max_1)

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

max_index = A.index(max(A))
max_value = A.pop(max_index)

res = [str(max_value)] * N
res[max_index] = str(max(A))
print('\n'.join(res))

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

ans = []
cp = copy.copy(a) 
v_max = max(a)
cp.remove(v_max)
v_next = max(cp)

for i in a:
    
    
    if i == v_max:
        print(v_next)
    else:
        print(v_max)

Solution (Python):
import collections

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

a = collections.Counter(A)
a = sorted(a.items(), key=lambda x: -x[0])

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

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

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

M1 = 0
M2 = 0

for i in range(N):
    if A[i] > M1:
        M1 = A[i]
    elif A[i] > M2:
        M2 = A[i]


for i in range(N):
    if A[i] == M1:
        print(M2)
    else:
        print(M1)

Solution (Python):
n = int(input())
a = []
max_count = 0
maxi = 0
max_id = 0
for i in range(n):
  a.append(int(input()))
  if a[i]>maxi:
    max_count = 1
    max_id = i
    maxi = a[i]

  elif a[i]==maxi:
    max_count += 1
    
if max_count <= 1:
  for i in range(max_id):
    print(maxi)
  print(sorted(a, reverse=True)[1])
  for i in range(max_id + 1, n):
    print(maxi)
    
else:
  for i in range(n):
    print(maxi)

Solution (Python):
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
b=sorted(a)    
n_max=b[-1]
n_max2=b[-2]

for i in range(N):
    if a[i]==n_max:
        print(n_max2)
    else:
        print(n_max)

Solution (Python):
import copy
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
ma =max(a)
cn =0
for i in range(n):
  if a[i]==ma and cn<2:
    b=copy.deepcopy(a)
    del b[i]
    print(max(b))
    cn +=1
  else:
    print(ma)

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

max1 = 0
max2 = 0

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

    if max1 < A[i]:
        max2 = max1
        max1 = A[i]

    elif max2 < A[i]:
        max2 = A[i]

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

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

a_sort = sorted(a)
max = a_sort[-1]
second = a_sort[-2]

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

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

a = []
maximum = 0
second_maximum = 0
for i in range(n):
    input_num = int(input())
    a.append(input_num)
    if input_num > maximum:
        second_maximum = maximum
        maximum = input_num
    elif input_num > second_maximum:
        second_maximum = input_num
        
for a_num in a:
    if a_num == maximum:
        print(second_maximum)
    else:
        print(maximum)

Solution (Python):
N=int(input())
AN=[int(input()) for _ in range(N)]
ret=max(AN)
ANc=sorted(AN,reverse=True)
ret2=ANc[1]

for i in range(N):
    if ret != AN[i]:
        print(ret)
    else:
        print(ret2)

Solution (Python):
import copy

N = int(input())

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


max1 = max(A)

max_i = A.index(max1)
max2 = max(A[:max_i] + A[max_i+1:])


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

    else:
        print(max1)

Solution (Python):
N = int(input())
arr = []
for i in range(N):
  arr.append(int(input()))
max_inds = []
max_v = arr[0]
for i in range(N):
  if arr[i] > max_v:
    max_v = arr[i]
for i in range(N):
  if arr[i] == max_v:
    max_inds.append(i)
for i in range(N):
  if len(max_inds) >= 2:
    print(max_v)
  else:
    if i == max_inds[0]:
      cop = arr.copy()
      del cop[i]
      print(max(cop))
    else:
      print(max_v)

Solution (Python):
def calc(N, A):
    Amax = [0, 0]
    for a in A:
        if (a > Amax[0]):
            Amax[1] = Amax[0]
            Amax[0] = a
        elif (a > Amax[1]):
            Amax[1] = a
    result = ''
    for a in A:
        if (a == Amax[0]):
            result += str(Amax[1]) + '\n'
        else:
            result += str(Amax[0]) + '\n'
    return result


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

Solution (Python):

import sys

n = input()
seq = [int(x) for x in sys.stdin.read().rstrip().split("\n")]
seq_max = max(seq)


seq_max_indices = []
for i in range(0, len(seq)):
    if seq[i] == seq_max:
        seq_max_indices.append(i)

if len(seq_max_indices) == 1:
    seq_second_max = sorted(seq, reverse=True)[1]
    result = [str(seq_max) for x in range(len(seq))]
    result[seq_max_indices[0]] = str(seq_second_max)
    print("\n".join([str(x) for x in result]))
else:
    print("\n".join([str(seq_max) for x in range(len(seq))]))

Solution (Python):
N = int(input())
A_list = []
A_l = []
for i in range(N):
    A = int(input())
    A_list.append(A)
    A_l.append(A)
A_list.sort(reverse = True)

for j in range(N):
    if A_l[j] != A_list[0]:
        print(A_list[0])
    else:
        print(A_list[1])

Solution (Python):
N = int(raw_input())
A = [(int(raw_input()), i) for i in range(N)]
AS = sorted(A, key=lambda x:-x[0])
for i in range(N):
    if i != AS[0][1]:
        print AS[0][0]
    else:
        print AS[1][0]

Solution (Python):
import copy
n = int(input())
a = [int(input()) for _  in range(n)]
jisyo = {}
flag = False
if(a.count(max(a))!=1):
	flag = True
b = copy.deepcopy(a)
b.sort()
for i in a:
	if flag:
		print(b[-1])
	elif(i == b[-1]):
		print(b[-2])
	else:
		print(b[-1])

Solution (Python):
N = int(input())
As = [int(input()) for _ in range(N)]
m1, m2 = list(sorted(As, reverse=True))[:2]
for a in As:
  if a == m1:
     print(m2)
  else:
     print(m1)

Solution (Python):

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


ma = max(list_a)

i_ma = list_a.index(ma)
list_aa = list_a[:]
list_aa.pop(i_ma)

ma2 = max(list_aa)







for ai in list_a:
    if (ai == ma):
        print(ma2)
    else:
        print(ma)

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

max_val = 0
sub_max_val = 0
max_count = 0
lst = []
for i in range(n):
    ai = int(input())
    lst.append(ai)
    if ai > max_val:
        sub_max_val = max_val
        max_val = ai
        max_count = 1
    elif ai == max_val:
        max_count += 1
    elif ai > sub_max_val:
        sub_max_val = ai

if max_count > 1:
    for i in range(n):
        print(max_val)
else:
    for i in range(n):
        if lst[i] == max_val:
            print(sub_max_val)
        else:
            print(max_val)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
m1 = max(a)
mi = a.index(m1)
m2 = max(a[:mi] + a[mi+1:])

for i in range(n):
    if i == mi:
        print(m2)
    else:
        print(m1)

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
max1 = max(a)
ind = a.index(max1)
if ind == 0:
    a_ = a[1:len(a)]
elif ind == len(a)-1:
    a_ = a[0:len(a)-1]
else:
    a_ = a[0:ind] + a[ind+1:len(a)]
max2 = max(a_)
for i in range(n):
    if a[i] == max1:
        print(max2)
    else:
        print(max1)

Solution (Python):
a=[]
m1,m2=0,0
ct=0
t=input()
for i in range(t):
    n=input()
    a.append(n)
    if n>m1:
        m2=m1
        m1=n
        ct=i
    elif n>m2:
        m2=n
for i in range(t):
    if i==ct:
        print m2
    else:
        print m1

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

lis=sorted(li)
max1=lis[-1]
max2=lis[-2]
for i in li:
  if(i==max1):
    print(max2)
  else:
    print(max1)

Solution (Python):
N=int(input())
A = []
for n in range(N):
    A.append(int(input()))
import numpy as np
A_np = np.array(A)
A_max = A_np.max()
A_max_idx = A_np.argmax()
A_np_next = np.delete(A_np, A_max_idx)
A_next_max = A_np_next.max()
if A_max == A_next_max:
    for n in range(N):
        print(A_max)
else:
    for n in range(N):
        if n == A_max_idx:
            print(A_next_max)
        else:
            print(A_max)

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

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

m = max(A)
maxindexlist = my_index_multi(A,m)

if len(maxindexlist) == 1:
    for i in range(N):
        if i != (maxindexlist[0]):
            print(m)
        else:
            A.pop(maxindexlist[0])
            print(max(A))
else:
    for i in range(N):
        print(m)