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())
alist = []
for i in range(n):
    alist.append(int(input()))

amax = max(alist)
anslist = [amax]*n
if alist.count(amax)>=2:
    for i in anslist:
        print(i)
    exit()

if alist.count(amax)==1:
    maxindex = alist.index(amax)
    del alist[maxindex]
    anslist[maxindex]= max(alist)
    for i in anslist:
        print(i)
    exit()

Submission status: Accepted

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

A = sorted(List)
Lmax = A[-1]
lmax = A[-2]
for i in range(N):
    if List[i] == Lmax:
        print(lmax)
    else:
        print(Lmax)

Submission status: Accepted

Solution code:
N = int(input())
a = []
b = []
a_max = 0
a_second = 0

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

b = a[:]
a.sort(reverse=True)

a_max = a[0]
a_second = a[1]

for i in range(N):
    if b[i] == a_max:
        print(a_second)
    else:
        print(a_max)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(input()) for i in range(N)]
amax = max(a)
amax2 = sorted(a)[-2]
for i in range(len(a)):
  if a[i]==amax:
    print(amax2)
  else:
    print(amax)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A = np.zeros(N)

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

ind = A.argsort()[::-1][:2]

first_a = A[ind[0]]
second_a = A[ind[1]]

for i, a in enumerate(A):
    if i == ind[0]:
        print(int(second_a))
    else:
        print(int(first_a))

Submission status: Accepted

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

kou = sorted(a, reverse=True)

for j in a:
	if j == kou[0]:
		print(kou[1])
	else:
		print(kou[0])

Submission status: Accepted

Solution code:
n = int(input())

a = [0] * n

first = 0
second = 0

for i in range(n):
    a[i] = int(input())
    if i == 0:
        first = a[i]
    else:
        if a[i] >= first:
            second = first
            first = a[i]
        elif a[i] >= second:
            second = a[i]
            
for i in a:
    if i == first:
        print(second)
    else:
        print(first)

Submission status: Accepted

Solution code:
N=int(input())
l=list()
for i in range(N):
    l.append(int(input()))
a=sorted(l)
m1=a[-1]
m2=a[-2]
for k in range(N):
    if(m1==l[k]):
        print(m2)
    else:
        print(m1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = []
maxNum=-1
secNum=-1
maxI=-1
for i in range(N):
    A.append(int(input()))
    if(maxNum<A[i]):
        secNum=maxNum
        maxNum=A[i]
        maxI=i
    elif(secNum<A[i]):
        secNum=A[i]

for i in range(len(A)):
    if(i!=maxI):
        print(maxNum)
    else:
        print(secNum)

Submission status: Accepted

Solution code:
n=int(input())

max=0
max_i=0
max2=0
for i in range(n):
    x=int(input())
    if max<x:
        max = x
        max_i = i
    elif max2<x:
        max2 = x


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

Submission status: Accepted

Solution code:
import copy
N = int(input())
As = []
for i in range(N):
    As.append(int(input()))
maxA = max(As)
instA = As.copy()
instA.remove(maxA)
secA = max(instA)
for i in range(N):
    if As[i] == maxA:
        print(secA)
    else:
        print(maxA)

Submission status: Accepted

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

MAX = max(A)
sorted_A = sorted(A)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

copied_arr = a.copy()
max1 = max(a)
copied_arr.remove(max1)
max2 = max(copied_arr)

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

Submission status: Accepted

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

for i in range(n):
	a = int(input())
	lis.append(a)
kou = sorted(lis, reverse=True)

for i in range(n):
	if lis[i] < kou[0]:
		print(kou[0])
	else:
		print(kou[1])

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(int(input()) for _ in range(n))
    s = sorted(a)
    MAX1, MAX2 = s[-1], s[-2]
    for i in range(n):
        ans = MAX2 if a[i] == MAX1 else MAX1
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N) ]
left = []
right = []
left_max = 0
right_max = 0
for i in range(N):
    if i == 0:
        left.append(0)
    else:
        left.append(max(left_max, A[i-1]))
    
    if (A[i-1] > left_max) and i != 0:
        left_max = A[i-1]
        
for i in range(N-1, -1, -1):
    if i == N-1:
        right.append(0)
    else:
        right.append(max(right_max, A[i+1]))
    
    if i != N-1:
        if A[i+1] > right_max:
            right_max = A[i+1]
right.reverse()

for i in range(N):
    print(max(left[i],right[i]))

Submission status: Accepted

Solution code:
from collections import *

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

count_a = Counter(a).most_common()
count_a = sorted(count_a, key = lambda x:x[0], reverse=True)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
A_max = max(A)
AA = A[:]
AA.remove(A_max)
A_max_2nd = max(AA)
for num in A:
    if num != A_max:
        print(A_max)
    else:
        print(A_max_2nd)

Submission status: Accepted

Solution code:

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

a_max = max(a)
b = a.copy()
b.remove(a_max)
a_max_second = max(b)

for a_i in a:
    if a_i != a_max:
        print(a_max)
    else:
        print(a_max_second)

Submission status: Accepted

Solution code:
N=int(input())

l=list(int(input()) for i in range(N))

sort_l=sorted(l,reverse=True)

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

Submission status: Accepted

Solution code:
N=int(input())
l=list(int(input()) for i in range(N))

r_sortList = sorted(l, reverse=True)

for i in l:
  if i == r_sortList[0]:
    print(r_sortList[1])
  else:
    print(r_sortList[0])

Submission status: Accepted

Solution code:
##C
n=int(input())
a=list(int(input()) for i in range(n))
b=sorted(a)

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

Submission status: Accepted

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

m = sorted_As[0]
l = sorted_As[1]

res = [m] * N
if l != m:
    ind = As.index(m)
    res[ind] = l

print(" ".join(list(map(str, res))))

Submission status: Accepted

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

m=max(a)
b=a[:]
b.remove(m)
m2=max(b)
x=a.count(m)

for j in a:
    if j==m and x>1:
        print(m)
    elif j==m and x==1:
        print(m2)
    else:
        print(m)

Submission status: Accepted

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

sA = 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=[None]*n
max = 0
max_i = 0
for i in range(n):
  a[i] = int(input())
  if a[i] > max:
    max = a[i]
    max_i = i

max_2 = 0
for i in range(n):
  if i == max_i:
    continue
  elif a[i] > max_2:
    max_2 = a[i]

for i in range(n):
  if i != max_i:
    print(max)
  else:
    print(max_2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    a = list(int(input()) for _ in range(n))
    ranking = sorted(a)[::-1]
    first = ranking[0]
    second = ranking[1]
    first_idx = a.index(first)
    for idx in range(n):
        if idx == first_idx:
            print(second)
        else:
            print(first)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def abc_134c(N):
    max_1 = (0, 0)
    max_2 = (0, 0)
    for i in range(N):
        buf = int(input())
        if max_2[1] < buf:
            if max_1[1] < buf:
                max_2 = max_1
                max_1 = (i, buf)
            else:
                max_2 = (i, buf)

    output = [max_1[1] for _ in range(N)]
    output[max_1[0]] = max_2[1]
    [print(output[i]) for i in range(N)]


if __name__ == "__main__":
    N = int(input())
    abc_134c(N)

Submission status: Accepted

Solution code:
N = int(input())
nums = [int(input()) for _ in range(N)]
nums_copy = sorted(nums[:], reverse=True)
max_1 = nums_copy[0]
max_2 = nums_copy[1]

for n in nums:
    if n == max_1:
        print(max_2)
    else:
        print(max_1)

Submission status: Accepted

Solution code:
N = int(input())
max_1 = 0
max_2 = 0
nums = []
for _ in range(N):
    n = int(input())
    if n >= max_1:
        max_2 = max_1
        max_1 = n
    if n < max_1:
        if n >= max_2:
            max_2 = n
    nums.append(n)

for n in nums:
    if n == max_1:
        print(max_2)
    else:
        print(max_1)

Submission status: Accepted

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

s=max(a)
t=a.index(s)

for i in range(n):
  if i==t:
    del a[t]
    print(max(a))
  else:
    print(s)

Submission status: Accepted

Solution code:
#h = list(map(int, input().split()))
#r = int(input())
#n, d = map(int, input().split())

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

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

sa = sorted(a)
sa.reverse()

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

Submission status: Accepted

Solution code:
#h = list(map(int, input().split()))
#r = int(input())
#n, d = map(int, input().split())

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

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

sa = sorted(a)
sa.reverse()

m1 = sa[0]
m2 = sa[0]
for i in sa:
    if i != m1:
        m2 = i
        break

if a.count(m1) >= 2:
    for i in a:
        print(m1)
else:
    for i in a:
        if i == m1:
            print(m2)
        else:
            print(m1)

Submission status: Accepted

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

Submission status: Accepted

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

ts2 = sorted(t)[-2]
tsmax = sorted(t)[-1]
result = [max(t)]*len(t)
result[t.index(tsmax)] = ts2

print("\n".join(list(map(str, result))))

Submission status: Accepted

Solution code:
N = int(input())

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

max_num = max(A)
B = sorted(A)

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) 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())
max = 0
max_i = N + 1
max_sc = 0
for i in range(N):  
    tmp = int(input())
    if tmp > max:
        max_sc = max
        max = tmp
        max_i = i
    elif tmp > max_sc:
        max_sc = tmp
for i in range(N):
    if i == max_i:
        print(max_sc)
    else:
        print(max)

Submission status: Accepted

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

lmax = [0] * (N + 1)
rmax = [0] * (N + 1)

for i in range(0, N - 1):
    lmax[i + 1] = max(lmax[i], A[i])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for _ in range(n):
    a.append(int(input()))
max1=max(a)
import copy
b=copy.copy(a)
b[b.index(max1)]=0
max2=max(b)
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 i in range(N)]
max_val=max(A)

def f(A):
  for i in range(N):
    if A[i]==max_val:
      n=i
    else:
      pass
   
  return n
n=f(A)
l=[max_val]*N
A.pop(n)
second_max=max(A)
l[n]=second_max

for i in range(N):
  print(l[i])

Submission status: Accepted

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

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

a1,a2 = sorted(numbers, reverse=1)[:2]
b = [a2 if x==a1 else a1 for x in numbers]
print('\n'.join(map(str,b)))

Submission status: Accepted

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

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


m1,m2 = sorted(numbers, reverse=1)[:2]

b = [m2 if x==m1 else m1 for x in numbers]
for s in b:
    print(s)

Submission status: Accepted

Solution code:
n = int(input())
data = [int(input()) for k in range(n)]
m1,m2 = sorted(data, reverse=1)[:2]
b = [m2 if x==m1 else m1 for x in data]
print('\n'.join(map(str,b)))

Submission status: Accepted

Solution code:
N = int(input())
A = [0 * x for x in range(N)]
B = [0 * x for x in range(N-1)]

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

flag = False
M = max(A)
if A.count(M) > 1:
  flag = True
for i in range(N):
  if A[i] == M:
    if flag:
      print (M)
    else:
      print(max(A[:i]+A[i+1:]))
  else:
    print (M)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
 
n = int(input())
data = [int(input()) for k in range(n)]
m1,m2 = sorted(data, reverse=1)[:2]
b = [m2 if x==m1 else m1 for x in data]
print('\n'.join(map(str,b)))

Submission status: Accepted

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

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

for i in range(n):
  if arr[i]==a:
    b=max(arr[:i]+arr[i+1:])
    break
    
for i in range(n):
  if arr[i]!=a:
    print(a)
  else:
    print(b)

Submission status: Accepted

Solution code:
#134
N=int(input())
a=[int(input()) for i in range(N) ]
a_M=[]
a_M1=sorted(a)[-1]
a_M2=sorted(a)[-2]
for i in range(N):
    if a[i]==a_M1:
        a_M.append(a_M2)
    else:
        a_M.append(a_M1)
for x in a_M:
    print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
#n,d=map(int,input().split())
n=int(input())
a=list(int(input())for _ in range(n))
A=copy.deepcopy(a)
A.sort(reverse=True)
#print("-----------")
for i in range(n):
        if a[i]!=A[0]:
                print(A[0])
        else:
                print(A[1])

Submission status: Accepted

Solution code:
#　まずinput
n = int(input())
t = [int(input()) for i in range(n)] 

ma = max(t)
ma2 = sorted(t)[n-2]
 
for j in t:
    if j != ma:
        print(ma)
    else:
        print(ma2)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ma = max(t)
ma2 = sorted(t)[n-2]

for j in t:
  if j != ma:
  	print(ma)
  else:
    print(ma2)

Submission status: Accepted

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

sorted_A_list = sorted(A_list)

for i, item in enumerate(A_list):
  if item != sorted_A_list[-1]:
    print(sorted_A_list[-1])
  else:
    print(sorted_A_list[-2])

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(1, N+1):
    A.append((i, int(input())))
A.sort(reverse=True, key=lambda x:x[1])

max_ind = A[0][0]
max_value = A[0][1]

for i in range(1, N+1):
    if i == max_ind:
        print(A[1][1])
    else:
        print(max_value)

Submission status: Accepted

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

tmp=sorted(a_list)[::-1]
one=tmp[0]
two=tmp[1]
for i in range(len(a_list)):
    if a_list[i]==one:
        print(two)
    else:
        print(one)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
m = -1
o = -1
for i in range(n):
    p = int(input())
    m = max(m, p)
    if m != o:
        num=i
    o=m
    a += [p]
anslist=[max(a)]*n
if a.count(max(a)) >= 2:
    for i in range(n):
        print(anslist[i])
else:
    a.pop(num)
    anslist[num] = max(a)
    for i in range(n):
        print(anslist[i])

Submission status: Accepted

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

for i in range(n):
    numlist.append(int(input()))
sortlist=numlist[:]
sortlist.sort()


for num in numlist:
    if num==sortlist[-1]:
        print(sortlist[-2])
    else:
        print(sortlist[-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for i in range(N)]
Am = max(A)
Asm = sorted(A)[-2]

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

Submission status: Accepted

Solution code:
n = int(input())
hoge = [int(input()) for i in range(n)]
max_value = max(hoge)
second_value = sorted(hoge)[-2]
if max_value == second_value:
    for i in range(len(hoge)):
        print(max_value)
else:
    for i in hoge:
        if i != max_value:
            print(max_value)
        else:
            print(second_value)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd
import numpy as np
import copy

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    L = [int(sys.stdin.readline()) for _ in range(N)]

    Mi = L.index(max(L))

    tmpL = copy.deepcopy(L)
    tmpL[Mi] = 0
    Mi2 = tmpL.index(max(tmpL))

    for i in range(len(L)):
        if i == Mi:
            print(L[Mi2])
            continue
        print(L[Mi])

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)
n, *a = map(int,open(0))
for i in a:
  d[i] += 1
l = list(d.keys())
l.sort()
m = l[-1]
if d[m] == 1:
  i = a.index(m)
  [print(m) for j in range(i)]
  print(l[-2])
  [print(m) for j in range(n-i-1)]
else:
  [print(m) for i in range(n)]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)
c = A.index(max(A))
for i in range(N):
    if i == c:
        print(B[-2])
    else:
        print(B[-1])

Submission status: Accepted

Solution code:
N = int(input())
A = []
B = []
while len(A) != N:
    A.append(int(input()))
B = A[0:N]
B.sort()
if B[-1] == B[-2]:
    for _ in range(N):
        print(B[-1])
else:
    for _ in range(N):
        if A[_] == B[-1]:
            print(B[-2])
        else:
            print(B[-1])

Submission status: Accepted

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

m1 = max(a)
b = sorted(a, reverse = True)
m2 = max(b[1:])

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

Submission status: Accepted

Solution code:
n = int(input(''))

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

n1 = max(xs)
n2 = sorted(xs)[-2]

for x in xs:
    if x == n1:
        print(n2)
    else:
        print(n1)

Submission status: Accepted

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

_nums = sorted(nums, reverse=True)
max1 = _nums[0]
max2 = _nums[1]
for i in range(0, N):
    if nums[i] == max1:
        print(max2)
    else:
        print(max1)

Submission status: Accepted

Solution code:
N = int(input())
num_list = [int(input()) for i in range(N)]
sec_num, max_num = sorted(num_list)[-2:]

for k in num_list:
    if(max_num == k):
        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()))

tmp = a[:]
max1 = max(tmp)
tmp.remove(max1)
max2 = max(tmp)

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

Submission status: Accepted

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

org = A[:]
A.sort()
for v in org:
    if v == A[N - 1]:
        print(A[N - 2])
    else:
        print(A[N - 1])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n = int(input())
	a = []
	for i in range(n):
		a.append(int(input()))
	mx = max(a)
	if(a.count(mx)!=1):
		for i in range(n):
			print(mx)
	else:
		for i in range(n):
			if(a[i]==mx):
				b = deepcopy(a)
				b.pop(a.index(mx))
				print(max(b))
			else:
				print(mx)

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Accepted

Solution code:
n1 = int(input())
n2 = []

m1 = 0
m2 = 0
for i2 in range(n1):
    t1 = int(input())
    n2.append(t1)
    if t1 > m1:
        m2 = m1
        m1 = t1
    elif t1 > m2:
        m2 = t1

for i1 in range(n1):
    if n2[i1] == m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
n = int(input())
num = [int(input()) for _ in range(n)]
m = max(num)
sec = sorted(num)[-2]
for x in num:
    if x != m:
        print(m)
    else:
        print(sec)

Submission status: Accepted

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

max_A = max(A, key=int)
max_A_number = A.index(max_A)
A.remove(max_A)
next_A = max(A, key=int)

for i in range(N):
    if i == max_A_number:
        print(next_A)
    else:
        print(max_A)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
list=[]
i=0
j=0
l=0
m=0
o=0
c=max(a)
for i in range(n):
  if c!=a[i]:
    continue
  else:
    list.append(i)
if len(list)>1:
  for l in range(n):
    print(c)
else:
  del a[list[0]]
  d=max(a)
  for o in range(n):
    if o==list[0]:
      print(d)
    else:
      print(c)

Submission status: Accepted

Solution code:
n=int(input())
t1=int(input())
t2=int(input())

if t1 >= t2:
    m1, i1 = t1, 1
    m2, i2 = t2, 2
else:
    m1, i1 = t2, 2
    m2, i2 = t1, 1

for i in range(2, n):
    idx = i + 1
    v = int(input())
    if m1 < v:
        m2, i2 = m1, i1
        m1, i1 = v, idx
    elif m2 < v:
        m2, i2 = v, i1
        i2 = idx

for i in range(0, n):
    if m1 == m2:
        print(m1)
    elif i+1 == i1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

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

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

b = copy.copy(a) 
b.sort(reverse=True)
for val in range(N):
    if a[val] < 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)]
A = max(a)
b = sorted(a)[-2]
if a.count(A) > 1:
    for i in range(len(a)):
        print(A)
else:
    for i in range(len(a)):
        if a[i] == A:
            print(b)
        else:
            print(A)

Submission status: Accepted

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

temp=s.copy()
s_max=max(temp)
temp.remove(s_max)
s_max2=max(temp)

for i in range(N):
  if s[i]<s_max:
    print(s_max)
  else:
    print(s_max2)

Submission status: Accepted

Solution code:
n = int(input())
a = [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:
n = int(input())
a = [int(input()) for i in range(n)]
a_s = sorted(a, reverse=True)
hantei = a_s[:2]
del a_s
for i in range(n):
    if a[i] == hantei[0]:
        print(hantei[1])
    else:
        print(hantei[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

S = sorted(A)
M1 = S[-1]
M2 = S[-2]

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

Submission status: Accepted

Solution code:
import math

n = int(input())

arr = []
s_arr = []

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

s_arr=sorted(arr, reverse=True)

for a in arr:
    if a >= s_arr[0]:
        print(s_arr[1])
    else:
        print(s_arr[0])

Submission status: Accepted

Solution code:
n = int(input())

l = []

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

m = max(l)

if l.count(m) >= 2:
  for i in range(n):
    print(m)
  exit()

index = l.index(m)  

l.pop(index)

for i in range(n):
  if i == index:
  	print(max(l))
  else:
    print(m)

Submission status: Accepted

Solution code:
n=int(input())
num_list=[]
for a in range(n):
    a=int(input())
    num_list.append(a)
new_list=sorted(num_list)
p=new_list[-1]
q=new_list[-2]
for x in range(n):
    if num_list[x]==p:
        print(q)
    else:
        print(p)