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



Sample input:
3
1
4
3


Sample output:
4
3
4

Submission status: Accepted

Solution code:
n = int(input())
al = []
for i in range(n):
  a = int(input())
  al.append(a)
mal = sorted(al, reverse=True)
for i in range(n):
  if al[i] != mal[0]:
    print(mal[0])
  else:
    print(mal[1])

Submission status: Accepted

Solution code:
N = int(input())
A_List =[]
for i in range(N):
    A = int(input())
    A_List.append(A)
A_List2 = A_List.copy()
A_List2 = sorted(A_List2)

A_max = A_List2[-1]
A_max2 = A_List2[-2]

for a in A_List:
    if a ==A_max:
        print(A_max2)
    else:
        print(A_max)

Submission status: Accepted

Solution code:
def resolve():
    a = [int(input()) for _ in range(int(input()))]
    st = sorted(a)
    first = st[-1]
    second = st[-2]
    for i in a:
        if i == first:
            print(second)
        else:
            print(first)


resolve()

Submission status: Accepted

Solution code:
n = int(input())
a_list = [int(input()) for nesya in range(n)]
s = sorted(a_list,reverse=True)
max1 = s[0]
max2 = s[1]
for a in a_list:
  if a == max1:
    print(max2)
  else:
    print(max1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

def resolve():
    N,=pin()
    A=[int(input())for i in range(N)]
    B=sorted(A)
    first=B[-1]
    second=B[-2]
    for a in A:
        if a==first:print(second);continue
        print(first)
          
#%%submit!    
resolve()

Submission status: Accepted

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

a_s=sorted(a)
m1=a_s[-1]
m2=a_s[-2]

for i in range(n):
    if a[i]==m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
n = int(input())
top_val = 0
top_idx = set()
semi_top = 0

for i in range(n):
  a = int(input())
  if a > top_val:
    semi_top = top_val
    top_val = a
    top_idx.clear()
    top_idx.add(i)
  elif a == top_val:
    top_idx.add(i)
  elif a > semi_top:
    semi_top = a

if len(top_idx) > 1:
  semi_top = top_val

semi_top = str(semi_top)
top_val = str(top_val)

print("\n".join([semi_top if i in top_idx else top_val for i in range(n)]))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
left = [0]*n
right = [0]*n
for i in range(1, n):
    left[i] = max(left[i-1], a[i-1])
    right[n-i-1] = max(right[n-i], a[n-i])
for i in range(n):
    print(max(left[i], right[i]))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
AMax = max(A)
x = A.index(AMax)
Aelse = A[:x]+A[x+1:]
AelseMax = max(Aelse)
if AMax == AelseMax:
    for i in range(N):
        print(AMax)
else:
    for i in range(N):
        if x == i:
            print(AelseMax)
        else:
            print(AMax)

Submission status: Accepted

Solution code:
N=int(input())
arr = [int(input()) for _ in range(N)]
arr2 = sorted(arr)
max1 =arr2[-1]
max2=arr2[-2]


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

Submission status: Accepted

Solution code:
import copy
n = int(input())
a = [int(input()) for _ in range(n)]
s = copy.copy(a)
s.sort(reverse=True)
first = s[0]
second = s[1]
mx = []
for i in range(n):
    if a[i] == first:
        mx.append(second)
    else:
        mx.append(first)
for i in range(n):
    print(mx[i])

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a)
max_a=max(a)
second=b[-2]
for i in range(n):
    if a[i] != max_a:
        print(max_a)
    else:
        print(second)

Submission status: Accepted

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

s_a_ls = sorted(a_ls)
max_val = s_a_ls[-1]

for item in a_ls:
    if item == max_val:
        print(s_a_ls[-2])
    else:
        print(max_val)

Submission status: Accepted

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

l = sorted(A)
b = l[-1]
c = l[-2]

for i in range(N):
    if A[i] == b:
        print(c)
    else:
        print(b)

Submission status: Accepted

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

sorted_A_list = sorted(A_list, reverse=True)

for a in A_list:
    if a == sorted_A_list[0]:
        ans = sorted_A_list[1]
    else:
        ans = sorted_A_list[0]
    print(ans)

Submission status: Accepted

Solution code:
n=int(input())
as_=[int(input()) for _ in range(n)]
l=sorted(as_)
m1=l[-1]
m2=l[-2]
for a in as_:
    if a==m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
n = int(input())

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

s = sorted(t)
m = s[-1]
m1 = s[-2]

for i in t:
  if i!=m:
    print(m)
  else:
    print(m1)

Submission status: Accepted

Solution code:
import numpy

N = int(input())

la = list()
for i in range(N):
    la.append(int(input()))

max1 = sorted(la)[-1]
max2 = sorted(la)[-2]

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
A = IR(n)

B = sorted(A)
a = B.pop()
b = B.pop()
for x in A:
    if x == a:
        print(b)
    else:
        print(a)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = list(A)
B.sort()
m1 = B[N-1]
m2 = B[N-2]
#a = A.count(m1)
for i in range(N):
  if A[i] == m1:
    print(m2)
  else:
    print(m1)

Submission status: Accepted

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(int(input()) for i in range(n))
l = a[:]
l.sort(reverse=True)
x = l[0]
y = l[1]
ans = 0
for i in range(n):
    if a[i] == x:
        ans = y
    else:
        ans = x
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = []
    m_A = [0, 0]
    for i in range(N):
        a = int(input())
        A.append(a)
        if m_A[1] < a:
            m_A[0] = m_A[1]
            m_A[1] = a
        elif m_A[0] < a:
            m_A[0] = a
    for i in range(N):
        if A[i] == m_A[1]:
            print(m_A[0])
        else:
            print(m_A[1])


solve()

Submission status: Accepted

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

max_A_1 = sorted(A)[-1]
max_A_2 = sorted(A)[-2]

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input())) # [1, 3, 5, 4, 2]
al = sorted(a, reverse = True) # [5, 4, 3, 2, 1]
mx = al[0]
submx = al[1]
for i in range(n):
    if a[i] == mx:
        print(submx)
    else:
        print(mx)

Submission status: Accepted

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

comp = sorted(a, reverse = True)

Fmax = comp[0]
Smax = comp[1]

for i in range(n):
    if a[i] == Fmax:
        print(Smax)
    
    else:
        print(Fmax)

Submission status: Accepted

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

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

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

print(*ans, sep="\n")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    maxi = max(A)
    a = A.copy()
    a.sort()
    submaxi = max(a[:N-1])
    for i in range(N):
        if A[i] != maxi:
            print(maxi)
        else:
            print(submaxi)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# C - Exception Handling

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

Submission status: Accepted

Solution code:
import sys, heapq, bisect, math, fractions
from collections import deque

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

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

Submission status: Accepted

Solution code:

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

a_sort=sorted(a)

max_a=max(a)
next_max=a_sort[-2]

lis=[0]*n

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

L=[str(a) for a in lis]
L="\n".join(L)
print(L)

Submission status: Accepted

Solution code:
N,*A =map(int,open(0).read().split())
B =sorted(A)
biggest = B[-1]
for i in A:
  if i==biggest:
    print(B[-2])
  else:
    print(biggest)

Submission status: Accepted

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

Submission status: Accepted

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

B = sorted(A, reverse=True)
first = B[0]
second = B[1]

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

Submission status: Accepted

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

B = sorted(A, reverse=True)
first = B[0]
second = B[1]

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

first = max(A)
B = A.copy()
B.remove(first)
second = max(B)

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

Submission status: Accepted

Solution code:
n=int(input())
maxx=0
sec=0
lis=[]
for i in range(n):
  s=int(input())
  lis.append(s)
  if s>=maxx:
    sec=maxx
    maxx=s
  elif s>sec:
    sec=s
for j in range(0,n):
  if lis[j]==maxx:
    print(sec)
  else:
    print(maxx)

Submission status: Accepted

Solution code:
n=int(input())
a = [0]*n
for i in range(n):
  a[i] = int(input())
sorteda = a.copy()
sorteda.sort(reverse=True)
maxa = sorteda[0]
secmaxa = sorteda[1]
for i in range(n):
  if a[i]==maxa:
    print(secmaxa)
  else:
    print(maxa)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = sorted(A)  
max_A = B[N-1]
smax_A = B[N-2]

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

Submission status: Accepted

Solution code:
n = int(input())
aaa = [int(input()) for _ in range(n)]
max_a = sorted(aaa)[-1]
second_a = sorted(aaa)[-2]
for a in aaa:
    if a == max_a:
        print(second_a)
    if a != max_a:
        print(max_a)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list()
    max_value = 0
    second_max_value = 0
    max_index = -1
    for i in range(N):
        a = int(input())
        A.append(a)
        if a > max_value:
            second_max_value = max_value
            max_value = a
            max_index = i
        elif a > second_max_value:
            second_max_value = a
    for i, a in enumerate(A):
        if i == max_index:
            print(second_max_value)
        else:
            print(max_value)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(((i, int(input())) for i in range(N)), key=lambda x: x[1])

maxidx, maxi = A[-1]
secidx, second = A[-2]

A.sort()
for a in A:
    if a[0] == maxidx:
        print(second)
    else:
        print(maxi)

Submission status: Accepted

Solution code:
#include <bits/stdc++.h>
N = int(input())
A = [int(input()) for _ in range(N)]
first, second = sorted(A)[::-1][:2]
for a in A:
    print(first if a != first else second)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a, reverse=True)
mx = sorted(b)[-1]
mx2 = sorted(b)[-2]

for i in a:
    if i != mx:
        print(mx)
    else:
        print(mx2)

Submission status: Accepted

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

maxR = [0] * n
maxL = [0] * n
maximum = 0
for i in range(n):
    maximum = max(maximum,a[i])
    maxL[i] = maximum
maximum = 0
for i in range(n):
    maximum = max(maximum,a[n-i-1])
    maxR[n-i-1] = maximum



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

Submission status: Accepted

Solution code:
#ABC 134 C
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())
east=[0]*(n+1)
west=[0]*(n+1)
for i in range(1,n+1):
    east[i]=max(east[i-1],a[i-1])
    west[-i-1]=max(west[-i],a[-i])
for k in range(1,n+1):
    print(max(east[k-1],west[k]))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = [int(input()) for i in range(n)]

a = sorted(s,reverse=True)
M = a[0]

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

Submission status: Accepted

Solution code:
n = int(input())
a = [[i, int(input())] for i in range(n)]
a.sort(reverse=True, key=lambda x:x[1])
first, second = a[0][1], a[1][1]
a.sort(key=lambda x:x[0])
for i in range(n):
  print(first if a[i][1] != first else second)

Submission status: Accepted

Solution code:
import numpy as np

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

max_idx = np.argmax(a)
first = a[max_idx]
a[max_idx] = 0
second = max(a)
a[max_idx] = first

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

Submission status: Accepted

Solution code:
import copy
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = list(map(int, read().split()))

max_a = max(a)
b = copy.copy(a)
b.remove(max_a)
nxt_a = max(b)

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

Submission status: Accepted

Solution code:

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

a2=sorted(a)
amax1=a2[n-1]
amax2=a2[n-2]

for i in range(n):
    if a[i]==amax1:
        print(amax2)
    else:
        print(amax1)

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################
 
N=II()
A=[II() for i in range(N)]

b=sorted(A)
b.reverse()
for i in range(N):
    if A[i] == b[0]:
        print(b[1])
    else:
        print(b[0])

Submission status: Accepted

Solution code:
n = int(input())
lst = [int(input()) for i in range(n)]

maxi = [0, 0]
for i in range(n):
  if lst[i] > maxi[0]:
    maxi = [lst[i], i]
    
maxi2 = 0
for j in range(n):
  if j == maxi[1]:
    continue
  else:
    if lst[j] > maxi2:
      maxi2 = lst[j]
    
for i in range(n):
  if i != maxi[1]:
    print(maxi[0])
  else:
    print(maxi2)

Submission status: Accepted

Solution code:
N = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
A = [int(input()) for i in range(N)]
greatest = max(A)

if A.count(greatest)==1:
    B = list(set(A))
    B.remove(greatest)
    for i in range(N):
        if A[i] != greatest:
            print(greatest)
        else:
            print(max(B))

else:
    for i in range(N):
        print(greatest)

Submission status: Accepted

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

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

Submission status: Accepted

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

b = sorted(a)
b.reverse()

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

Submission status: Accepted

Solution code:
n = int(input())
a_list = [int(input()) for i in range(n)]
a_list_sort = sorted(a_list)
a_list_max1 = max(a_list)
a_list_max2 = a_list_sort[-2]
for i in range(n):
    if a_list_max1 == a_list[i]:
        print(a_list_max2)
    else:
        print(a_list_max1)

Submission status: Accepted

Solution code:
n=int(input())
v=[int(input()) for i in range(n)]
t=sorted(v,reverse=True)
for i in v:
  print(t[1] if i==t[0] else t[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())
Aa = A[:]
Aa.sort()
maxa = Aa[-1]
for i in range(N):
    if A[i] != maxa:
        print(maxa)
    else:
        print(Aa[-2])

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
maxi = max(a)
s = sorted(a,reverse=True)
 
for i in range(n):
    if a[i] != maxi:
        print(maxi)
    else:
        print(s[1])

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
maxi = max(a)
s = sorted(a,reverse=True)

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
D=sorted(A)
num=max(D)
num2=D[-2]
for i in range(N):
    if A[i]==num:
        print(num2)
    else:
        print(num)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A, reverse=True)
result = [B[0]]*N
x = A.index(B[0])
if B[0] != B[1]:
    result[x] = B[1]

for a in result:
    print(a)

Submission status: Accepted

Solution code:
N = int(input())
a1 = 0
a2 = 0
a1_ind = -1

for i in range(0,N):
    x = int(input())
    if a1 < x:
        a2 = a1
        a1 = x
        a1_ind = i
    elif a2 < x:
        a2 = x

for i in range(0,N):
    if i == a1_ind:
        print(a2)
    else:
        print(a1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int(input())
    A = deque([int(input()) for i in range(N)])
    MAX = max(A)
    MAX2 = 0
    Ms = [-1]*N
    for i in range(N):
        if A[i] == MAX:
            if MAX2 != 0:
                Ms[i] = MAX2
            else:
                A[i] = 0
                MAX2 = max(A)
                Ms[i] = MAX2
        else:
            Ms[i] = MAX
    for i in range(N):
        print(Ms[i])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
As = [int(input()) for _ in range(N)]

Bs = sorted(As)
maxA2, maxA = Bs[-2:]

anss = []
for A in As:
    if A == maxA:
        anss.append(maxA2)
    else:
        anss.append(maxA)

print('\n'.join(map(str, anss)))

Submission status: Accepted

Solution code:
import copy
import sys
input = sys.stdin.readline
n=int(input())
A = [int(input()) for _ in range(n)]
A2 = copy.deepcopy(A)
max1 = max(A)
A.remove(max1)
max2 = max(A)
for i in range(n):
    if A2[i]==max1:
        print(max2)
    else:
        print(max1)

Submission status: Accepted

Solution code:
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
sortedA=sorted(A,reverse=True)
large_1=sortedA[0]
if sortedA[1]==large_1 or len(A)==1:
    for i in range(N):
        print(large_1)
else:
    num=A.index(large_1)
    for i in range(num):
        print(large_1)
    print(sortedA[1])
    for j in range(N-num-1):
        print(large_1)

Submission status: Accepted

Solution code:


n = int(input())
a = [int(input()) for i in range(n)]
a_sort = sorted(a)
amax = a_sort[-1]
asmas = a_sort[-2]

for i in range(n):
  if a[i] == amax:
    print(asmas)
  else:
    print(amax)

Submission status: Accepted

Solution code:
n=int(input())
A=[int(input()) for _ in range(n)]
m=max(A)
p=A.index(m)
l=1
for i in range(n):
	if i!=p:
		l=max(l,A[i])
for i in range(n):
	if i==p:
		print(l)
	else:
		print(m)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n=int(input())
a=[int(input()) for _ in range(n)]
max_=max(a)
cnt=a.count(max_)
pos=a.index(max_)

if cnt>1:
    for i in range(n):
        print(max_)
else:
    a[pos]=0
    max2_=max(a)
    for i in range(n):
        if i==pos:
            print(max2_)
        else:
            print(max_)

Submission status: Accepted

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
b = sorted(a)
max = b[-1]
max_sec = b[-2]

for A in a:
    if A == max:
        print(max_sec)
    else:
        print(max)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(input()) for i in range(n)]
B = sorted(A)
x = B[-1]
y = B[-2]

for i in A:
    if i == x:
        print(y)
    else:
        print(x)

Submission status: Accepted

Solution code:
N = int(input())
A = list(int(input()) for _ in range(N))
B = A[:]
B.sort()
mx = B[-1]
mx2 = B[-2]

for a in A:
  if a == mx:
    print(mx2)
  else:
    print(mx)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
S = sorted(A)

for i in A:
  if i < S[N-1]:
    print(S[N-1])
  else:
    print(S[N-2])

Submission status: Accepted

Solution code:
n = int(input())
A = [int(input()) for i in range(n)]
As = sorted(A)

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

Submission status: Accepted

Solution code:
n = int(input())
l = []
for i in range(n):
    l.append(int(input()))
m = max(l)
ans = [m]*n
if len(set(l)) == 1 or l.count(m) > 1:
    for i in ans:
        print(i)
else:
    x = sorted(set(l))[-2]
    a = l.index(m)
    ans[a] = x
    for i in ans:
        print(i)

Submission status: Accepted

Solution code:
import sys
import os
import math
import string
import collections

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    A = [ii() for _ in range(N)]
    SA = sorted(A, reverse=True)
    for a in A:
        if a == SA[0]:
            print(SA[1])
        else:
            print(SA[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N=int(input())
A=[int(input()) for _ in range(N)]
A_sorted=sorted(A)

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
l = sorted(a, reverse = True)
for i in range(n):
    if a[i] == l[0]:
        print(l[1])
    else:
        print(l[0])

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def resolve():
    n=int(input())
    l=[int(input()) for i in range(n)]
    l1=sorted(l,reverse=True)
    for j in range(n):
        if l[j]!=l1[0]:
            print(l1[0])
        else:
            print(l1[1])
resolve()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=[int(input()) for i in range(n)]
    biggest = max(l)
    lsort=sorted(l)
    niban=lsort[-2]
    for j in range(n):
        if l[j]!=biggest:
            print(biggest)
        else:
            print(niban)
resolve()

Submission status: Accepted

Solution code:
n = int(input())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i] = int(input())
    b[i] = a[i]
max_a = max(a)
max_idx = a.index(max_a)
b[max_idx] = 0
max_b = max(b)
for i in range(n):
    if i != max_idx:
        print(max_a)
    else:
        print(max_b)

Submission status: Accepted

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

a_sort = sorted(a, reverse=True)

for v in a:
    if v == a_sort[0]:
        print(a_sort[1])
    else:
        print(a_sort[0])

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
t=max(a)
s=a.index(t)
a.pop(s)
u=max(a)
for i in range(n):
  if i==s:
    print(u)
  else:
    print(t)

Submission status: Accepted

Solution code:
N=int(input())
S=[int(input()) for i in range(N)]
T=sorted(S,reverse=True)

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