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:
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(input()) for _ in range(N)]

    max_num = max(As)
    max_index = As.index(max_num)

    for i in range(N):
        if i == max_index:
            As.remove(max_num)
            print(max(As))
        else:
            print(max_num)
if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

    max_num = max(As)
    max_index = As.index(max_num)

    for i in range(N):
        if i == max_index:
            del As[max_index]
            print(max(As))
        else:
            print(max_num)
if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
A = list(int(input()) for _ in range(N))

A_max = sorted(A, reverse = True)[0]
A_second = sorted(A, reverse=True)[1]

for i in range(N):
    if A[i] == A_max:
        print(A_second)
    else:
        print(A_max)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=[0]*N
    Mi=-1
    M=0
    for i in range(N):
        A[i]=I()
        if A[i]>M:
            Mi=i
            M=A[i]
            
    A[Mi]=0
    
    for i in range(N):
        if i!=Mi:
            print(M)
        else:
            print(max(A))

main()

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N = int(input())

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

AA = Counter(A)

B = sorted(AA.items(), key=lambda x:x[0])

if B[-1][1] == 1:
    c = B[-2][0]
else:
    c = B[-1][0]

M = B[-1][0]

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

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N = int(input())

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

B = copy.deepcopy(A)
heapq.heapify(B)

for i in range(N):
    b = heapq.heappop(B)
    if b == A[i]:
        c = b
        b = heapq.heappop(B)
        heapq.heappush(B,c)
    heapq.heappush(B,b)
    print(-b)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc134/tasks/abc134_c

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

max_a = 0
sec_max_a = 0
for i in range(n):
    if max_a <= a[i]:
        sec_max_a = max_a
        max_a = a[i]
    elif sec_max_a < a[i]:
        sec_max_a = a[i]

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

Submission status: Accepted

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

l1=sorted(a)[-1]
l2=sorted(a)[-2]

for i in a:
  if i==l1:
    print(l2)
  if i!=l1:
    print(l1)

Submission status: Accepted

Solution code:
n = int(input())
a = list(int(input()) for _ in range(n))
aa = sorted(a.copy())
mx, sd = aa[n - 1], aa[n - 2]
for i in a:
    print(mx if i < mx else sd)

Submission status: Accepted

Solution code:
from heapq import nlargest
import sys
n = int(input())
a = [int(input()) for i in range(n)]
l1, l2 = nlargest(2, a)

if l1 == l2:
  for i in range(n):
    print(l1)
  sys.exit()

for i in a:
  if i == l1:
    print(l2)
  else:
    print(l1)

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 134
# C - Exception Handling

N=int(input())
ls = []
lsmax=0
lsmaxnum=1
lsmax2=0
for i in range (N):
    a=int(input())
    ls.append(a)
    if a==lsmax:
        if lsmaxnum==1:
            pass
        else:
            lsmaxnum+=1
    if a>lsmax:
        lsmax=a
if lsmaxnum==1:
    ls2=sorted(ls)
    lsmax2=ls2[-2]

# print(lsmax,lsmax2,lsmaxnum)

for j in range (N):
    if ls[j]==lsmax:
        if lsmaxnum>1:
            print(lsmax)
        else:
            print(lsmax2)
    else:
        print(lsmax)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
sortA = sorted(A)
ma = sortA[-1]
ma2 = sortA[-2]
for a in A:
    if a == ma:
        print(ma2)
    else:
        print(ma)

Submission status: Accepted

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


A_max = A_s[0]
A_max2 = A_s[1]

for i in A:
    if i == A_max:
        print(A_max2)
    else:
        print(A_max)

Submission status: Accepted

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

B = sorted(A)
max1 = B[-1]
max2 = B[-2]
for x in A:
    if x == max1:
        print(max2)
    else:
        print(max1)

Submission status: Accepted

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

check = sorted(an, reverse=True)
for i in range(n):
  if an[i] == check[0] :
    print(check[1])
  else :
    print(check[0])

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
s = sorted(a)
for j,k in enumerate(a):
    print(s[-2]) if k == s[-1] else print(s[-1])

Submission status: Accepted

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

Submission status: Accepted

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

sorted_A = sorted(A, reverse=True)

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
A_cpy = A[:]
A_cpy.sort()
max_ = A_cpy[-1]

for a in A:
    if a == max_:
        print(A_cpy[-2])
    else:
        print(max_)

Submission status: Accepted

Solution code:
import math


def resolve():
    import sys
    import string
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    n = int(input().rstrip())
    a_list = [int(input().rstrip()) * -1 for i in range(n)]

    import numpy
    indices = numpy.argsort(a_list)
    max_num = a_list[indices[0]] * -1
    second_max_num = a_list[indices[1]] * -1

    for i in range(len(a_list)):
        if i != indices[0]:
            print(max_num)
        else:
            print(second_max_num)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
a_list = [int(input()) for _ in range(n)]
cp_list = a_list.copy()
cp_list.sort()
second_ans = cp_list[-2]
ans = cp_list[-1]
for i in range(n):
    if a_list[i] == ans:
        print(second_ans)
    else:
        print(ans)

Submission status: Accepted

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

l = sorted(a)

max_num = l[-1]
sec_max = l[-2]

cnt = a.count(max_num)

for x in a:
    if x == max_num and cnt == 1:
        print(sec_max)
    else:
        print(max_num)

Submission status: Accepted

Solution code:
N = int(input())
b = 0
c = 0
first = 0
A = []
for i in range(N):
    a = int(input())
    if b < a:
        ind = i
        b = a
    A.append(a)
for j in range(N):
    if j==ind:
        continue
    if c < A[j]:
        sind = j
        c = A[j]
for k in range(N):
    if k==ind:
        print(c)
    else:
        print(b)

Submission status: Accepted

Solution code:
n = int(input())
l = []

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

def has_duplicates(seq):
    return sorted(seq)[len(seq)-1] == sorted(seq)[len(seq)-2]

x = max(l)

if has_duplicates(l):
    for i in l:
        print(x)
else:
    for i in l:
        if i != x:
            print(x)
        else:
            print(sorted(l)[n-2])

Submission status: Accepted

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

Submission status: Accepted

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

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:
N = int(input())
A = []

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

maxA = max(A)
idx = A.index(maxA)
A.sort()
for i in range(len(A)):
  if i == idx:
    print(max(A[:-1]))
  else:
    print(maxA)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for _ in range(N):
	A.append(int(input()))
B = sorted(A, reverse = True)
m1, m2 = B[0], B[1]
for i in range(N):
	if m1 > A[i]:
		print(m1)
	else:
		print(m2)

Submission status: Accepted

Solution code:
# C - Exception Handling
N = int(input())
A = list(int(input()) for _ in range(N))
A_sorted = list((sorted(A, reverse = True)))
A_sorted = A_sorted[0:2]

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

for j in ans:
    print(j)

Submission status: Accepted

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

Submission status: Accepted

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

m1, m2 = sorted(A, reverse=True)[0:2]
for a in A:
    print(m2 if a == m1 else m1)

Submission status: Accepted

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

mls = [-1 for _ in range(N+1)]
for i, a in enumerate(A, 1):
    mls[i] = max(mls[i-1], a)

mrs = [-1 for _ in range(N+1)]
for i, a in enumerate(A[::-1], 1):
    mrs[i] = max(mrs[i-1], a)
mrs = mrs[::-1]

for i in range(N):
    print(max(mls[i], mrs[i+1]))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

sort_a = sorted(a, reverse=True)
max_a = sort_a[0]
max_a_1 = sort_a[1]

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

Submission status: Accepted

Solution code:
import copy
N=int(input())
ans=[]
S=[int(input()) for i in range(N)]
W=copy.copy(S)
W.sort()
for i in range(N):
  if W[-1]==S[i]:
    ans.append(W[-2])
  else:
    ans.append(W[-1])
for j in range(N):
  print(ans[j])

Submission status: Accepted

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

b = sorted(a)

m = max(a)
for i in a:
    if i == m:
        ans.append(b[-2])
    else:
        ans.append(m)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    m = max(a)
    s = sorted(a)[-2]
    for i in a:
        if i == m:
            print(s)
        else:
            print(m)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
N=int(input())
A=[]
for i in range(N):
  a=int(input())
  A.append(a)
import copy
B=copy.copy(A)
B.sort()
max=B[-1]
max2=B[-2]

if max==max2:
  for i in range(N):
    print(max)
else:
  ind=A.index(max)
  for i in range(N):
    if i==ind:
      print(max2)
    else:
      print(max)

Submission status: Accepted

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

S = sorted(A,reverse=True)
maxa = S[0]
maxa2 = S[1]
B=[]
B = [maxa2 if a==maxa else maxa for a in A]

for b in B:
    print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

b = sorted(a)

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

sys.setrecursionlimit(10**7)

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

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

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

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

a_sort = sorted(a,reverse=True)
# print(a_sort)

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

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

#Ap = np.array(A)
#C = np.zeros(N + 1)

# if ans:
#     print('Yes')
# else:
#     print('No')

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

A.remove(max1)

max2 = max(A)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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



solve()

Submission status: Accepted

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

b = sorted(a)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys


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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

a.remove(M)

S = max(a)

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

Submission status: Accepted

Solution code:
import copy

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

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

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

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

Submission status: Accepted

Solution code:
import copy

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

first = 0
second = 0

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

max_a = max(a)

cnt = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

asort = sorted(a)

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

A_sort = sorted(A, reverse=True)

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

Submission status: Accepted

Solution code:

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

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

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

b.sort()
b.reverse()

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

Submission status: Accepted

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

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

# 最大値と等しい値がが2つ以上ある場合
if n_max1 > 1:
    for _ in range(N):
        print(max1)
    exit()

# 最大値と等しい値が1つだけの場合
else:
    max2 = sorted(list(set(A)))[-2]
    for i in range(N):
        if A[i] != max1:
            print(max1)
        else:
            print(max2)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

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

Submission status: Accepted

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

sorted_a = sorted(a, reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

c = []
mL = 0
mR = 0
# m = 0


for i, a in enumerate(A):
    # print(a)
    if a == m:
        print(s)
    else:
        print(m)
    # if i == 0:
    #     mR = max(A[i + 1 :])
    #     print(mR)
    # elif i == len(A) - 1:
    #     mL = max(A[0: i])
    #     print(mL)
    # else:
    #     mL = max(A[0: i])
    #     mR = max(A[i + 1 :])
    #     m = max(mL, mR)
    #     print(m)

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in ans:
    print(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

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]
B.sort(reverse=True)
for j in range(N):
  if A[j]==B[0] :
    print(B[1])
  else :
    print(B[0])