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:
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

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

B = sorted(A)
B.reverse()
m1 = B[0]
m2 = B[1]

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
a = []
for line in sys.stdin.readlines():
  a.append(int(line.strip()))

s = sorted(a, reverse=True)
m0 = s[0]
m1 = s[1]

for aa in a:
  if aa == m0:
    print(m1)
  else:
    print(m0)

Submission status: Accepted

Solution code:
N = int(input())

M1, M2 = 0, 0
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    if a > M1:
        M2 = M1
        M1 = a
    elif a > M2:
        M2 = a

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

Submission status: Accepted

Solution code:
N = int(input())
para = []
com = [] 
for i in range(N):
    a = int(input())
    para.append(a)
    com.append(a)
com.sort(reverse= True)
for i in range(N):
    if para[i] == com[0]:
        print(com[1])
    else:
        print(com[0])

Submission status: Accepted

Solution code:
N = int(input())
A = []
m1 = 0
m2 = 0
for i in range(N):
  a = int(input())
  if m1<=a:
    m2 = m1
    m1 = a
  elif m2<=a:
    m2 = a
  A += [a]
for a in A:
  if a == m1:
    print(m2)
  else:
    print(m1)

Submission status: Accepted

Solution code:
import copy
def calcmax(a,b,fst,scd,n):
    for i in xrange(n):
        if fst == a[i]:
            count = i

    for i in xrange(n):
        if count == i:
            print scd
        else:
            print fst

if __name__ == '__main__':
    n = int(raw_input())
    a = [int(raw_input()) for i in xrange(n)]
    print("")

    fst = max(a)

    b = copy.deepcopy(a)
    b.remove(fst)

    scd = max(b)

    calcmax(a,b,fst,scd,n)

Submission status: Accepted

Solution code:
N = int(input())

nums = [int(input()) for i in range(N)]
first = sorted(nums)[-1]
second = sorted(nums)[-2]

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

Submission status: Accepted

Solution code:
n = int(input())
num = [ int(input()) for _ in range(n) ]
B = sorted(num,reverse=True)
maxnum = B[0]
maxnum2 = B[1]

for i in range(n):
    if num[i] != maxnum:
        print(maxnum)
    else:
        print(maxnum2)

Submission status: Accepted

Solution code:
n = int(input())
num = [ int(input()) for _ in range(n) ]
B = sorted(num,reverse=True)
maxnum = B[0]
maxnum2 = B[1]

for i in range(n):
    if num[i] != maxnum:
        print(maxnum)
    else:
        print(maxnum2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
	n = int(input().strip())
	a = [0] * n
	for i in range(n):
		a[i] = int(input().strip())
	l = [0] *(n+1)
	r = [0] *(n+1)
	for i in range(0, n):
		l[i+1] = max(l[i], a[i])
	for i in reversed(range(1, n)):
		r[i-1] = max(r[i], a[i])
	for i in range(n):
		print(max(l[i], r[i]))

if __name__ == '__main__':
	main()

Submission status: Accepted

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

def main():
	n = int(input().strip())
	a = [0] * n
	for i in range(n):
		a[i] = int(input().strip())
	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)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
b = [i for i in a]
b.sort()
b.reverse()
b = b[:2]
for i in range(n):
  if a[i] != b[0]:
    print(b[0])
  else:
    print(b[1])

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = [int(input()) for _ in range(n)]
t1 = max(a)
t1_idx = [i for i, v in enumerate(a) if v == t1]
a.sort()

if len(t1_idx) < 2:
    try:
        t2 = a[-1*len(t1_idx)-1]
    except:
        for i in range(n):
            print(t1)

    for i in range(n):
        if i in t1_idx:
            print(t2)
        else:
            print(t1)
else:
    for i in range(n):
        print(t1)

Submission status: Accepted

Solution code:
# 最大値と二番目に大きいやつをとっておく。最大値のときだけ二番目に大きいやつ採用
n = int(input())
arr = []
for i in range(n):
  t = int(input()) 
  arr.append([i, t])

sorted_arr = list(sorted(arr, key = lambda x : x[1]))
biggest = sorted_arr[-1]
second_biggest = sorted_arr[-2]

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

Submission status: Accepted

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

sorted_data = sorted(A)[::-1]
for a in A:
    if a == sorted_data[0]:
        print(sorted_data[1])
    else:
        print(sorted_data[0])

Submission status: Accepted

Solution code:
n = int(input())
values = [int(input()) for i in range(n)]
all_max = max(values)
count = 0

max_count = 0
is_include_two_max = False
for val in values:
    if val == all_max:
        max_count += 1
    if max_count == 2:
        is_include_two_max = True
        break

if is_include_two_max:
    print('\n'.join([str(all_max) for i in range(n)]))
else:
    for i, val in enumerate(values):
        if val != all_max:
            print(all_max)
        else:
            print(max(values[0:i] + values[i+1:]))

Submission status: Accepted

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

main()

Submission status: Accepted

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

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

for i in li:
    if i > a:
        b = a
        a = i
    elif i > b:
        b = i

for i in li:
    if i == a:
        print(b)
    else:
        print(a)

Submission status: Accepted

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

for i in li:
    if i > a:
        b = a
        a = i
    elif i > b:
        b = i

for i in li:
    if i == a:
        print(b)
    else:
        print(a)

Submission status: Accepted

Solution code:
from copy import copy


def main():
    N = int(input())
    A_list = [int(input()) for _ in range(N)]
    tmp_list = copy(A_list)
    tmp_list.sort()
    max_num = tmp_list[-1]
    second_max_num = tmp_list[-2]
    max_index = A_list.index(max_num)
    for i in range(N):
        if i is max_index:
            print(second_max_num)
            continue
        print(max_num)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

tmp = A.copy();
tmp.sort()
max1_A = tmp[-1];
max2_A = tmp[-2];
max_count = A.count(max1_A);

# 最大値が複数ある場合
if max_count > 1:
  for i in range(N):
    print(max1_A)
# 最大値が1つある場合
else:
  for i in range(N):
    if A[i] < max1_A:
      print(max1_A)
    else:
      print(max2_A)
      break
  for j in range(i+1,N):
    print(max1_A)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0))
m=max(a)

if a.count(m)>1:
    for i in range(n):
        print(m)
else:
    s=sorted(set(a))[::-1][1]
    for i in a:
        if i==m:
            print(s)
        else:
            print(m)

Submission status: Accepted

Solution code:
import copy

n = int(input().split()[0])
a_list = []

for _ in range(n):
    a_list.append(int(input().split()[0]))

kouho_list = sorted(a_list)
max_n = max(kouho_list)
second_max_n = kouho_list[-2]

max_list = [str(max_n) if x != max_n else str(second_max_n) for x in a_list]
max_str = '\n'.join(max_list)

print(max_str)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
a_max=max(a)
x=a.index(a_max)
a_sort=sorted(a)
y=a_sort[-2]
for i in range(n):
  if i==x:
    print(y)
  else:
    print(a_max)

Submission status: Accepted

Solution code:
#C問題
N = int(input())
A = []
f = 0
s = 0
for i in range(N):
    a = int(input())
    if a >= f:
        s = f
        f = a
    elif a >= s:
        s = a
    A.append(a)

for i in range(N):
    if A[i] == f:
        print(s)
    else:
        print(f)

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    xs = [int(stdin.readline().rstrip()) for _ in range(n)]

    max_1 = max(xs)
    key_max = xs.index(max_1)
    
    for i in range(n):
        if key_max == i:
            print(max(xs[:i]+xs[i+1:]))
        else:
          	print(max_1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    xs = [int(stdin.readline().rstrip()) for _ in range(n)]

    max_1 = max(xs)
    key_max = xs.index(max_1)

    for i in range(n):
        if key_max == i:
            print(max(xs[0:i]+xs[i+1:]))
        else:
          	print(max_1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    xs = [int(stdin.readline().rstrip()) for _ in range(n)]

    max_1 = max(xs)
    key_max = xs.index(max_1)

    for i in range(n):
        if key_max != i:
            print(max_1)
        elif i == 0:
            print(max(xs[i+1:]))
        elif i == n-1:
            print(max(xs[0:i]))
        else:
            print(max(max(xs[0:i]),max(xs[i+1:])))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    xs = [int(stdin.readline().rstrip()) for _ in range(n)]

    max_1, max_2 = sorted(xs)[-1], sorted(xs)[-2]

    for i in range(n):
        if xs[i] == max_1:
            print(max_2)
        else:
            print(max_1)
            
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
maxvalue = max(a)
maxindex = a.index(max(a))
for i in range(n):
    if i != maxindex:
        print(maxvalue)
    else:
        a_tmp = a[:]
        a_tmp.pop(maxindex) 
        print(max(a_tmp))

Submission status: Accepted

Solution code:
N = int(input())
m1 = -1
m2 = -1
As = []
for i in range(N):
    n = int(input())
    As.append(n)
    if n > m1:
        m2 = m1
        m1 = n
    else:
        if n > m2:
            m2 = n

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

Submission status: Accepted

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

lmax = [0]
rmax = [0]

for i in range(N-1):
    lmax.append(max(lmax[i], a[i]))
    rmax.append(max(rmax[i], a[-(i+1)]))

for i in range(N):
    print(max(lmax[i], rmax[-(i+1)]))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

M = max(d)
D = d[:]
d.remove(M)
m = max(d)

for j in range(N):
    if D[j]==M:
        print(m)
    else:
        print(M)

Submission status: Accepted

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

B = sorted([(x, i) for i, x in enumerate(A)], reverse=True)

m0, mi = B[0]
m1, _ = B[1]


for i in range(N):
    if i != mi:
        print(m0)
    else:
        print(m1)

Submission status: Accepted

Solution code:
N = int(input())
A_list = [int(input()) for x in range(N)]

sorted_list = sorted(A_list, reverse = True)
max_1st = sorted_list[0]
max_2nd = sorted_list[1]

for num in A_list:
    if num != max_1st:
        print(max_1st)
    else:
        print(max_2nd)

Submission status: Accepted

Solution code:
N = int(input()) 
s = [int(input()) for i in range(N)] #複数行の数値の入力を取得

x1 = sorted(s)[-1]
x2 = sorted(s)[-2]

if ( x1 == x2 ) :
    for val in s:
        print ( x1 )
else :
    for val in s:
        if ( val == x1 ):
            print ( x2 )
        else:
            print ( x1 )

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
LM=[0,A[0]]
a=A[::-1]
RM=[a[0]]
for i in range(1,N-1):
    LM.append(max(LM[-1],A[i]))
    RM.append(max(RM[-1],a[i]))
RM=RM[::-1]+[0]
for i in range(N):
    print(max(LM[i],RM[i]))

Submission status: Accepted

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

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

L = sorted(A)
mx1 = L[N-1]
mx2 = L[N-2]

for i in range(N):
    if A[i] == mx1:
        print(mx2)
    else:
        print(mx1)

Submission status: Accepted

Solution code:
N = int(input())
first, second, num = 0, 0, 0
l = []
for i in range(N):
	n = int(input())
	if n > first:
		first, second, num = n, first, i
	elif n > second:
		second = n
for i in range(N):
	if i == num:
		print(second)
	else:
		print(first)

Submission status: Accepted

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

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

mx = max(A)
mxi = A.index(max(A))

for i in range(N):
    if i != mxi:
        print(mx)
    elif i == 0:
        print(max(A[1:N]))
    elif i == N-1:
        print(max(A[0:N-1]))
    else:
        print(max(max(A[0:i]),max(A[i+1:N])))

Submission status: Accepted

Solution code:
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
Mod = 1000000007



def main(): #startline-------------------------------------------
    N = int(input())
    A = [int(input()) for i in range(N)]
    p = -float("inf")
    keepnumber = 0
    for i in range(N):
        if p <= A[i]:
            p = A[i]
            keepnumber = i
    for i in range(N):
        if i == keepnumber:
            print(max(A[:i]+A[i+1:]) if i != N else print(max(A[:N-1])))
        else:
            print(p)       
if __name__ == "__main__":
    main() #endline===============================================




def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys
minint = -sys.maxint - 1
maxint = sys.maxint

n = int(raw_input())
a = []
m = [0]*2
mx, mx2, ind, ind2 = minint, minint, 0, 0
for i in range(n):
  v = int(raw_input())
  if v > mx:
    mx, ind = v, i
  elif v > mx2:
    mx2, ind2 = v, i
  a += [v]
for i in range(n):
  if i == ind:
    print(mx2)
  else:
    print(mx)

Submission status: Accepted

Solution code:
import copy
N=int(input())
l=[]
for i in range(N):
  l.append(int(input()))
M=max(l)
L=copy.copy(l)
l.remove(M)
m=max(l)
for j in range(N):
  if L[j]==M:
    print(m)
  else:
    print(M)

Submission status: Accepted

Solution code:
import copy

def main():

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

    srtdA = copy.copy(A)
    srtdA.sort(reverse=True)
    atmax = srtdA[0]
    atsecond = srtdA[1]


    for  a in A:
        if a==atmax:
            print(atsecond)
        else:
            print(atmax)

if __name__== "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
an = []
for _ in range(n):
  an.append(int(input()))
maxl = [an[0]]
maxr = [an[-1]]
for a in an[1:]:
  maxl.append(max(maxl[-1], a))
for a in an[:-1][::-1]:
  maxr.append(max(maxr[-1], a))
maxr = maxr[::-1]

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

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)
max = B[0]
second = B[1]
for i in range(N):
    if(max == second):
        print(max)
    else:
        if(A[i] == max):
            print(second)
        else:
            print(max)

Submission status: Accepted

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

# d_arr = [5,5]
# N = len(d_arr)
d_max = max(d_arr)
d_ind = d_arr.index(d_max)

for i in range(N):
    if i == d_ind:
        d_arr.pop(d_ind)
        print(max(d_arr))
    else:
        print(d_max)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

n = int(input())
l = []
m1 = 0
m2 = 0
for i in range(n):
    num = int(input())
    l.append(num)
    if num > m1:
        m1 = num
    elif num > m2:
        m2 = num

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

Submission status: Accepted

Solution code:
n = int(input())
l = []
m1 = 0
m2 = 0
for i in range(n):
    num = int(input())
    l.append(num)
    if num > m1:
        m1 = num
    elif num > m2:
        m2 = num

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

Submission status: Accepted

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


r=0
count=0
for i in range(N):
    A[i]=int(input())
    if A[i]>r:
     r=A[i]
     count=i

for i in range(N):
    if i==count:
     del A[i]
     print(max(A))
    else:
     print(r)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
m1=0
m2=0
for i in range(n):
    if a[i]>m1:
        m2=m1
        m1=a[i]
    elif m1>=a[i] and m2<a[i]:
        m2=a[i]
for i in range(n):
    if a[i]!=m1:
        print(m1)
    else:
        print(m2)

Submission status: Accepted

Solution code:
import copy
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
ma =max(a)
cn =0
for i in range(n):
  if a[i]==ma and cn<2:
    b=copy.deepcopy(a)
    b[i]=0
    print(max(b))
    cn +=1
  else:
    print(ma)

Submission status: Accepted

Solution code:
import sys
import math

if sys.platform =='ios':
  sys.stdin=open('input134c.txt')

#+++++

n = int(input())
a = []
max=0
max2=0
for i in range(n):
	ai = int(input())
	a.append(ai)
	if max < ai:
		max2 = max
		max = ai
	elif max2 < ai:
		max2 = ai			

#n, d = map(int, input().split())

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

Submission status: Accepted

Solution code:
N=int(input())
L=[]
for _ in range(N):
  L.append(int(input()))
sL=sorted(L)
sL.reverse()
m=max(L)
m2=sL[1]

for i in range(N):
  if L[i]==m:
    print(m2)
  else:
    print(m)

Submission status: Accepted

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

def solve(N: int, A: "List[int]"):
    maxA = 0
    maxInd = 0
    for i in range(N):
        if A[i] > maxA:
            maxA = A[i]
            maxInd = i
    A[maxInd] = 0
    subMaxA = max(A)
    for i in range(N):
        if i == maxInd:
            A[i] = subMaxA
        else:
            A[i] = maxA
    print('\n'.join(map(str, 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 = int(input())

f = 0
s = 0
index = 0
for i in range(N):
  a = int(input())
  if a > f:
    index = i
    s = f
    f = a
  elif a > s:
    s = a

for i in range(N):
  if i == index:
    print(s)
  else:
    print(f)

Submission status: Accepted

Solution code:
# import sys
# input = sys.stdin.readline
# n = int(input())
# a = [int(input()) for _ in range(n)]
#
# max_i = 0
# max_num = 0
# for i in range(n):
#     if a[i] > max_num:
#         max_num = a[i]
#         max_i = i
#
# a.sort(reverse=True)
#
# for i in range(n):
#     if i != max_i:
#         print(max_num)
#     else:
#         print(a[1])

n,*a=map(int,open(0).read().split())
ma=max(a)
# 最大値のインデックスを取得
ma_index=a.index(ma)
for i in range(n):
    if i==ma_index:
        # 最大値を除いた配列の最大値を出力
        print(max(a[:i]+a[i+1:]))
    else:
        print(ma)

Submission status: Accepted

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

max_i = 0
max_num = 0
sec_num = 0
for i in range(n):
    if a[i] > max_num:
        max_num = a[i]
        max_i = i

a.sort(reverse=True)

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

Submission status: Accepted

Solution code:
n = int(input())
fa = 0
sa = 0
fi = 0
si = 0
for i in range(n):
    a = int(input())
    if a > fa:
        sa, si = fa, fi
        fa = a
        fi = i
    elif a > sa:
        sa = a
        si = i

for i in range(n):
    if i != fi:
        print(fa)
    else:
        print(sa)

Submission status: Accepted

Solution code:
N = int(input())
A_s = [int(input()) for _ in range(N)]
max_a = max(A_s)
is_double_max = False
for i in range(N):
  if A_s[i] != max_a or is_double_max:
      print(max_a)
  else:
      A_s.pop(i)
      if max(A_s) == max_a:
          is_double_max = True
      print(max(A_s))
      A_s.insert(i,max_a)

Submission status: Accepted

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

sA = sorted(A)
x, y = sA[-1], sA[-2]

ix = A.index(x)
for i in range(N):
    if i == ix:
        print(y)
    else:
        print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    a_max = max(a)
    ind_M = a.index(a_max)
    tmpl = a
    tmpl.pop(ind_M)
    for i in range(n):
        if i != ind_M:
            print(a_max)
        else:
            print(max(tmpl))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

A = []

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

maxa = max(A)

copy = A[:]

copy.remove(maxa)

maxa2 = max(copy)

for i in A:
    if i == maxa:
        print(maxa2)
    else:
        print(maxa)

Submission status: Accepted

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

L_max=max(L)

L_max_count=0
for l in L:
    if l==L_max:
        L_max_count+=1
    if L_max_count > 1:
        break

for i in range(N):
    now=L[i]
    
    if L_max_count > 1:
        ans=L_max
    
    elif now!=L_max:
        ans=L_max
        
    else:
        L_temp=L.copy()
        L_temp_p=L_temp.pop(i)
        ans=max(L_temp)
    
    print(ans)

Submission status: Accepted

Solution code:
n=int(input())
arr=[]
for i in range(n):
    a = int(input())
    arr.append( (a,i) )
brr = sorted(arr)
max_num = brr[-1][0]
max_ind = brr[-1][1]
second_num = brr[-2][0]

for i in range(n):
    if i==max_ind:
        print(second_num)
    else:
        print(max_num)

Submission status: Accepted

Solution code:
n = int(input())
 
a = [int(input()) for i in range(n)]
ma1 = max(a)
ma2 = a.count(ma1)
 
for i in range(n):
    if a[i] == ma1:
        if ma2 == 1:
            a[i] = 1
            print(max(a))
            a[i] = ma1
        else:
            print(ma1)
    else:
        print(ma1)

Submission status: Accepted

Solution code:
n = int(input())

a = [int(input()) for i in range(n)]
ma1 = max(a)
ma2 = a.count(ma1)

for i in range(n):
    if a[i] == ma1:
        if ma2 == 1:
            a[i] = 1
            print(max(a))
            a[i] = ma1
        else:
            print(ma1)
    else:
        print(ma1)

Submission status: Accepted

Solution code:

import collections

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

ys = sorted(xs)
mx1 = ys[-1]
mx2 = ys[-2]

for x in xs:
    if x == mx1:
        print(mx2)
    else:
        print(mx1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())
AA = sorted(A, reverse=True)
no1 = AA[0]
no2 = AA[1]
for i in A:
    if i == no1:
        print(no2)
    else:
        print(no1)

Submission status: Accepted

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

AS=sorted(A, reverse=True)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# input
N = int(input())
t1 = 0
t2 = 0
num1 = 0
num2 = 0
for i in range(N):
    x = int(input())
    if t1 < x:
        t2 = t1
        num2 = num1
        t1 = x
        num1 = i
    else:
        if t2 < x:
            t2 = x
            num2 = i
for j in range(0, num1):
    print(t1)
print(t2)
for k in range(num1+1, N):
    print(t1)

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)
m1=max(a)
a.remove(m1)
m2=max(a)
for i in range(n):
  if b[i]==m1:
    print(m2)
  else:
    print(m1)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
_A = sorted(A)
_max = _A[-1]
_max2 = _A[-2]

for a in A:
    if a == _max:
        print(_max2)
    else:
        print(_max)

Submission status: Accepted

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

Submission status: Accepted

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

# 最大値をとるインデックスを求めておく
k = max(range(N), key=lambda i: A[i])
ans = '\n'.join(
    str(
        max(A[:k] + A[k + 1:]) if i == k else
        A[k]
    )
    for i in range(N)
)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sort = sorted(A)

max = sort[-1]
maxx = sort[-2]

for i in range(n):
  if max == A[i]:
    print(maxx)
  else:
    print(max)

Submission status: Accepted

Solution code:
n = int(input())
ls = []
for i in range(n):
    ls.append(int(input()))
maxnum = max(ls)
ind = ls.index(maxnum)
ls.remove(maxnum)
secondnum = max(ls)
ls = ls[0:ind] + [maxnum] + ls[ind:]
#print(ls)
if maxnum == secondnum:
    for i in range(n):
        print(maxnum)
    quit()
for i in range(n):
    if ls[i] == maxnum:
        print(secondnum)
    else:
        print(maxnum)