Problem:


Score : 300 points

Problem Statement

You are given a sequence of length N: A_1, A_2, ..., A_N.
For each integer i between 1 and N (inclusive), answer the following question:

Find the maximum value among the N-1 elements other than A_i in the sequence.

Constraints

2 \leq N \leq 200000

1 \leq A_i \leq 200000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print N lines. The i-th line (1 \leq i \leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.

Sample Input 1

3
1
4
3

Sample Output 1

4
3
4

The maximum value among the two elements other than A_1, that is, A_2 = 4 and A_3 = 3, is 4.

The maximum value among the two elements other than A_2, that is, A_1 = 1 and A_3 = 3, is 3.

The maximum value among the two elements other than A_3, that is, A_1 = 1 and A_2 = 4, is 4.

Sample Input 2

2
5
5

Sample Output 2

5
5



Sample input:
3
1
4
3


Sample output:
4
3
4

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    sort_A = sorted(A)
    max_A = sort_A[-1]
    max_se_A = sort_A[-2]
    for a in A:
        if a == max_A:
            print(max_se_A)
        else:
            print(max_A)
    return 0

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
length = int(input())
suretsu=[int(input()) for i in range(length)]
result = []
sorted_suretsu = sorted(suretsu,reverse=True)
zantei_max = sorted_suretsu[0]

for i in range(length):
    if (zantei_max == suretsu[i]):
        result.append(str(sorted_suretsu[1]))
    else:
        result.append(str(zantei_max))
print('\n'.join(result))

Submission status: Accepted

Solution code:
N = int(input())
list = [int(input()) for i in range(N)]
list_max = sorted(list)
max = max(list)
for i in range(N):
	if(list[i] == max):
		print(list_max[-2])
	else:
		print(max)

Submission status: Accepted

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

b=sorted(a)
for i in range(n):
    if a[i]==b[n-1]:
        ama=i

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

Submission status: Accepted

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

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

Submission status: Accepted

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

sorted_a = sorted(a)

mx = sorted_a[-1]
next = sorted_a[-2]

for _a in a:
    if _a == mx:
        print(next)
    else:
        print(mx)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
largest = 0
second_largest = 0
for i in range(n):
    temp = int(input())
    if temp > largest:
        largest = temp
    elif largest >= temp > second_largest:
        second_largest = temp
    a.append(temp)

for i in range(n):
    if a[i] == largest:
        print(second_largest)
    else:
        print(largest)

Submission status: Accepted

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

sorted_a = list(sorted(a,reverse=True))

ans_a = []

for i in a:
    if i == sorted_a[0]:
        ans_a.append(sorted_a[1])
    
    else:
        ans_a.append(sorted_a[0])

for i in ans_a:
    print(i)

Submission status: Accepted

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

N = int(input())
A = []
max1 = 0
max2 = 0

for _ in range(N):
    a = int(input())
    # if max1 <= a:
    #     max2 = max1
    #     max1 = a
    # elif max2 <= a:
    #     max2 = a
    A.append(a)

# for a in A:
#     print(max1 if a != max1 else max2)


# でも制約からこんなバグりやすいプログラム書かなくても
A_sorted = sorted(A)
max1 = A_sorted[-1]
max2 = A_sorted[-2]
for a in A:
    print(max1 if a != max1 else max2)

Submission status: Accepted

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

N = int(input())
A = []
max1 = 0
max2 = 0

for _ in range(N):
    a = int(input())
    if max1 <= a:
        max2 = max1
        max1 = a
    elif max2 <= a:
        max2 = a
    A.append(a)

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
a = [int(input()) for i in range(n)]
b=sorted(a)
x=b[-1]
y=b[-2]
for i in range(n):
  if a[i]<x:
    print(x)
  else:
    print(y)

Submission status: Accepted

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

def main():
    n = int(input())
    a = tuple(map(int, [input() for _ in range(n)]))
    max_a, max_a2 = sorted(a, reverse=True)[:2]
    print('\n'.join(map(str, [max_a if i != max_a else max_a2 for i in a])))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    max_a, max_a2 = sorted(a, reverse=True)[:2]
    print('\n'.join(map(str, [max_a if i != max_a else max_a2 for i in a])))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    max_a2, max_a = sorted(a)[-2:]
    print('\n'.join(map(str, [max_a if i != max_a else max_a2 for i in a])))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    max_a2, max_a = sorted(a)[-2:]
    print('\n'.join([str(max_a) if i != max_a else str(max_a2) for i in a]))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    max_a = max(a)

    if a.count(max_a) > 1:
        print('\n'.join([str(max_a) for _ in a]))
    else:
        max_a2 = sorted(a)[-2]
        print('\n'.join([str(max_a) if i != max_a else str(max_a2) for i in a]))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
A_sorted = sorted(A)
for i in range(N):
    if A[i] != A_sorted[-1]:
        print(A_sorted[-1])
    else:
        j = len(A_sorted) - 1
        count = 0
        while A[i] == A_sorted[j] and count <= 0:
            j -= 1
            count += 1
        print(A_sorted[j])

Submission status: Accepted

Solution code:
n=int(input())
l=[]
mx=-1
s=1
for _ in range(n):
    x=int(input())
    l.append(x)
    if x==mx:
        s+=1
    elif x>mx:
        mx=x
        s=1
if s>1:
    for _ in range(n):
        print(mx)
else:
    j=l.index(mx)
    for i in range(n):
        if i!=j:
            print(mx)
        else:
            l.remove(mx)
            print(max(l))

Submission status: Accepted

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

max_number = max(a)
max_number2 = sorted(a)[-2]

for i in range(n):
    if a[i] == max_number:
        print(max_number2)
    else:
        print(max_number)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A,reverse=True)
m = B[0]
n = B[1]
ind = A.index(m)
if m != n:
    ans = "\n".join([str(m) if i != ind else str(n) for i in range(N) ])
else:
    ans = "\n".join([str(m)for _ in range(N)])
print(ans)

Submission status: Accepted

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

s = sorted(a)

max1 = s[-1]
max1_ind = a.index(max1)
max2 = s[-2]

# print(max1, max2)

for i in a:
    if i is a[max1_ind]:
        print(max2)
    else:
        print(max1)

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    B = sorted(A)
    max_A = B[-1]
    submax_A = B[-2]
    for i in range(N):
        if A[i] == max_A:
            print(submax_A)
        else:
            print(max_A)
    return


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:
n,*a=map(int,open(0).read().split())

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

Submission status: Accepted

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

aa = sorted(a)
first = aa[-1]
second = aa[-2]

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    maxA = -1
    max2A = -1
    max_i = -1
    for i in range(N):
        a = I()
        if a > maxA:
            max2A = maxA
            maxA = a
            max_i = i
        else:
            max2A = max(max2A, a)
    for i in range(N):
        if i != max_i:
            print(maxA)
        else:
            print(max2A)

main()

Submission status: Accepted

Solution code:
#ABC134_C

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

Amax=max(A)
indmax=[i for i,v in enumerate(A) if v==Amax]

if len(indmax)>1:
    for _ in range(N):
        print(Amax)
else:
    Amax2=sorted(A)[-2]
    for i in range(N):
        if i!=indmax[0]:
            print(Amax)
        else:
            print(Amax2)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=[0]*N
for i in range(N):
    A[i]=int(input())
m=sorted(A)[N-1]
m_=A.index(m)
m2=sorted(A)[N-2]
m2_=A.index(m2)
for i in range(N):
    if i!=m_:
        print(m)
    else:
        print(m2)

Submission status: Accepted

Solution code:
import sys
a = int(input())
a_list = []
for i in range(a):
    a_list.append(int(input()))
max_num = max(a_list)
if a_list.count(max_num) != 1:
    for i in range(a):
        print(max_num)
else:
    sec_num = sorted(a_list)[-2]
    for i in a_list:
        if i == max_num:
            print(sec_num)
        else:
            print(max_num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# import re
# import array
# import copy
# import functools
# import operator

# import collections
# import itertools
# import bisect
# import heapq


# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace

# from queue import PriorityQueue as pq

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )
# # from itertools import accumulate
# # from collections import deque

# from operator import mul
# from functools import reduce

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random

def main():
    # n, *l = map(int, open(0).read().strip().split())
    # n = int(input().strip())
    # a = list(map(int, input().strip().split()))
    n = int(input().strip())
    max0=0;max1=0;i0=sys.maxsize;i1=sys.maxsize               # assure that max1<=max0
    for i in range(n):
        n_temp=int(input())
        if n_temp >= max0 :
            max1=max0;i1=i0 
            max0=n_temp;i0=i
        elif max0>n_temp and n_temp>max1:
            max1=n_temp;i1=i
        else: #  n_tem@ <= max1
            pass
    for i in range(n):
        if i==i0:
            print(max1)
        else:
            print(max0)
    return

if __name__ == '__main__':
    main()

    '''
    


    '''

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
B=sorted(A)[::-1]
x=B[0] 
y=B[1]
if x==y:
  for i in range(N):
    print(x)
else:
  z=A.index(x)
  for i in range(z):
    print(x)
  print(y)
  for i in range(N-z-1):
    print(x)

Submission status: Accepted

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

Submission status: Accepted

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

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

maxa = max(a)
maxcnt = 0
maxidx = 0

for i in range(n):
    if maxcnt == 0:
        maxidx = i
    if a[i] == maxa:
        maxcnt += 1
    


for i in range(n):
    if maxcnt == 1 and i == maxidx:
        a[maxidx]=0
        print(max(a))
    else:
        print(maxa)

Submission status: Accepted

Solution code:
#ABC-134-C
N = int(input())
A = {}
for i in range(N):
    A[i] = int(input())

value_sorted = sorted(A.items(), key=lambda x:x[1])
max_value = 0

for i in range(N):
    max_value_tapple = value_sorted[-1]
    if max_value_tapple[0] == i:
        max_value_tapple = value_sorted[-2]
        max_value = max_value_tapple[1]
    else:
        max_value = max_value_tapple[1]
    print(max_value)

Submission status: Accepted

Solution code:
import numpy as np
import copy
def main():
    n = int(input())
    
    max_num = 0
    max_second = 0
    for i in range(n):
        a = int(input())
        if a > max_num:
            max_num = a
            max_index = i
        elif a > max_second:
            max_second = a

    for j in range(n):
        if j == max_index:
            print(max_second)
        else:
            print(max_num)



    
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def mainFunc():
    N = int(input())
    ai = [0 for i in range(N)]
    m1, m2 = 0, 0
    for i in range(N):
        ai[i] = int(input())
        if m1 <= ai[i]:
            m2 = m1
            m1 = ai[i]
        elif m2 <= ai[i]:
            m2 = ai[i]

    ans = ""
    for i in range(N):
        ans += str(m1) if ai[i] < m1 else str(m2)
        ans += "\n"
    
    print(ans)
mainFunc()

Submission status: Accepted

Solution code:
# 23:59
import copy
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_sort = copy.deepcopy(a)
a_sort.sort()
max = a_sort[n-1]
max_next = a_sort[n-2]
for i in range(n):
    if a[i] == max:
        print(max_next)
    else:
        print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
N = int(input())
A = [int(input()) for _ in range(N)]
print(*list(map(max, [0]+list(accumulate(A, max))[:-1],
                list(accumulate(A[::-1], max))[::-1][1:]+[0])), sep="\n")

Submission status: Accepted

Solution code:
n = int(input())
l = [int(input()) for _ in [0]*n]
#最大値が2つある場合に注意しないといけない。
#最大値が2つ以上ある場合を先に処理
import sys
if l.count(max(l))>1:
  m1 = max(l)
  for i in range(n):
    print(m1)
#O(n)の処理なら何回やってもいいくらいの気持ちでいく
else:
  s=set(l)
  m1 = max(s)
  s.remove(max(s))
  m2 = max(s)
  for i in l:
    if i == m1:
      print(m2)
    else:
      print(m1)

Submission status: Accepted

Solution code:
def calculate(arr):

    largest,second = findLargetAndSecond(arr)

    for i in range(len(arr)):
        value = arr[i]
        if largest != value:
            print(largest)
        else:
            print(second)


def findLargetAndSecond(arr):
    largest = 0
    second = 0

    for i in range(0,len(arr)):
        if arr[i] > largest:
            second = largest
            largest = arr[i]
        else:
            if arr[i] >= second:
                second = arr[i]

    return largest,second



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

calculate(arr)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
a_copy=a[:]
first=max(a)
a_copy.remove(first)
second=max(a_copy)

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

Submission status: Accepted

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

Submission status: Accepted

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

highmax = 0
maxs=0
for i in range(n):
    if highmax < a[i]:
        highmax = a[i]
        maxs = i

for i in range(n):
    max = 0
    if maxs != i:
        print(a[maxs])
    else:
        for j in range(n):
            if i != j:
                if max < a[j]:
                    max = a[j]
        print(max)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    B = sorted(A)
    m = B[-1]
    mm = B[-2]

    if m == mm:
        for _ in range(N):
            print(m)

    else:
        for a in A:
            if a != m:
                print(m)
            else:
                print(mm)


main()

Submission status: Accepted

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

for i in range(N):
    B[i][0] = A[i]
    B[i][1] = i

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

Submission status: Accepted

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

x=max(A)
count=(A.count(x))
index=[]
if count!=1:
    for i in range(N):
        print(x)
else:
    B=copy.copy(A)
    B.remove(x)
    y=max(B)
    for i in range(N):
        if A[i]==x:
            print(y)
        else:
            print(x)

Submission status: Accepted

Solution code:
N=int(input())
A=[]
max1=0
max2=0
for i in range(N):
	A.append(int(input()))
	
max1=max(A)
cnt=0
for i in range(N):
	if max1 is A[i]:
		cnt += 1
	elif max2 < A[i]:
		max2 = A[i]	
		
for i in range(N):
	if cnt >= 2:
		print(max1)
	else:	
		if max1 == A[i]:
			print(max2)
		else:
			print(max1)

Submission status: Accepted

Solution code:
N = int(input())

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

M = max(A)
I = A.index(M)
del A[I]

K = max(A)

for i in range(N):
    if i == I:
        print(K)
    else:
        print(M)

Submission status: Accepted

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

F, S = sorted(A, reverse=True)[:2] # First, Second

for i in A:
    if i == F:
        print(S)
    else:
        print(F)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for _ in range(n):
    A = int(input())
    a.append(A)
    
s = sorted(a)
for i in range(n):
    if a[i] == s[-1]:
        print(s[-2])
    else:
        print(s[-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 = A.index(maxA)
A.sort()

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_list = [int(input()) for _ in range(n)]
    a_sorted = sorted(a_list)
    a_first = a_sorted[-1]
    a_second = a_sorted[-2]
    a_count = a_list.count(a_first)

    if a_count >= 2:
        for a in a_list:
            print(a_first)
    else:
        for a in a_list:
            if a == a_first:
                print(a_second)
            else:
                print(a_first)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_list = [int(input()) for _ in range(n)]
    a_sorted = sorted(a_list)
    a_first = a_sorted[-1]
    a_second = a_sorted[-2]

    for a in a_list:
        if a == a_first:
            print(a_second)
        else:
            print(a_first)


if __name__ == '__main__':
    main()

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 = [int(input()) for i in range(N)]
Amax = max(A)
cnt = A.count(Amax)
if cnt >= 2:
    for i in range(N):
        print(Amax)
else:
    A[A.index(Amax)] = 0
    b = max(A)
    for a in A:
        if a == 0:
            print(b)
        else:
            print(Amax)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input()) for _ in range(N)]
MAX1=max(A)
for n in range(N):
    if MAX1==A[n]:
        A[n]=0
        break
MAX2=max(A)
A[n]=MAX1
for a in A:
    if MAX1==a:
        print(MAX2)
    else:
        print(MAX1)

Submission status: Accepted

Solution code:
n = int(input())
a_lis = []
for i in range(n):
    a_lis.append(int(input()))
a_s = sorted(a_lis)
max_a = a_s[-1]
n_max_a = a_s[-2]
for i in range(n):
    if a_lis[i] == max_a:
        print(n_max_a)
    else:
        print(max_a)

Submission status: Accepted

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

max_number = a_sort[-1]
sub_max_number = a_sort[-2]

for i in range(n):
  if a[i] == max_number:
    print(sub_max_number)
  else:
    print(max_number)

Submission status: Accepted

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

one_ind = A.index(max(A))
one_max = max(A)
del A[one_ind]
sec_ind = A.index(max(A))
sec_max = max(A)

for i in range(N):
    if i != one_ind:
        print(one_max)
    else:
        print(sec_max)

Submission status: Accepted

Solution code:
n=int(input())
L=[int(input()) for i in range(n)]
#print(L)
sorted_L=sorted(L)
#print(sorted_L)

a=sorted_L[-1]
b=sorted_L[-2]

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

Submission status: Accepted

Solution code:
def exception_handling(N: int, A: list)->list:
    sorted_A = sorted(A)
    return [sorted_A[-1] if a != sorted_A[-1] else sorted_A[-2] for a in A]


if __name__ == "__main__":
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = exception_handling(N, A)
    for a in ans:
        print(a)

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append([i, int(input())])
a.sort(key=lambda x: x[1])
ans = [0 for _ in range(n)]
for i in range(n):
    index = a[i][0]
    ans[index] = a[-2][1] if i == (n-1) else a[-1][1]
for a in ans:
    print(a)

Submission status: Accepted

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

max_num = max(A)
A_bk = A[:]
if (A.count(max_num)>=2):
    for i in range(N):
        print(max_num)
else:
    for i in range(N):
        if (A[i] != max_num):
            print(max_num)
        else:
            A_bk.remove(max_num)
            print(max(A_bk))

Submission status: Accepted

Solution code:
import copy
N = int(input())
A = [int(input()) for i in range(N)]
B = A.copy()
B.sort()
M,m = B[-1],B[-2]
for a in A:
    print(M if a != M else m)

Submission status: Accepted

Solution code:
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
p=s[-1]
q=s[-2]
for i in range(n):
  if l[i]==p:
    print(q)
  else:
    print(p)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
b=sorted(a)
m1=b[-1]
m2=b[-2]

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

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = [INT() for _ in range(N)]

B = sorted(A,reverse = True)
max_a = B[0]
second_a = B[1]

for a in A:
	if a != max_a: print(max_a)
	else: print(second_a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def main():
    N = int(sys.stdin.readline())
    A = [int(sys.stdin.readline()) for i in range(N)]
    maxa = max(A)
    if A.count(maxa) > 1:
        for i in range(N):
            print(maxa)
    else:
        for i in range(N):
            if A[i] != maxa:
                print(maxa)
            else:
                print(sorted(A)[-2])
                
main()

Submission status: Accepted

Solution code:
import sys
def main():
    N = int(sys.stdin.readline())
    A = [int(sys.stdin.readline()) for i in range(N)]
    maxa = max(A)
    maxb = sorted(A)[-2]
    if A.count(maxa) > 1:
        for i in range(N):
            print(maxa)
    else:
        for i in range(N):
            if A[i] != maxa:
                print(maxa)
            else:
                print(maxb)
                
main()

Submission status: Accepted

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

t = sorted(a, reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque

num = int(input())

arr = []

for i in range(num):
    arr.append(int(input()))

arr0 = sorted(arr,reverse=True)
arr00 = arr0[0]
arr01 = arr0[1]

for i in range(num):
    if arr[i] != arr00:
        print(arr00)
    else:
        print(arr01)

Submission status: Accepted

Solution code:
n = int(input())
#a = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(int(input()))

b=sorted(a,reverse=True)
max_a=b[0]
max_a2=b[1]

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

Submission status: Accepted

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

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

# こいつはn **16 = 10**8**16
#3
#[1,4,3]
#[4,3,1]

Submission status: Accepted

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

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

max_A = max(A)
max_c = A.count(max_A)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy

N = int(input())

a_list = []
for n in range(N):
    a_list.append(int(input()))

a_list_copy = copy.copy(a_list)
maximum_list = []
for i in range(2):
    maximum_list.append(max(a_list_copy))
    a_list_copy.remove(max(a_list_copy))

if maximum_list[0] == maximum_list[1]:
    for a in a_list:
        print(maximum_list[0])
else:
    for a in a_list:
        if a == maximum_list[0]:
            print(maximum_list[1])
        else:
            print(maximum_list[0])

Submission status: Accepted

Solution code:
N=int(input())
L=[]
s,e,s1,e1,t=0,0,0,0,0
for i in range(N):
  L.append(int(input()))
s=L.index(max(L))
e=L[s]
L[s]=0
s1=L.index(max(L))
e1=L[s1]
for i in range(N):
  if i!=s:
    print(e)
  else:
    print(e1)

Submission status: Accepted

Solution code:
import copy

n = int(input())
a = [int(input()) for i in range(n)]
b = copy.deepcopy(a)
b.sort(reverse=True)
c = b[0]
d = b[1]

for i in range(n):
    if a[i] == c:
        print(d)
    else:
        print(c)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(input()) for _ in range(n)]
semi_max_num, max_num = sorted(A)[-2:]
for a in A:
    if a != max_num:
        print(max_num)
    else:
        print(semi_max_num)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
a_max = max(a)
max_c = a.count(a_max)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
sorted_a = []
for item in a:
    sorted_a.append(item)
sorted_a.sort(reverse=True)
for num in a:
    if num == sorted_a[0]:
        print(sorted_a[1])
    else:
        print(sorted_a[0])