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 _ in range(N)]
A_dic = {}
for ai in A:
    if ai not in A_dic:
        A_dic[ai] = 1
    else:
        A_dic[ai] += 1

A_sort = sorted(A, reverse=True)
max_1 = A_sort[0]
max_2 = A_sort[1]

for ai in A:
    if ai == max_1 and A_dic[ai] == 1:
        print(max_2)
    else:
        print(max_1)

Submission status: Accepted

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

M = max(a)
b = a.count(M)
if b >=2:
    for i in range(n):
        print(M)
else:
    A = copy.copy(a)
    for i in range(b):
        a.remove(M)
        m = max(a)
    for i in A:
        if i == M:
            print(m)
        else:
            print(M)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = [int(input()) for i in range(n)]
max = np.max(a)
max_pos = np.argmax(a)
b = [max]*n
b[max_pos] = np.max(a[:max_pos]+a[max_pos+1:])
for key in b:
    print(key)

Submission status: Accepted

Solution code:
#C
from collections import Counter
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
b = a.copy()
b.sort()
b.reverse()
fi = b[0]
se = b[1]
for i in a:
    if i == fi:
        print(se)
    else:
        print(fi)

Submission status: Accepted

Solution code:
N = int(input())
k = []
for i in range(N):
    k.append(int(input()))
B = k.copy()
B.sort()
B.reverse()
P = B[0]
Q = B[1]
for i in range(N):
    if k[i] == P:
        print(Q)
    else:
        print(P)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(input()) for i in range(n)]
    a_sorted = sorted(a)
    first, second = a_sorted[-1], a_sorted[-2]
    f_idx = a.index(first)

    for idx in range(n):
        if idx == f_idx:
            print(second)
        else:
            print(first)

main()

Submission status: Accepted

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

A_copy = copy.copy(A)
A_copy.sort(reverse=True)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
b = a.copy()
m = max(a)
b2 = b.remove(m)
mb = max(b)
for j in a:
  if j < m:
    print(m)
  elif j == m:
    print(mb)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n = int(input())
a = [int(input()) for _ in range(n)]
b = 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:
import copy

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

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

Submission status: Accepted

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

Submission status: Accepted

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

sot = sorted(a,reverse = True)
ans1 = sot[0]
ans2 = sot[1]

for i in a:
  if i != ans1:
    print(ans1)
  else:
    print(ans2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [0 for i in range(n)]
a[0] = int(input())
max = a[0]
max2 = 0
for i in range(1,n):
    a[i] = int(input())
    if  a[i] >= max:
        max2 = max
        max = a[i]
    elif a[i] >= max2:
        max2 = a[i]
for i in range(n):
    if a[i] == max:
        print(max2)
    else:
        print(max)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
# 列ベクトルとかの受け取り
lists = [int(input()) for _ in range(n)]
arr = np.array(lists)

maxnum = max(lists)
filter = arr == maxnum
maxarr = arr[filter]
filt2 = arr < maxnum
nextmaxnum = max(arr[filt2]) if len(arr[filt2])!=0 else maxnum

if len(maxarr)>1:
    for _ in range(n):
        print(maxnum)
else:
    for num in arr:
        if num != maxnum:
            print(maxnum)
        else:
            print(nextmaxnum)

Submission status: Accepted

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array([0] + [ir() for _ in range(N)] + [0])
max_left = np.maximum.accumulate(A)
max_rihgt = np.maximum.accumulate(A[::-1])[::-1]
answer = np.zeros(N+1, np.int64)
answer[1:] = np.maximum(max_left[:-2], max_rihgt[2:])
print('\n'.join(answer[1:].astype(str)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
#from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

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

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



resolve()

Submission status: Accepted

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

def solve(N: int, A: "List[int]"):
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

if __name__ == '__main__':
    
    N = int(input())
    A = [0]*N
    max_a1 = 0
    max_a2 = 0
    for i in range(N):
        a = int(input())
        if a > max_a1:
            max_a1 ,max_a2 = a, max_a1
        elif a > max_a2:
            max_a2 = a
        A[i] = a

    for i in range(N):
        print(max_a1) if A[i] < max_a1 else print(max_a2)

Submission status: Accepted

Solution code:
import os, sys, re, math

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

sa = sorted(A, reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = []
for i in range(n):
    l.append(int(input()))
sorted_l = sorted(l)  # nlogn (n=2e5)
mmm = sorted_l[-1]
only = mmm != sorted_l[-2]
for p in l:
    if not only or p != mmm:
        print(mmm)
    else:
        print(sorted_l[-2])

Submission status: Accepted

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

ma_n = 0
ma_b = 0
mn = 0
for i in range(N):
    if A[i] >= ma_n:
        ma_b = ma_n
        ma_n = A[i]
        mn = i
    elif A[i] >= ma_b:
        ma_b = A[i]
for i in range(N):
    if i != mn:
        print(ma_n)
    else:
        print(ma_b)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from heapq import heappush, heappop
#input = sys.stdin.readline

def main():
    n=int(input())
    a=[(int(input()),i) for i in range(n)]
    a.sort(reverse=True)
    m,mi=a[0][0],a[0][1]
    for i in range(n):
        if mi==i:
            print(a[1][0])
        else:
            print(m)
  
if __name__ == '__main__':
    main()

Submission status: Accepted

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

c = [0] * n
d = [0] * n

i = 0
for j in range(n):
    c[j] = i
    i = max(i, a[j])
i = 0
for j in reversed(range(n)):
    d[j] = i
    i = max(i, a[j])

for i in range(n):
    print(max(c[i],d[i]))

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
max1 = max(A)
max2 = sorted(A,reverse = True)[1]
for i in range(N):
    if(A[i] == max1):
        print(max2)
    else:
        print(max1)

Submission status: Accepted

Solution code:
n=int(input())
l=[int(input()) for _ in range(n)]
s=sorted(l)
a,b=s[-1],s[-2]
for i in l: print([b,a][a>i])

Submission status: Accepted

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

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

b = sorted(a, reverse=True)

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

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

# 最大値を取得
max_num = max(numbers)

# 最大値を同じ値がいくつ在るかを確認
max_nums = numbers.count(max_num)

if max_nums >= 2:
    for i in range(len(numbers)):
        print(max_num)
else :
    max_index = numbers.index(max(numbers))
    for i in range(len(numbers)):
        if i == max_index:
            second_max = sorted(numbers)[-2]
            print(second_max)
        else :
            print(max_num)

Submission status: Accepted

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

A_sorted = sorted(A, reverse=True)
max1 = A_sorted[0]
max2 = A_sorted[1]

if max1 == max2:
  for _ in range(N):
    print(max1)
else:
  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)]
b = a.index(max(a))
c = max(a)
a.remove(max(a))
for i in range(n):
  if i == b:
    print(max(a))
  else:
    print(c)

Submission status: Accepted

Solution code:
import heapq
q = []
N = int(input())
A = [int(input()) for _ in range(N)]
for i in range(N):
    heapq.heappush(q, -A[i])

MAX1 = -heapq.heappop(q)
MAX2 = -heapq.heappop(q)
for i in range(N):
    if A[i] == MAX1:
        print(MAX2)
    else:
        print(MAX1)

Submission status: Accepted

Solution code:
_, *a = map(int, open(0).read().split())
s = sorted(a)
for i in a:
    print(s[(i < s[-1])-2])

Submission status: Accepted

Solution code:
from copy import deepcopy

def solve():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    B = deepcopy(A)
    B.sort()

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

solve()

Submission status: Accepted

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


arr = sorted(a)

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

Submission status: Accepted

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

A_sort = sorted(A)

A_max = A_sort[-1]
A_second_max = A_sort[-2]

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Exception Handling
https://atcoder.jp/contests/abc134/tasks/abc134_c

"""
import sys


def solve(arr):
    sarr = sorted(arr)
    ans = [sarr[-1] if a != sarr[-1] else sarr[-2] for a in arr]
    return ans


def main(args):
    N = int(input())
    arr = [int(input()) for _ in range(N)]
    ans = solve(arr)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
import sys
import os
import copy

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

    N = int(sys.stdin.readline().rstrip())
    A = [int(sys.stdin.readline().rstrip()) for _ in range(N)]
    B = copy.copy(A)
    A.sort(reverse=True)
    f = A[0]
    s = A[1]

    for n in range(N):
        t = B[n]
        if f == t:
            print(s)
        else:
            print(f)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# C
n = int(input())
a = [int(input()) for i in range(n)]
maxa = [-1,0]
premaxa = [-1,-1]
for i,num in enumerate(a):
    if num >= maxa[1]:
        premaxa = [maxa[0], maxa[1]]
        maxa = [i,num]
    elif num > premaxa[1]:
        premaxa = [i,num]
for i in range(n):
    if i == maxa[0]:
        print(premaxa[1])
    else:
        print(maxa[1])

Submission status: Accepted

Solution code:
N = int(input())
a = list()
tmp = [0, 0]

for _ in range(N):
    ai = int(input())
    a.append(ai)
    if ai > tmp[1]:
        tmp[1] = ai
    elif ai > tmp[0]:
        tmp[0] = ai

m = tmp[1]

for ai in a:
    ans = m
    if ai == m:
        ans = tmp[0]
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
first = 0
second = 0
first_index = 0
second_index = 0
for i in range(n):
    x = int(input())
    if x > first:
        second_index = first_index
        second = first
        first = x
        first_index = i
    elif x > second:
        second = x
        second_index = i
for i in range(n):
    if i == first_index:
        print(second)
    else:
        print(first)

Submission status: Accepted

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

my_max = np.max(np.array(A))
max_count = np.count_nonzero(A == my_max)

if max_count > 1:
    [print(my_max) for _ in range(N)]
else:
    my_next_max = np.max(np.array([a for a in A if a != my_max]))
    [print(my_max) if a != my_max else print(my_next_max) for a in A]

Submission status: Accepted

Solution code:
N = int(input())
A = []
my_max = 0
for _ in range(N):
    a = int(input())
    A.append(a)
    my_max = max(my_max, a)

max_count = A.count(my_max)

if max_count > 1:
    [print(my_max) for _ in range(N)]
else:
    my_next_max = max([a for a in A if a != my_max])
    [print(my_max) if a != my_max else print(my_next_max) for a in A]

Submission status: Accepted

Solution code:
n = int(input())
A = [int(input()) for _ in range(n)]
AM = sorted(A)[-2:]
for a in A:
    print(AM[a != AM[1]])

Submission status: Accepted

Solution code:
n=int(input())
A=[int(input()) for _ in range(n)]
m=max(A)
ind=A.index(m)
A[ind]=0
m2=max(A)
for i in range(n):
    print(m2 if i == ind else m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
import heapq
a = []
heapq.heapify(a) # リストを変換
z = []
for i in range(n):
    ai = int(input())
    z.append(ai)
    if i < 2:
        heapq.heappush(a, ai)
    else:
        t = heapq.heappop(a)
        #print(ai, t)
        heapq.heappush(a, max(ai, t))

x2 = heapq.heappop(a)
x1 = heapq.heappop(a)

for zi in z:
    if x1 != zi:
        print(x1)
    else:
        print(x2)

Submission status: Accepted

Solution code:
n = int(input())
l = [int(input()) for i in range(n)]
lr = sorted(l,reverse = True)
ma = max(l)
ind = l.index(ma)
for i in range(n):
  if i == ind:
    print(lr[1])
  else:
    print(ma)

Submission status: Accepted

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

SA = sorted(A, reverse=True)
max_1A = SA[0]
max_2A = SA[1]

for i in range(N):
  if A[i] == max_1A:
    print(max_2A)
  else:
    print(max_1A)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(input()) for _ in range(n)]
maxA = max(A)
maxIdx = A.index(maxA)
for i in range(n):
  if i != maxIdx:
    print(maxA)
  else:
    print(max(A[:i] + A[i + 1:]))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = [0]*N
for i in range(N):
  A[i] = int(input())
#print(A)
M = max(A)
ind = A.index(M)
#print(ind)
A.pop(ind)
m = max(A)
for i in range(N):
  #print(i)
  if i != ind:
    print(M)
  else:
    print(m)

Submission status: Accepted

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

a1=max(a)
temp=copy.copy(a)
temp.remove(a1)
a2=max(temp)


for i in range(n):
    if a[i]==a1:
        print(a2)
    else:
        print(a1)

Submission status: Accepted

Solution code:
N = int(input())
List = [int(input()) for _ in range(N)]
s_list = sorted(List,reverse=True)
Max1 = s_list[0]
Max2 = s_list[1]

for i in range(N):
    if List[i]==Max1:
        print(Max2)
    else:
        print(Max1)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
m1=max(a)
m2=-1
c=0
for x in a:
    if x==m1:c+=1
    if x!=m1:m2=max(m2,x)
if c>=2:m2=m1
if m2==-1:m2=m1
for x in a:
    if x==m1:print(m2)
    else:print(m1)

Submission status: Accepted

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

sort_a = sorted(a)

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
maxi = [0, 0]
for _ in range(n):
    a.append(int(input()))
    if maxi[0] < a[-1]: 
        maxi[1] = maxi[0]
        maxi[0] = a[-1]
    elif maxi[1] < a[-1]:
        maxi[1] = a[-1]

for x in a:
    if x == maxi[0]: print(maxi[1])
    else: print(maxi[0])

Submission status: Accepted

Solution code:
N=int(input())
first=0
second=0
d=[0]
for i in range(N):
  a=int(input())
  if first<a:
    first=a
    d=i
  elif second<a:
    second=a
if first==second:
  for _ in range(N):
    print(first)
else:
  for j in range(N):
    if j==d:
      print(second)
    else:
      print(first)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(A)
sort_A = sorted(c.items(), key=lambda x: x[0], reverse=True)
if sort_A[0][1] > 1:
    for _ in range(N):
        print(sort_A[0][0])
else:
    for i in range(N):
        if A[i] != sort_A[0][0]:
            print(sort_A[0][0])
        else:
            print(sort_A[1][0])

Submission status: Accepted

Solution code:
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

INF = 10**7
max = -INF
max2 = -INF

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
ma=max(a)
b=a
for i in range(n):
  if b[i]==ma:
    b[i]=0
    p=i
    break
    
maa=max(b)
A=[]
for i in range(n):
  if i!=p:
    A.append(ma)
  else:
    A.append(maa)
    
for i in range(n):
  print(A[i])

Submission status: Accepted

Solution code:
import heapq

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

list_ans = list_score.copy()
list_ans.sort()


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

Submission status: Accepted

Solution code:
def main(n,a):
    lst = sorted(a, reverse = True)
    first, second = lst[0:2]
    res = []
    for i in range(len(a)):
        if a[i] == first:
            res.append(str(second))
        else:
            res.append(str(first))
    return res

n = int(input())
a = [int(input()) for _ in range(n)]
print("\n".join(main(n,a)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#134_C
n=int(input())
a=[int(input()) for _ in range(n)]
max1,max2=0,0
for i in range(n):
    if a[i]>max1:
        max2=max1
        max1=a[i]
    elif a[i]>max2:
        max2=a[i]
        
for i in range(n):
    print(max1 if a[i]!=max1 else max2)

Submission status: Accepted

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

for i in l:
	if i<k[-1]:
		print(k[-1])
	if i==k[-1]:
		print(k[-2])

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input().rstrip())

numbers = [int(input().rstrip()) for i in range(n)]

ordered = list(reversed(sorted(numbers)))

for i in numbers:
    if i == ordered[0]:
        print(ordered[1])
    else:
        print(ordered[0])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)
M0 = B[-1]
M1 = B[-2]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(stdin.readline().rstrip()) for _ in range(n)]

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]

maxA = max(A)
B = sorted(A, reverse = True)
secA = max(B[1:])
for i in range(N) :
    if A[i] == maxA :
        print(secA)
    else :
        print(maxA)

Submission status: Accepted

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

M = max(A)
ind = A.index(M)
A[ind] = 0
M2 = max(A)


if M in A:
    for i in range(n):
        print(M)
else:
    for i in range(n):
        if A[i] == 0:
            print(M2)
        else:
            print(M)

Submission status: Accepted

Solution code:

n = int(input())

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

B = sorted(A, reverse=True)

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

Submission status: Accepted

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

First = max(A)
ind = A.index(First)
A[ind] = 0
Second = max(A)
A[ind] = First

for i in range(n):
    if A[i] == First:
        print(Second)
    else:
        print(First)

Submission status: Accepted

Solution code:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
b=copy.deepcopy(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:
def main(n: int, a: list):
    a_max, a_second = sorted(a, reverse=True)[:2]

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


if __name__ == "__main__":
    n = int(input())
    a = [int(input()) for _ in range(n)]

    main(n, a)

Submission status: Accepted

Solution code:
import sys
N = int(input())
A = [int(input()) for _ in range(N)] 
A_max1 = max(A)
if A.count(A_max1) >= 2:
    for i in range(N):
        print(A_max1)
    sys.exit()    
elif  A.count(A_max1) == 1:
    A[A.index(A_max1)] = 0
    A_max2 = max(A)
    A[A.index(0)] = A_max1
    for i in range(N):
        if A[i] == A_max1:
            print(A_max2)
        else:
            print(A_max1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from copy import copy


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A_max = copy(A)
    A_max.sort(reverse=True)

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

A = []
max1 = 0
max2 = 0
max1w = False
for _ in range(n):
    a = int(input())
    A.append(a)
    if a > max1:
        max2 = max1
        max1 = a
        max1w = False
    elif a == max1:
        max1w = True
    elif a > max2:
        max2 = a

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

Submission status: Accepted

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

right = [0]
left = [0]

for a in A:
   left.append(max(a, left[-1]))

for a in reversed(A):
   right.append(max(a, right[-1]))

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

Submission status: Accepted

Solution code:
N = int(input())
A = [0]*N
for i in range(0, N):
    A[i] = int(input())
B = A.copy()
B.sort()
m1, m2 = B[N-1], B[N-2]
for i in range(0, N):
    if A[i] != m1:
        print (m1)
    else:
        print (m2)

Submission status: Accepted

Solution code:
import heapq
N = int(input())
A = []

for _ in range(N):
    A.append((-1)*(int(input())))

B = A.copy()

heapq.heapify(B)
max_1 = 0 - heapq.heappop(B)
max_2 = 0 - heapq.heappop(B)

if max_1 == max_2:
    for _ in range(N):
        print(max_1)
        
else:
    index = A.index(-max_1)
    
    for i in range(index):
        print(max_1)

    print(max_2)

    for i in range(N - index - 1):
        print(max_1)

Submission status: Accepted

Solution code:
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    a = [0] * n

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

    a_lmax = [0] * n
    a_rmax = [0] * n
    a_lmax[0] = 0
    a_rmax[-1] = 0

    for i in range(1, n):
        a_lmax[i] = max(a_lmax[i-1],a[i-1])
        a_rmax[-1-i] = max(a_rmax[-i], a[-i])

    for i in range(n):
        print(max(a_lmax[i], a_rmax[i]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    s = sorted(list(set(A)))
    mc = A.count(s[-1])

    for a in A:
        if len(s) == 1:
            print(s[-1])
        elif a == s[-1] and mc == 1:
            print(s[-2])
        else:
            print(s[-1])


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

n, *a = map(int, sys.stdin.read().split())

x, y = sorted(list(a))[n-2:n]
for i in a:
    if i == y:
        print(x)
    else:
        print(y)

Submission status: Accepted

Solution code:
import copy

n = int(input())
lst = []
for _ in range(n):
    lst.append(int(input()))
clean_lst = copy.deepcopy(lst)

m1 = max(lst)
lst.remove(m1)
m2 = max(lst)

for i in clean_lst:
    print(m1 if i!=m1 else m2)

Submission status: Accepted

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

sorted_a = sorted(a_ls,reverse = True)
max_a = sorted_a[0]
second_a = sorted_a[1]
max_ind = a_ls.index(max_a)
for i in range(n):
    if not i == max_ind:
        print(max_a)
    else:
        print(second_a)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
m = max(a)
if a.count(m) > 1:
    for i in range(n):
        print(m)
else:
    for i in range(n):
        if a[i] == m:
            b = a.copy()
            b.remove(m)
            print(max(b))
        else:
            print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

desc = sorted(list(set(a)), reverse=True)
max = desc[0]
large_2 = desc[1] if len(desc) > 1 else 0

if a.count(max) == 1:
    for val in a:
        if val == max:
            print(large_2)
        else:
            print(max)
else:
    for _ in range(n):
        print(max)

Submission status: Accepted

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

Submission status: Accepted

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

x = sorted(set(a), reverse = True)
t = [0]*2
if len(x) > 1:
  t[0],t[1] = x[0],x[1]
else:
  t[0],t[1] = x[0],x[0]
  
max = t[0]
count= a.count(max)
for i in range(n):
  if a[i] == max:
    if count > 1:
      print(max)
    else:
      print(t[1])
  else:
    print(max)