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())
A = ([int(input()) for n in range(N)])
sorted_A = sorted(A)
max_ = sorted_A[len(A)-1]
semi_max = sorted_A[len(A)-2]


for i in range(N):
    if(A[i]==max_):
        print(semi_max)
    else:
        print(max_)

Submission status: Accepted

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

A_max = max(A)
A_max_2 = sorted(A)[-2]
for i in range(n):
    if A[i] == A_max:
        print(A_max_2)
    else:
        print(A_max)

Submission status: Accepted

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

max_v1 = max(a)
max_i1 = a.index(max_v1)
a.remove(max_v1)
max_v2 = max(a)

for i in range(n):
    if i == max_i1:
        print(max_v2)
    else:
        print(max_v1)

Submission status: Accepted

Solution code:
N = int(input())

max_num = 1
second_max_num = 1
A = [0]*N
for i in range(N):
    j = int(input())
    A[i] = j
    if j > max_num:
        second_max_num = max_num
        max_num = j
    elif j > second_max_num:
        second_max_num = j

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

Submission status: Accepted

Solution code:
import heapq

n = int(input())
a = []

for i in range(1, n+1):
  av = -int(input())
  heapq.heappush(a, (av, i))

fst = heapq.heappop(a)
sec = heapq.heappop(a)

for i in range(1,n+1):
  if i == fst[1]:
    print (-sec[0])
  else:
    print (-fst[0])

Submission status: Accepted

Solution code:
n = int(input())
maxindex = maxvalue = 0
a = []
for i in range(n):
    _a = int(input())
    if maxvalue <= _a:
        maxvalue = _a
        maxindex = i
    a.append(_a)

for i in range(n):
    if i != maxindex:
        print(maxvalue)
        continue
    t = a[:]
    t.pop(i)
    print(max(t))

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a_max = max(a)
n_max = len(list(filter(lambda x: x==a_max, a)))
if n_max >= 2:
  for i in range(n):
    print(a_max)
else:
  a_exp = max(list(filter(lambda x: x < a_max, a)))
  for i in range(n):
    if a[i] == a_max:
      print(a_exp)
    else:
      print(a_max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpln(n)
m = 0
mm = 0
cnt = 0
for i in a:
    if i > m:
        mm = m
        m = i
        cnt = 0
    elif i == m:
        cnt += 1
    elif i > mm:
        mm = i
for i in a:
    if i == m:
        if cnt > 0:
            print(m)
        else:
            print(mm)
    else:
        print(m)

Submission status: Accepted

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

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

Submission status: Accepted

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

maxa = max(a)
index_max = a.index(maxa)

for i in range(0, n):
    if i == index_max:
        print(sorted(a)[-2])
    else:
        print(maxa)

Submission status: Accepted

Solution code:
N=int(input())
D=sorted(dict([(i,int(input())) for i in range(N)]).items(),key=lambda x:x[1])
M=D[-1][1]
m=D[-2][1]
for i in range(N):
  if i==D[-1][0]:
    print(m)
  else:
    print(M)

Submission status: Accepted

Solution code:
# ABC134C - Exception Handling
def main():
    N, *A = map(int, open(0))
    m1, m2 = sorted(A, reverse=1)[:2]
    ans = [m1 if i != m1 else m2 for i in A]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC134C - Exception Handling
def main():
    N, *A = map(int, open(0))
    sorted_A = sorted(A)
    m1, m2 = sorted_A[-1], sorted_A[-2]
    ans = [m1 if i != m1 else m2 for i in A]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
al = [int(input()) for _ in range(n)]
al2 = sorted(al)

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

Submission status: Accepted

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

value=max(A)
index = A.index(max(A))
for i in range(N):
  if i==index:
    b=A.pop(i)
    print(max(A))
  else:
      print(value)

Submission status: Accepted

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

Submission status: Accepted

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

    A_sorted = sorted(A)

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


if __name__ == '__main__':
    main()

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 = []
b = []
 
for i in range(n):
    s = int(input())
    a.append(s)
    b.append(s)
    
b.sort()
b.reverse()
 
if b[0] == b[1]:
    for i in range(n):
        print(b[0])
else:
    for i in range(n):
        if a[i] == b[0]:
            print(b[1])
        else:
            print(b[0])

Submission status: Accepted

Solution code:
import copy

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

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a_max = max(a)
b_max = sorted(a)[-2]
for j in range(n):
  if a[j] == a_max:
    print(b_max)
  else:
    print(a_max)

Submission status: Accepted

Solution code:
n=int(input())
lists=[int(input()) for i in range(n)]
liscop=lists.copy()
lists=sorted(lists)
for i in liscop:
    if i==lists[-1]:
        print(lists[-2])
    else:
        print(lists[-1])

Submission status: Accepted

Solution code:
import numpy as np
#import heapq
N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
A = np.array(A)
A_max_1 = np.max(A)
A_max_index = np.argmax(A)
A = np.delete(A, A_max_index)
A_max_2 = np.max(A)
answer = []
for i in range(N):
  if not i == A_max_index:
    answer.append(A_max_1)
  else:
    answer.append(A_max_2)
for i in range(N):
  print(answer[i])

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
x=max(a)
count=0
b=len([a[i] for i in range(len(a)) if a[i]==x])
for j in range(n):
    if b>1:
        print(x)
    else:
        if a[j]==x:
            tmp=a[j]
            a.remove(a[j])
            print(max(a))
            a.insert(j,tmp)
        else:
            print(x)

Submission status: Accepted

Solution code:
N=int(input())
A = []
for _ in range(N):
    A.append(int(input()))
A2=sorted(A,reverse=True)
M=A2[0]
M2=A2[1]
for i in range(N):
  #print(A[i])
  
  if A[i]==M:
    print(M2)
  else:
    print(M)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
max1 = 0
max2 = 0
for i in range(N):
  if max1 < A[i]:
    max2 = max1
    max1 = A[i]
  elif A[i] > max2:
    max2 = A[i]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

(fst, snd) = (0, 0)
for i in range(N):
    a = int(input())
    if a > fst:
        (fst, snd, argFst) = (a, fst, i)
    elif a > snd:
        snd = a

for i in range(N):
    if i == argFst:
        print(snd)
    else:
        print(fst)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A_list = []
for i in range(1,N+1):
    A = int(input())
    A_list.append(A)
A_list_sort = sorted(A_list)

max_a = A_list_sort[-1]
max_b = A_list_sort[-2]


for i in range(N):
    if A_list[i] == max_a:
        print(max_b)
    else:
        print(max_a)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
x = 0
x_max = 0
for _ in range(n):
  x = int(input())
#  if x_max 
  a.append(x)

b = a.copy()  
b.sort(reverse=True)
a_max1 = b[0]
a_max2 = b[1] 

for i in a:
  if i == a_max1:
    print(a_max2)
  else:
    print(a_max1)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [int(input().rstrip('\n')) for _ in range(n)]
    b = sorted(a, reverse=True)
    for i in range(len(a)):
        if a[i] == b[0]:
            print(b[1])
        else:
            print(b[0])


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
N = int(input())

max = -1
max2 = -1
maxnum = -1
max2num = -1
for index in range(N):
    temp = int(input())
    if max < temp:
        max = temp
        maxnum = index
    elif max2 < temp:
        max2 = temp

for index in range(N):
    if index == maxnum:
        print(max2)
    else:
        print(max)

Submission status: Accepted

Solution code:
n = int(input())
max_id = 0
cur_max = 0
second_max = 0
for i in range(n):
  ai = int(input())
  if ai > cur_max:
    second_max = cur_max
    cur_max = ai
    max_id = i
  elif ai > second_max:
    second_max = ai

for i in range(n):
  if (i == max_id):
    print(second_max)
  else:
    print(cur_max)

Submission status: Accepted

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


max1=-1
max2=-10

max1_ind=-100
max2_ind=-100

for i in range(len(S)):
        if S[i] > max1:
                max2=max1
                max2_ind = max1_ind

                max1=S[i]
                max1_ind=i
        elif S[i] > max2:
                max2=S[i]
                max2_ind=i

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

Submission status: Accepted

Solution code:
import heapq
import copy
N = input()
A = [-int(input()) for _ in range(int(N))]
A_heap = copy.deepcopy(A)
heapq.heapify(A_heap)
for idx, a in enumerate(A):
    pop_A = heapq.heappop(A_heap)
    pop_A_list = []
    pop_A_list.append(pop_A)
    if pop_A == a:
        pop_A2 = heapq.heappop(A_heap)
        print(-(pop_A2))
        heapq.heappush(A_heap, pop_A)
        heapq.heappush(A_heap, pop_A2)
        continue

    print(-(pop_A))
    heapq.heappush(A_heap, pop_A)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
m=max(a)
x=a.index(m)
for i in range(n):
  if i!=x:
    print(m)
  else:
    print(max(a[:i]+a[i+1:]))

Submission status: Accepted

Solution code:
N=int(input())
Numbers=[int(input()) for i in range(N)]
Numbers2=sorted(Numbers)
Amax=Numbers2[-1]
Asecond=Numbers2[-2]
for j in Numbers:
        if j != Amax:
                print(Amax)
        else:
                print(Asecond)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input()) for n in range(N)]
m=max(A)
n=sorted(A,reverse=True)[1]
print("\n".join([str(m) if a<m else str(n) for a in A]))

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input()) for n in range(N)]
m=max(A)
n=sorted(A,reverse=True)[1]
for i in range(N):
    if A[i]<m:
        print(m)
    else:
        print(n)

Submission status: Accepted

Solution code:
N = int(input())
A = [0]*N

for r in range(N): A[r] = int(input())
A_max = max(A)
A_sec = sorted(A)[-2]

for r in range(N):
  if A[r] == A_max: print(A_sec)
  elif A[r] == A_sec: print(A_max)
  else: print(A_max)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
b=max(a)
c=a.count(b)
if c>1:
  for i in range(n):
    print(b)
else:
  d=sorted(a, reverse=True)
  e=d[1]
  f=0
  h=0
  while f!=b:
    g=a[h]
    if f<g:
      f=g
    h=h+1
  for i in range(h-1):
    print(b)
  print(e)
  for i in range(n-h):
    print(b)

Submission status: Accepted

Solution code:
N = int(input())
M1 = 0
M2 = 0
A = []
for a in range(N):
    a = int(input())
    A.append(a)
    if a > M2:
        if a > M1:
            M2 = M1
            M1 = a
        else:
            M2 = a

for a in A:
    if a == M1:
        print(M2)
    else:
        print(M1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
b = copy.deepcopy(a)
amax = max(a)
b.remove(amax)
amax2 = max(b)
for i in range(n):
    if a[i] == amax:
        print(amax2)
    else:
        print(amax)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
B=sorted(A,reverse=True)
max=B[0]
sec=B[1]

if max==sec:
    for n in range(N):
        print(max)
else:
    for a in A:
        if a==max:
            print(sec)
        else:
            print(max)

Submission status: Accepted

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

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]

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

Submission status: Accepted

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

import numpy as np

N = int(readline())
A = np.zeros(N+2,np.int32)
A[1:-1] = np.array(read().split(),np.int32)

A

from_left = np.maximum.accumulate(A)
from_right = np.maximum.accumulate(A[::-1])[::-1]

answer = np.maximum(from_left[:-2], from_right[2:])
print('\n'.join(answer.astype(str)))

Submission status: Accepted

Solution code:
N = int(input())
A = []
afirst = 0
asecond = 0
for _ in range(N):
	a = int(input())
	A.append(a)
	if(afirst < a):
		asecond = afirst
		afirst = a
	elif(asecond<a):
		asecond = a

for a in A:
	if(a == afirst):
		print(asecond)
	else:
		print(afirst)

Submission status: Accepted

Solution code:
def main(A):
    maxInt = max(A)
    secondInt = sorted(A)[-2]

    for a in A:
        if a == maxInt:
            print(secondInt)
        else:
            print(maxInt)

if __name__ == '__main__':
    N = int(input())
    A = [int(input()) for _ in range(N)]
    main(A)

Submission status: Accepted

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

max_a = max(al)  
tmp_al = al[:]
tmp_al.remove(max_a)
snd_a = max(tmp_al)
  
for a in al:
  if a == max_a:
    print(snd_a)
  else:
    print(max_a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = []
M = 0
p = 0
for i in range(N):
	t = int(input())
	A.append(t)
	if M < t:
		M = t
		p = i

A[p] = 0
sec = max(A)

for i in range(N):
	if i == p:
		print(sec)
	else:
		print(M)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
no1 = max(A)
import sys
if A.count(no1) > 1:
    for i in range(N):
        print(no1)
    sys.exit()
else:
    ind = A.index(no1)
    no2 = max(A[:ind]+A[ind+1:])
    for i in range(N):
        if i == ind:
            print(no2)
        else:
            print(no1)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
maxa=max(A)
id=A.index(maxa)
for i in range(N):
  if i==id:
    tmp=max(A[:i]+A[i+1:])
    print(tmp)
  else:
    print(maxa)

Submission status: Accepted

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

sortA = sorted(a, reverse=True)
maxA = sortA[0]
semiMaxA = sortA[1]

for i in range(n):
  if a[i] == maxA:
    print(semiMaxA)
  else:
    print(maxA)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
a_max=max(a)
a_second=sorted(a)[-2]

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = []
    ret = []
    for i in range(N):
        A.append(int(input()))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
B = A.copy()
B.sort()
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())
max1=0
max2=0
max1_i=0

for i in range(n):
    a=int(input())
    if a>max1:
        max2=max1
        max1=a
        max_i=i
    elif a>max2:
        max2=a
    else:
        pass

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(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:
import heapq

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

r, s = heapq.nlargest(2, lis)

for x in lis:
    if x == r:
        print(s)
    else:
        print(r)

Submission status: Accepted

Solution code:
import heapq

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

r, s = heapq.nlargest(2, lis)

if lis.count(r) == 1:
    for x in lis:
        if x == r:
            print(s)
        else:
            print(r)

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

Submission status: Accepted

Solution code:
N = int(raw_input())
A = []
for i in range(0,N):
  A.append(int(raw_input()))
A = list(enumerate(A))
A = sorted(A, key=lambda x: x[1])
max_A = A[N-1][1]
second_max_A = A[N-2][1]
A = sorted(A,key=lambda x: x[0])
for i in range(0,N):
  if A[i][1] == max_A:
    print second_max_A
  else:
    print max_A

Submission status: Accepted

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

b = A[:]
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:
import copy
N = int(input())
A = [int(input()) for _ in range(N)]
AA = sorted(copy.deepcopy(A))
MAX = A.index(AA[-1])
for i in range(N):
  if i == MAX:
    print(AA[-2])
  else:
    print(AA[-1])

Submission status: Accepted

Solution code:
n,*a=map(int,open(0))
b=sorted(a)
for i in range(n):
    print([b[-2],b[-1]][a[i]<b[-1]])

Submission status: Accepted

Solution code:
n,*a=map(int,open(0))
b=sorted(a)
for i in range(n):
    print([b[-1],b[-2]][a[i]==b[-1]])

Submission status: Accepted

Solution code:
n,*a=map(int,open(0))
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 = []
for i 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(second)
  else:
    print(first)

Submission status: Accepted

Solution code:
def main():

    A = [int(i) for i in open(0).read().split()[1:]]
    tmp = A[:]
    tmp.sort()
    first = tmp[-1]
    second = tmp[-2]
    print("\n".join(str(first) if a != first else str(second) for a in A))
    return


main()

Submission status: Accepted

Solution code:
def main():

    A = [int(i) for i in open(0).read().split()[1:]]
    tmp = sorted(A[:])
    print("\n".join(str(tmp[-1]) if a != tmp[-1] else str(tmp[-2]) for a in A))
    return


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
A = [int(input()) for _ in range(n)]
# ans = []
#
# for _ in range(n):
#     tmp = A.popleft()
#     print(max(A))
#     A.append(tmp)

# 時間がかかるのはソートだけ。
sorted_A = sorted(A, reverse=True)
max_val = sorted_A[0]
second_val = sorted_A[1]

for i in range(n):
    # 索引は速いらしい
    if A[i] != max_val:
        print(max_val)
    else:
        print(second_val)

Submission status: Accepted

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

tmp = a[:]
max1_val = max(tmp)
max1_idx = tmp.index(max1_val)
del tmp[max1_idx]
max2_val = max(tmp)

for i in range(n):
    if i != max1_idx:
        print(max1_val)
    else:
        print(max2_val)

Submission status: Accepted

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

sort_A = list(set(A))
A_max = sort_A[-1]
n_A_max = A.count(A_max)

if n_A_max == 1:
    A_second_max = sort_A[-2]

if n_A_max >= 2:
    for idx in range(N):
        print(A_max)
else:
    for idx in range(N):
        print(A_second_max if A[idx] == A_max else A_max)

Submission status: Accepted

Solution code:
from copy import deepcopy
n,*a=map(int,open(0).read().split())
b=deepcopy(a)
b.sort()
c=b[-1]
for i in a:
    if i==b[-1]:
        print(b[-2])
    else:
        print(c)

Submission status: Accepted

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

max_A = max(A)
next_A = sorted(A, reverse=True)[1]
for i in range(N):
    if A[i] != max_A:
        print(max_A)
    else:
        print(next_A)

Submission status: Accepted

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

Submission status: Accepted

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

m1=B[0]
m2=B[1]

for j in A:
    if j == B[0]:
        print(B[1])
    else:
        print(B[0])

Submission status: Accepted

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

Submission status: Accepted

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

N = int(input())

max_num = 0
max_index = 0
second_num = 0
for i in range(N):
    num = int(input())
    if num >= max_num:
        if second_num < 1:
            max_num = num
            second_num = 1
        else:
            second_num, max_num = max_num, num
        max_index = i
    elif num > second_num:
        second_num = num
for i in range(N):
    if max_index == i:
        print(second_num)
    else:
        print(max_num)

Submission status: Accepted

Solution code:
N = int(input())
A = []
largest = -1
second_largest = -1
more_than_one_largetst = False

for i in range(N):
  a = int(input())
  A.append(a)
  if largest == a:
    more_than_one_largest = True
  else:
    if largest < a:
      second_largest = largest
      largest = a
      more_than_one_largest = False
    else:
      if second_largest < a:
        second_largest = a
      else:
        pass

for a in A:
  if a != largest:
    print(largest)
  else:
    if more_than_one_largest:
      print(largest)
    else:
      print(second_largest)

Submission status: Accepted

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

a_sorted = sorted(a, reverse=True)
for x in a:
  if x == a_sorted[0]:
    print(a_sorted[1])
  else:
    print(a_sorted[0])

Submission status: Accepted

Solution code:
def main():

    A = [int(i) for i in open(0).read().split()[1:]]
    tmp = A[:]
    tmp.sort()
    first = tmp[-1]
    second = tmp[-2]
    print("\n".join(str(first) if not a == first else str(second) for a in A))
    return


main()

Submission status: Accepted

Solution code:
from heapq import *

N=int(input())
A=[int(input()) for i in range(N)]
h=[]
for i in A:
    heappush(h, -i)
maxh = -heappop(h)
secondh = -heappop(h)
for i in A:
    print(maxh if i != maxh else secondh)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

l_s = sorted(l)

for i in l:
    if i != l_s[-1]:
        print(l_s[-1])
    else:
        print(l_s[-2])

Submission status: Accepted

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


def main():
    n = int(input())
    A = [[int(input()), i] for i in range(n)]
    B = list(reversed(sorted(A)))
    a_1 = B[0][0]
    m = B[0][1]
    a_2 = B[1][0]

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = [(int(input()), i) for i in range(N)]
A.sort()
x1, i1 = A[-1]
x2, i2 = A[-2]

for i in range(N):
    if i == i1:
        print(x2)
    else:
        print(x1)

Submission status: Accepted

Solution code:
n=int(input())
l=[int(input()) for _ in range(n)]
l2=list()
l2=sorted(l,reverse=True)
m1=l2[0]
m2=l2[1]
ansl=[m1 for i in range(n)]
if m1!=m2:
    for i in range(n):
        if l[i]==m1:
            ansl[i]=m2
            break
for j in range(n):
    print(ansl[j])

Submission status: Accepted

Solution code:
n = input()
a = [input() for _ in xrange(n)]
ans = max(a)
i = a.index(ans)
ans2 = max(a[:i] + a[i + 1:])
for i in xrange(n):
  if a[i] != ans:
    print ans
  else:
    print ans2

Submission status: Accepted

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

A_sorted = sorted(A)
for x in A:
  if x < m:
    print(m)
  else:
    print(A_sorted[-2])

Submission status: Accepted

Solution code:
n = int(input())
mv1 = 0
mi1 = 0
mv2 = 0
for i in range(n):
    tmp = int(input())
    if tmp > mv1:
        mv1 = tmp
        mi1 = i
    elif tmp > mv2:
        mv2 = tmp

for i in range(n):
    if i != mi1:
        print(mv1)
    else:
        print(mv2)

Submission status: Accepted

Solution code:
n = int(input())
mv = 0
mi = 0
d = []
for i in range(n):
    tmp = int(input())
    if tmp > mv:
        mv = tmp
        mi = i
    else:
        d.append(tmp)

for i in range(n):
    if i == mi:
        print(max(d))
    else:
        print(mv)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
if N == 2:
    for j in A[::-1]:
        print(j)
else:
    tmp = sorted(A)
    del tmp[0:(N-2)]
    for i in range(N):
        if A[i] == tmp[1]:
            print(tmp[0])
        else:
            print(tmp[1])

Submission status: Accepted

Solution code:
N = int(input())
max = [0, 0] # [10,20]
maxIndex = -1

for i in range(N):
  cur = int(input())
  if(max[0] <= cur):
    max[0] = cur
    if(max[1] < max[0]):
      max[1], max[0] = max[0], max[1]
      maxIndex = i

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

Submission status: Accepted

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

Submission status: Accepted

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

A_sorted = sorted(A)

for i in range(N):
    v = A[i]
    if v < m:
        print(m)
    else:
        print(A_sorted[-2])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import heapq

N=int(input())
l=[]

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

ll=sorted(l)

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