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())
apple = []
for _ in range(n):
    apple.append(int(input()))
big = max(apple)
orange = [big for i in range(n)]
num = apple.index(big)
del apple[num]
cat = max(apple)
orange[num] = cat
for i in orange:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())
f, s = [0, 0], [0, 0]
for i in range(N):
    a = int(input())
    if f[1] < a:
        s = f
        f = [i, a]
    elif s[1] < a:
        s = [i, a]
for i in range(N):
    if f[0] == i:
        print(s[1])
    else:
        print(f[1])

Submission status: Accepted

Solution code:
n = int(input())
A = [int(input()) for _ in range(n)]
# print(A)
mf = max(A)
cnt_mf = A.count(mf)

if cnt_mf > 1:
    for _ in range(n):
        print(mf)
    exit()

Aset = set(A)
# print(Aset - {mf})
ms = max((Aset - {mf}))
# print(ms)

for e in A:
    if e != mf:
        print(mf)
    else:
        print(ms)

Submission status: Accepted

Solution code:
import copy
n = int(input())
a = [int(input()) for _ in range(n)]
 
b = copy.deepcopy(a)
b.sort()
max1 = b[-1]
max2 = b[-2]
 
for i in a:
    if i == max1:
        print(max2)
    else:
        print(max1)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    d = [int(input()) for _ in range(n)]
    s_d = sorted(d)
    max = s_d[-1]
    for di in d:
        if di == s_d[-1]:
            print(s_d[-2])
        else:
            print(max)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

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

b = copy.deepcopy(a)
b.sort()
max1 = b[-1]
max2 = b[-2]

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
A_sorted = list(sorted(A, reverse=True))

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
ls = [int(input()) for _ in range(n)]
mx = max(ls)
c = ls.count(mx)
new = ls[:]
new.remove(mx)
nx = max(new)
if c > 1:
    for _ in range(n):
        print(mx)
    sys.exit()
for i in ls:
    if i == mx:
        print(nx)
    else:
        print(mx)

Submission status: Accepted

Solution code:
import copy

N = int(input())

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

B = copy.copy(A)
B.sort()

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

Submission status: Accepted

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

n, *a = map(int, read().split())
sort_a =  sorted(a)

max_1 = sort_a[-1]
max_2 = sort_a[-2]
l = [max_2 if x == max_1 else max_1 for x in a]
print(*l)

Submission status: Accepted

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

li2 = li1.copy()
li2.sort(reverse=True)

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

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[-2])
    else:
        print(sorted_A[-1])

Submission status: Accepted

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

import heapq

h = []
for a in A:
    if len(h) < 2:
        heapq.heappush(h, a)
    else:
        heapq.heappushpop(h, a)

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

Submission status: Accepted

Solution code:
import heapq


def main():
    N = int(input())
    A = [(-1)*int(input()) for _ in range(N)]
    A_ = A.copy()
    heapq.heapify(A)

    for a in A_:
        tmp1 = heapq.heappop(A)
        if a == tmp1:
            tmp2 = heapq.heappop(A)
            print((-1) * tmp2)
            heapq.heappush(A, tmp1)
            heapq.heappush(A, tmp2)
        else:
            print((-1) * tmp1)
            heapq.heappush(A, tmp1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
A = []
M = 0
j = -1
for i in range(n):
    a = int(input())
    A.append(a)
    if a > M:
        M = a
        j = i
A.sort()
for i in range(n):
    if i == j:
        print(A[-2])
        continue
    print(M)

Submission status: Accepted

Solution code:
n = int(input())

a = []

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

a_max = max(a)
a_max_index = a.index(a_max)

a.sort(reverse=True)
a_second_max = a[1]

for i in range(n):
    if i == a_max_index:
        print(a_second_max)
    else:
        print(a_max)

Submission status: Accepted

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

Submission status: Accepted

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

b = sorted(a,reverse=True)
x = b[0]
y = b[1]

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

Submission status: Accepted

Solution code:

n = int(input())
a = []
y = 0
for i in range(n):
    x = int(input())
    a.append(x)
    if y <= x:
        y = x
        m = i

a.sort(reverse = True)
a_1 = a[0]
a_2 = a[1]

if a_1 == a_2:
    for i in range(n):
        print(a_1)

else:
    for i in range(m):
        print(a_1)

    print(a_2)

    for j in range(m+1,n):
        print(a_1)

Submission status: Accepted

Solution code:
import copy
# input
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
  
# main / output
top = max(a)
if a.count(top) != 1:
  for i in range(n):
    print(top)
else:
  topind = a.index(top)

  tmp = copy.deepcopy(a)
  tmp[topind] = 0
  sub = max(tmp)
  
  for i in range(n):
    if i == topind:
      print(sub)
    else:
      print(top)

Submission status: Accepted

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


for i in range(n):
    a = int(input())
    l.append(a)
    if(dic.get(a) is None):
        dic[a] = 1
    else:
        dic[a] += 1

mi = max(dic)
if(dic[mi]>=2):
    for i in range(n):
        print(mi)
else:
    del(dic[mi])
    mi2 = max(dic)
    for i in range(n):
        if(l[i]==mi):
            print(mi2)
        else:
            print(mi)

Submission status: Accepted

Solution code:
#import numpy as np
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
from itertools import permutations as perm


N = int(input())
#H1,M1,H2,M2,K= map(int,input().split())
#A = list(map(int,input().split()))
#B = list(map(int,input().split()))
#S= str(input())
l=[]
for i in range(N):
    B = int(input())
    l.append(B)
m=max(l)
x=l.copy()
x.remove(m)
n=max(x)
for i in l:
    if i!=m:
        print(m)
    else:
        print(n)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
sort=sorted(A)
x,y=sort[-1],sort[-2]
for a in A:
    print(x if a!=x else y)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
Max = max(A)
x = A.count(Max)

for i in range(0 ,N) :
    if x >= 2 :
        print(Max)
    elif A[i] == Max :
        A[i] = 0
        print(max(A))
    else : print(Max)

Submission status: Accepted

Solution code:
N = int(input())
maximum = 0
max_sec = 0
A = []
for _ in range(N):
  a = int(input())
  A.append(a)
  if a > maximum:
    max_sec = maximum
    maximum = a
  elif a > max_sec:
    max_sec = a
for i in range(N):
  if A[i] == maximum:
    print(max_sec)
  else:
    print(maximum)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    first = max(A)
    idx = A.index(first)
    second = max(A[:idx]+A[idx+1:])
    for i in range(N):
        if i == idx:
            print(second)
        else:
            print(first)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def solve(N, As):
    max = sorted(As)[-1]
    secmax = sorted(As)[-2]
    if max == secmax:
        for _ in range(N):
            print(max)
    else:
        for a in As:
            if a == max:
                print(secmax)
            else:
                print(max)



if __name__ == "__main__":
    N = int(input())
    As = []
    [As.append(int(input())) for i in range(N)]
    solve(N, As)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
s=sorted(a)
maxi=max(a)
maxi2=s[-2]
for i in a:
    if i == maxi:
        print(maxi2)
    else:
        print(maxi)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc134/tasks/abc134_c

N = int(input())

max_a = 0
max_i = 0
max_a_2 = 0

for i in range(N):
    A = int(input())
    
    if A >= max_a:
        max_a_2 = max_a
        max_a = A
        max_i = i

    elif A >= max_a_2:
        max_a_2 = A

for i in range(N):
    if i != max_i:
        print(max_a)

    else:
        print(max_a_2)

Submission status: Accepted

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

m = max(A)
c = A.count(m)
if c == 1:
    m2 = sorted(set(A),reverse=True)[1]
    for i in A:
        print (m) if i != m else print(m2)
else:
    for _ in range(n):
        print (m)

Submission status: Accepted

Solution code:
N = int(input())

A = []
for i in range(N):
    a = int(input())
    A.append([a, i])
    
A_ = sorted(A, reverse=True)

#print(A_)

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

Submission status: Accepted

Solution code:
N = int(input())

A = []

[A.append(int(input())) for x in range(N)]

max_num = max(A)
num = A.index(max(A))
A[num] = 0

st_max_num = max(A)

for i in range(num):
    print(max_num)
print(st_max_num)

for i in range(num+1,N):
    print(max_num)

Submission status: Accepted

Solution code:
n = int(input())
a = [0 for _ in range(n)]
for i in range(n):
	a[i] = int(input())
maxa = max(a)
basho = a.index(maxa)
a[basho] = 0
for i in range(n):
	if i != basho:
		print(maxa)
	else:
		print(max(a))

Submission status: Accepted

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

idx1, ma1 = A.index(max(A)), max(A)

tmp = A[idx1]
A[idx1] = 0
idx2, ma2 = A.index(max(A)), max(A)

A[idx1] = tmp

for i in A:
	if i == ma1:
		print(ma2)
	else:
		print(ma1)

Submission status: Accepted

Solution code:
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())
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 main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    descending = sorted(A, reverse=True)
    maximum = descending[0]
    second = descending[1]
    for a in A:
        if a == maximum:
            print(second)
        else:
            print(maximum)
main()

Submission status: Accepted

Solution code:
N = int(input())

A = []
for i in range(N):
    a = int(input())
    A.append([a, i])
    
A_ = sorted(A, reverse=True)

#print(A_)

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

Submission status: Accepted

Solution code:
import copy
N = int(input())
output = []
dic = {}
A = []

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

A = sorted(A)
max_1 = A[-1]
max_2 = A[-2]

for i in range(N):
  tmp = dic[i]
  if tmp == max_1:
    output.append(max_2)
  else:
    output.append(max_1)
print(*output, sep="\n")

Submission status: Accepted

Solution code:
import copy
n=int(input())

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

b=[]
b = copy.deepcopy(a)
b.sort(reverse=True)
#print(b)
#print(a)
#print(a[1])
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 = []
for _ in range(N):
    A += [int(input())]
sorted_A = sorted(A)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [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])
   
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from operator import itemgetter
    import sys
    input = sys.stdin.readline

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

    it = iter(sorted(enumerate(A, start=1), key=itemgetter(1), reverse=True))
    i, ma1 = next(it)
    _, ma2 = next(it)

    for j in range(1, N + 1):
        if j == i:
            print(ma2)
        else:
            print(ma1)


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

max_num = -1
max_index = []
second_num = -1
dic = {}
for i in range(1, N+1):
    num = int(input())
    dic[i] = num
    if num > max_num:
        second_num = max_num
        max_num = num
        max_index.clear()
        max_index.append(i)
    elif num == max_num:
        max_index.append(i)
    elif num > second_num:
        second_num = num

for i in range(1, N+1):
    if dic[i] < max_num:
        print(max_num)
    elif dic[i] == max_num:
        if len(max_index) > 1:
            print(max_num)
        else:
            print(second_num)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

base=max(a)
maxkosu=a.count(base)
if maxkosu>1:
  for i in range(N):
    print(base)
else:
  maxidx=a.index(base)
  a[maxidx]=-1
  reigai=max(a)
  for i in range(N):
    if i==maxidx:
      print(reigai)
    else:
      print(base)

Submission status: Accepted

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

Submission status: Accepted

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

m = max(A)
L = sorted(A)
L.sort(reverse = True)

if L[1] == m:
    for _ in range(n):
        print(m)
else:
    for i in range(n):
        if A[i] == m:
            A.pop(i)
            print(max(A))
            A.append(0)
        else:
            print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = [int(input()) for i in range(n)]
S = sorted(A)[::-1]
m = S[0]
sm = S[1]
for a in A:
	print(m if a != m else sm)

Submission status: Accepted

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

for i in range(N):
    if M[N-1]>A[i]:
        print(M[N-1])
    elif M[N-1]==A[i]:
        print(M[N-2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
a=n2(n)
b=sorted(a)
m1=b[-1]
m2=b[-2]
c=[]

for i in a:
    if i==m1:
        c.append(m2)
    else:
        c.append(m1)
print(*c,sep="\n")

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
a=n2(n)
b=sorted(a)
m1=b[-1]
m2=b[-2]

for i in a:
    p0(i==m1,m2,m1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import copy

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

MaxIndex = A.index(max(A))

for i in range(N):
    if i != MaxIndex:
        print(A[MaxIndex])
    else:
        B = copy.copy(A)
        del B[MaxIndex]
        print(max(B))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def main():
    N = int(input())
    As = [int(input()) for _ in range(N)]
    max1 = max(As)
    max_idx = As.index(max1)
    As.remove(max1)
    max2 = max(As)
    max_list = [max1] * N
    max_list[max_idx] = max2
    for m in max_list:
        print(m)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

A=sorted(a)

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

Submission status: Accepted

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

maximum = max(A)
maximum_index = A.index(maximum)
second = max(A[:maximum_index] + A[maximum_index+1:])

for i in range(N):
    if i == maximum_index:
        print(second)
    else:
        print(maximum)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N = int(readline())
    A = [int(i) for i in readlines()]
    B = sorted(A) 
    mx = B[-1]
    mx2 = B[-2]
    for i in A:
        if mx == i:
            print(mx2)
        else:
            print(mx)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

A = [0]*N

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

Max = a[len(a)-1]
PreMax = a[len(a)-2]

for i in range(N):
    
    if A[i] < Max:
        print(Max)
    else:
        print(PreMax)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
maximum=max(A)
maximum2=sorted(A)[-2]
for a in A:
    if a!=maximum:
        print(maximum)
    else:
        print(maximum2)

Submission status: Accepted

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

tNum = max(a)
sNum = sorted(a, reverse=True)[1]

if a.count(tNum) > 1:
  for _ in range(n):
    print(tNum)
  exit()

for i in a:
  if i == tNum:
    print(sNum)
    continue
  print(tNum)

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

Submission status: Accepted

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

max_a = max(a)
if a.count(max_a) > 1:
    for i in range(n):
        print(max_a)
else:
    sec_max = sorted(a)[-2]
    max_i = a.index(max_a)
    for i in range(n):
        if i == max_i:
            print(sec_max)
        else:
            print(max_a)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
x = max(A)
k = A.index(x)
for i in range(N):
  if i != k:
    print(x)
  else:
    A.remove(x)
    print(max(A))

Submission status: Accepted

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

m = max(a)
count = a.count(m)

if count != 1:
    for i in range(n):
        print(m)

else:
    switch = 0
    for i in range(n-1):
        if a[i] == m:
            a.remove(m)
            m2max = max(a)
            print(m2max)
            a.append(m)
            switch = 1
        else:
            print(m)
    
    if switch == 1:
        print(m)
    else:
        a.remove(m)
        m2max = max(a)
        print(m2max)

Submission status: Accepted

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

for i in range(n):
    h.append(int(input()))
    
left = [0] * n
left[0] = h[0]
for i in range(1, n):
    left[i] = max(left[i - 1], h[i])

right = [0] * n
right[-1] = h[-1]
for i in reversed(range(n - 1)):
    right[i] = max(right[i + 1], h[i])

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

Submission status: Accepted

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

for i in range(n):
    h.append(int(input()))
    
h_sort = sorted(h, reverse=True)

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(int(input()) for i in range(N))
A_sorted = sorted(A)

M = max(A)
MI = A .index(M)

S = A_sorted[-2]

for i in range(N):
    if i == MI:
        print(S)
    else:
        print(M)

Submission status: Accepted

Solution code:
import sys


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


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(A[i - 1], left[i - 1])
    right[N - i - 1] = max(A[N - i], right[N - i])
[print(max(left[i], right[i])) for i in range(N)]

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

arr = []

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

M1 = A[-1]
M2 = A[-2]

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
t = sorted(a, reverse=True)
p = t[0]
q = t[1]
for ai in a:
    print(q if ai == p else p)

Submission status: Accepted

Solution code:
n = int(input())

s = []

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

m = max(s)

s2 = s.copy()

s2.remove(m)

m2 = max(s2)

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
#print(a)
s=sorted(a,reverse=True)
max_1=s[0]
max_2=s[1]
#print(s)
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())
a = [0]*n
c = []

for i in range(0,n):
  a[i] = int(input())
c = a
m1 = max(a)
m1_ = a.index(m1)
del c[m1_]
m2 = max(c)
m2_ = c.index(m2)

for i in range(0,n):
  if(i == m1_):
    print(m2)
  else:
    print(m1)

Submission status: Accepted

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

left = [0]
l = 1
for i in A:
    l = max(l,i)
    left.append(l)
right = [0]
r = 1
for i in A[::-1]:
    r = max(r,i)
    right.append(r)
    
for i in range(N):
    print(max(left[i],right[-i-2]))

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter


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 = [0]*n
for i in range(n):
    a[i] = int(input())
aa = sorted(a)
# print(aa)
for i in range(n):
    if a[i] != aa[-1]:
        print(aa[-1])
    else:
        print(aa[-2])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
#import numpy as np
import math
from fractions import Fraction
import itertools

input=sys.stdin.readline
n=int(input())
a=[int(input()) for _ in range(n)]
l=[0]*n
r=[0]*n
l[0]=a[0]
r[0]=a[-1]
for i in range(1,n):
    if a[i]>l[i-1]:
        l[i]=a[i]
    else:
        l[i]=l[i-1]
    if a[n-1-i]>r[i-1]:
        r[i]=a[n-1-i]
    else:
        r[i]=r[i-1]
print(r[n-2])
for i in range(1,n-1):
    print(max(l[i-1],r[n-i-2]))
print(l[n-2])

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
m1=max(a)
m2=sorted(a)[-2]
l=[i for i, x in enumerate(a) if x == m1]

if len(l)==1:
  for i in range(n):
    if i ==l[0]:
      print(m2)
    else:
      print(m1)
else:
  for i in range(n):
    print(m1)

Submission status: Accepted

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

mx_1, mx = sorted(a)[-2:]

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

Submission status: Accepted

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

B=sorted(A.copy())
b1=B[-1]
b2=B[-2]

for a in A:
    if a==b1:
        print(b2)
    else:
        print(b1)

Submission status: Accepted

Solution code:
n = int(input())
maximums = [0, 0]
nums = [int(input()) for _ in range(n)]
maximums = sorted(nums, reverse=True)[:2]
for num in nums:
    if num == maximums[0]:
        print(maximums[1])
    else:
        print(maximums[0])

Submission status: Accepted

Solution code:
N = int(input())
A = [(i,int(input())) for i in range(N)]
B = sorted(A,key=lambda x:x[1],reverse=True)
cnt = 0
bmax = B[0][1]
for i in range(N):
    if B[i][1]==bmax:
        cnt += 1
    else:break
for i in range(N):
    if A[i][1] < bmax:
        print(bmax)
    elif A[i][1]==bmax and cnt==1:
        print(B[1][1])
    elif A[i][1]==bmax and cnt>1:
        print(bmax)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(int(input()) for _ in range(n))
    A_s = sorted(A)
    max_A = A_s[n - 1]
    sub_max_A = A_s[n - 2]

    for i in range(n):
        if A[i] == max_A:
            print(sub_max_A)
        else:
            print(max_A)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = []
    for i in range(N):
        a = int(input())
        A.append(a)
    
    A_sorted = sorted(A, reverse=True)

    ans = []
    for a in A:
        if a == A_sorted[0]:
            ans.append(A_sorted[1])
        else:
            ans.append(A_sorted[0])
    
    print(*ans, sep='\n')

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def resolve():
  n = int(input())
  a = []
  ma = 0
  for i in range(n):
    a.append(int(input()))
    ma = max(ma, a[i])
  b = a.copy()
  b.sort()
  for i in range(n):
    if a[i] == ma:
      print(b[n-2])
    else:
      print(ma)
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    B = sorted(A)
    m = B[-1]
    m2 = B[-2]
    ans = []
    for a in A:
        if a!=m:
            ans.append(m)
        else:
            ans.append(m2)
    return ans
print(*solve(),sep='\n')

Submission status: Accepted

Solution code:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
t=copy.deepcopy(a)
t.sort()
for i in a:
  if i==t[-1]:
    print(t[-2])
    
  else:
    print(t[-1])