Problem:


Score : 300 points

Problem Statement

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

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

Constraints

2 \leq N \leq 200000

1 \leq A_i \leq 200000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

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

Sample Input 1

3
1
4
3

Sample Output 1

4
3
4

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

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

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

Sample Input 2

2
5
5

Sample Output 2

5
5



Sample input:
3
1
4
3


Sample output:
4
3
4

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    left = [A[0]] * N
    right = [A[-1]] * N

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

    for i in range(N):
        if i == 0:
            print(right[1])
        elif i == N-1:
            print(left[N-2])
        else:
            print(max(left[i-1], right[i+1]))


    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())
A = []
B = []
for i in range(N):
    a = int(input())
    A.append(a)
    B.append(a)
B.sort(reverse = True)
M1 = B[0]
M2 = B[1]

if M1 == M2:
    for i in range(N):
        print(M1)
else:
    for i in range(N):
        if A[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)
m1 = b[-1]
m2 = b[-2]

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

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    left = [A[0]] * N
    right = [A[-1]] * N

    for i in range(1,N):
        if(A[i] > left[i-1]):
            left[i] = A[i]
        else:
            left[i] = left[i-1]

    for i in reversed(range(0,N-1)):
        if(A[i] > right[i+1]):
            right[i] = A[i]
        else:
            right[i] = right[i+1]

    for i in range(N):
        if(i == 0):
            print(right[1])
        elif(i == N-1):
            print(left[N-2])
        else:
            print(max(left[i-1], right[i+1]))


    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

sorted_a = sorted(a)
first = sorted_a[-1]
second = sorted_a[-2]
first_place = a.index(first)
for i in range(n):
    if first == second:
        print(first)
    else:
        if i == first_place:
            print(second)
        else:
            print(first)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    m1 = 0
    m2 = 0
    la = []
    for i in range(n):
        a = ri()
        if m1 <= a:
            m2 = m1
            m1 = a
        elif m2 < a:
            m2 = a
        la.append(a)
    for a in la:
        if a == m1:
            print(m2)
        else:
            print(m1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

B = sorted(A)
maxA = B[-1]
maxA2 = B[-2]


for i in range(N):
    if A[i] == maxA:
        print(maxA2)
    else:
        print(maxA)

Submission status: Accepted

Solution code:
#そのまま実行したらTLE.２回目でOK．アイデア次第！

n=int(input())
l = [int(input()) for _ in [0] * n]
m = sorted(l)
a = m[-1] #リストの最大値
b = m[-2] #２番目に大きい値、最大値と重複していてもヒットする
for i in range(n):
    if l[i] == a:
        print(b)
    else:
        print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
b = a.copy()
b.sort()
a_max = b[-1]
a_second = b[-2]
for i in range(n):
    if a[i] == a_max:
        print(a_second)
    else:
        print(a_max)

Submission status: Accepted

Solution code:
N = int(input())
li = []
for i in range(N):
  s = int(input())
  li.append(s)
  
new = sorted(li, reverse=True)

s = max(li)
for index, i in enumerate(li):
  if s == li[index]:
    print(new[1])
  else:
    print(new[0])

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
A_sort = list(sorted(A))
for i in range(N):
  print([A_sort[-2], A_sort[-1]][A[i] < A_sort[-1]])

Submission status: Accepted

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

b = list(a)
a.sort()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N = cin.int()
    A = cin.intColsList(N)

    m1,m2 = sorted(A,reverse=True)[0],sorted(A,reverse=True)[1]
    for a in A:
        if a == m1:
            print(m2)
        else:
            print(m1)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(N):

    if (l[i] != l_sort[-1]):
        print(l_sort[-1])
    else:
        print(l_sort[-2])

Submission status: Accepted

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

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

B = A
maxim = max(A)
max_i = A.index(maxim)
B.remove(maxim)
second = max(B)

for i in range(N):
    if (i == max_i):
        print(second)
    else:
        print(maxim)

Submission status: Accepted

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

m, m2 = 0,0
for ai in a:
    if ai > m:
        m, m2 = ai, m
    elif ai > m2:
        m2 = ai

for ai in a:
    if ai == m:
        print(m2)
    else:
        print(m)

Submission status: Accepted

Solution code:
import copy

def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]

    tmp = copy.deepcopy(num_list)
    tmp.sort()

    max_first = max(num_list)
    max_second = tmp[n-2]
    
    for num in num_list:
        if num == max_first:
            print(max_second)
            continue
        print(max_first)
        
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
imax=0
amax=0
amax2=amax
for i in range(n):
    ai=int(input())
    if amax<ai:
        adummy=amax
        amax=ai
        imax=i
        amax2=adummy
    elif amax2<ai:
        amax2=ai
if imax==0:
    print(amax2)
    for i in range(1,n):
        print(amax)
elif imax==n-1:
    for i in range(n-1):
        print(amax)
    print(amax2)
else:
    for i in range(imax):
        print(amax)
    print(amax2)
    for i in range(n-imax-1):
        print(amax)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)[::-1]
mx1 = B[0]
mx2 = B[1]

for i in A:
    if i == mx1:
        print(mx2)
    else:
        print(mx1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
A = []
for i in range(n):
  A.append(int(input()))
s_A = sorted(A, reverse=True)

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

Submission status: Accepted

Solution code:
n=int(input())
a=int(input())
f,v,w=0,a,a
a=int(input())
if a>=v:
    w,v,f=v,a,1
else:
    w=a
for i in range(2,n):
    a=int(input())
    if a>=v:
        w,v,f=v,a,i
    elif a>=w:
        w=a
for i in range(n):
    if i==f:
        print(w)
    else:
        print(v)

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

Submission status: Accepted

Solution code:
import heapq
import copy
import numpy as np

N=int(input())
A=[]
for n in range(N):
    A.append( int(input()) )
A_ = copy.deepcopy(A)
A_ = np.array(A_)
A_ *= -1
A_ = list(A_)
heapq.heapify( A_ )
max_val = heapq.heappop(A_)*(-1)
second_max_val = heapq.heappop(A_)*(-1)

is_max = []
for n in range(N):
    if A[n]==max_val:
        is_max.append(True)
    else:
        is_max.append(False)
max_val_num = np.sum( np.array(is_max) )

for n in range(N):
    if max_val_num > 1:
        print(max_val)
    else:
        if is_max[n]:
            print(second_max_val)
        else:
            print(max_val)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)
for x in A:
    if x == B[-1]:
        print(B[-2])
    else:
        print(B[-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
def test(a_,n_):
    return abs(round(0.1/(n_-(a_+0.1))))

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
n_max = sum(x == a_max for x in a)
if n_max > 1:
    a_max_2 = a_max
    for _ in range(n):
        print(a_max)
else:
    #a_max_2=sorted(set(a))[-2]
    b = copy.copy(a)
    b.remove(a_max)
    a_max_2 = max(b)
    for i in a:
        x = test(i, a_max)
        print((1-x)*a_max + x*a_max_2)

Submission status: Accepted

Solution code:
import copy
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
n_ = sum(x == a_max for x in a)
if n_ > 1:
    a_max_2 = a_max
    for _ in range(n):
        print(a_max)
else:
    #a_max_2=sorted(set(a))[-2]
    b = copy.copy(a)
    b.remove(a_max)
    a_max_2 = max(b)
    for i in a:
        if i == a_max:
            print(a_max_2)
        else:
            print(a_max)

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
n_ = sum(x == a_max for x in a)
if n_ > 1:
    a_max_2 = a_max
    for _ in range(n):
        print(a_max)
else:
    a_max_2=sorted(set(a))[-2]
    for i in a:
        if i == a_max:
            print(a_max_2)
        else:
            print(a_max)

Submission status: Accepted

Solution code:
n = int(input())

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

first = sorted(set(x))[-1]

if len(set(x))==1:
  second = -100
else:
  second = sorted(set(x))[-2]

max_count = x.count(max(x))

for i in x:
  if (i == first) and (max_count == 1):
    if second == -100:
      print(first)
    else:
      print(second)
  elif (i == first) and (max_count != 1):
    print(first)
  else:
    print(first)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A_s = []
for i in range(N):
  A_s.append(int(input()))
  
A_s = np.array(A_s)
  
m_index = A_s.argmax()
sort_A_s = sorted(A_s)
m_value = A_s[m_index]
m_second = sort_A_s[N-2]

for i in range(N):
  if i != m_index:
    print(m_value)
  else:
    print(m_second)

Submission status: Accepted

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

b = sorted(a, reverse=True)

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

Submission status: Accepted

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

sa = sorted(a, reverse=True)

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

Submission status: Accepted

Solution code:
n = int(input())
A = [int(input()) for _ in range(n)]
B = A[:]
B.sort(reverse = True)
max_A = max(A)
for i in range(n):
    if A[i] == max_A:
        print(B[1])
    else:
        print(max_A)

Submission status: Accepted

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

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

sorted_As = sorted(As, reverse=True)
top_As = sorted_As[:2]

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

Submission status: Accepted

Solution code:
n=int(input())
alis=[int(input()) for i in range(n)]
anslis=[max(alis)]*n
if alis.count(max(alis))==1:
	anslis[alis.index(max(alis))]=sorted(alis)[-2]
for i in range(n):
	print(anslis[i])

Submission status: Accepted

Solution code:
N = int(input())
nums = [int(input()) for _ in range(N)]
 
all_max = max(nums)
 
new_nums = list(nums)
new_nums.remove(all_max)
 
second_max = max(new_nums)  # max関数はfor文の中にいれずに、先に2番目の最大値をもとめておく
 
for i in range(N): #indexをまわしているので、iとおく
    if nums[i] == all_max: 
        print(second_max)
    else:
        print(all_max)

Submission status: Accepted

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

all_max = max(nums)

new_nums = list(nums)
new_nums.remove(all_max)

second_max = max(new_nums)  # max関数はfor文の中にいれずに、先に2番目の最大値をもとめておく

for num in range(N):
    if nums[num] == all_max:
        print(second_max)
    else:
        print(all_max)

Submission status: Accepted

Solution code:
import copy

n = int(input())
l = [int(input()) for i in range(n)]
Max1 = sorted(l)[-1]
Max2 = sorted(l)[-2]
for i in range(n):
    if l[i] == Max1:
        print(Max2)
    else:
        print(Max1)

Submission status: Accepted

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

max_num = sorted_nums[-1]
second_max_num = sorted_nums[-2]

for num in nums:
    if num != max_num:
        print(max_num)
    else:
        print(second_max_num)

Submission status: Accepted

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

max_index = A.index(max(A))
A.sort(reverse=True)

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
import copy

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))
    
    max_A = max(A)
    B = sorted(A)
    max2_A = B[N-2]

    if max_A == max2_A:
        for i in range(N):
            print(max_A)
        exit()
    
    for i in range(N):
        tmp=A[i]
        if tmp == max_A:
            print(max2_A)
        else:
            print(max_A)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

max_a = max(a)
b = a[:]
b.remove(max_a)
max_b = max(b)

if max_a == max_b:
    for i in range(n):
        print(max_a)
else:
    idx = a.index(max_a)
    for i in range(n):
        if idx == i:
            print(max_b)
        else:
            print(max_a)

Submission status: Accepted

Solution code:
n = int(input())

f=0
s=0
a=[]
for i in range(n):
  a.append(int(input()))
b=sorted(a)
f=b[-1]
s=b[-2]
for ai in a:
  if ai == f:
    print(s)
  else:
    print(f)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
  
maxA = sorted(A, reverse=True)
maxA1 = maxA[0]
maxA2 = maxA[1]

for i in range(N):
  if A[i] == maxA1:
    print(maxA2)
  else:
    print(maxA1)

Submission status: Accepted

Solution code:
N = int(input())
list_A = []
for _ in range(N):
    A = int(input())
    list_A.append(A)
    
sorted_list = sorted(list_A)
A = sorted_list[len(sorted_list)-1]
B = sorted_list[len(sorted_list)-2]

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

Submission status: Accepted

Solution code:
N = int(input())
list_A = []
for _ in range(N):
    A = int(input())
    list_A.append(A)
    
sorted_list = sorted(list_A, reverse=True)
A = sorted_list[0]
B = sorted_list[1]

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    maximum = 0
    next_maximum = 0
    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)
        if a > maximum:
            maximum = a
        elif a > next_maximum:
            next_maximum = a
    for b in A:
        if b == maximum:
            print(next_maximum)
        else:
            print(maximum)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(input()) for i in range(n)]
    b = sorted(a, reverse=True)

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

bi = sorted(ai)

m = max(ai)

for i in range(n):
    if m == ai[i]:
        print(bi[-2])
    else:
        print(m)

Submission status: Accepted

Solution code:
import copy
n = int(input())
l=[int(input()) for x in range(n)]
ll=copy.copy(l)
ll.sort()
setl=list(set(ll))
m=max(l)
for i in range(n):
    if len(setl)==1:
        print(m)
    elif l[i]==m:
        print(ll[-2])
    else:
        print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [0 for n in range(N)]
B[0] = A[0]
for n in range(N-1):
    B[n+1] = max(B[n], A[n + 1])
C = [0 for n in range(N)]
C[-1] = A[-1]
for n in range(N - 1):
    C[-n-2] = max(C[-n-1], A[-n - 2])
for n in range(N):
    if n == 0:
        print(C[1])
    elif n == N - 1:
        print(B[N - 2])
    else:
        print(max(B[n-1], C[n+1]))

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=[]

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

first=max(a)
b=sorted(a)
second = b[-2]

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

Submission status: Accepted

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

temp = A[A_max_primary]
A[A_max_primary] = 0
A_max_secondary = A.index(max(A))
A[A_max_primary] = temp

for i in range(N):
  if i == A_max_primary:
    print(A[A_max_secondary])
  else:
    print(A[A_max_primary])

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
input=sys.stdin.readline

def resolve():
    N=int(input().rstrip())
    A=[int(input().rstrip()) for _ in range(N)]
    #booltable=[0]+booltable
    cumsum = list(accumulate(A))
    
    Amax=0
    Amax2=0
    _A=sorted(A)
    Amax2=_A[N-2]
    Amax=_A[N-1]

    for i in range(N):
        if A[i]==Amax:
            print(Amax2)
        else:
            print(Amax)
            

if __name__ == "__main__":
    #unittest.main()
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
A = []
for i in range(1, n+1):
    A.append(int(input()))
A_srt = sorted(A)
A1, A2 = A_srt[-1], A_srt[-2]
for i in A:
    if i == A1:
        print(A2)
    else:
        print(A1)

Submission status: Accepted

Solution code:
#coding:utf-8

n = int(input())
a = [int(input()) for _ in range(n)]
A = sorted(a, reverse=True)


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

Submission status: Accepted

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

for _ in range(N):
    A = int(input())
    list_A.append(A)
    
A = max(list_A)
index_A = list_A.index(A)

list_B = sorted(list_A, reverse=True)
B = list_B[1]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
SA = list(reversed(sorted(A)))
for a in A:
    if a == SA[0]:
        print(SA[1])
    else:
        print(SA[0])

Submission status: Accepted

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

N=int(input())
a=[0]*N

max1=[0,0]
max2=[0,0]
for i in range(N):
    a=int(input())
    if max1[0]<=a:
        max2=max1
        max1=[a,i]
    elif max2[0]<=a:
        max2=[a,i]

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

Submission status: Accepted

Solution code:
import sys

def main():
    N = int(input())
    A = [int(sys.stdin.readline()) for i in range(N)]
    anoA = sorted(A)
    mA = max(A)

    for j in range(N):
        if mA == A[j]:
            print(anoA[-2])

        else:
            print(mA)


main()

Submission status: Accepted

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

a_s=sorted(a,reverse=True)
mx=a_s[0]
for i, val in enumerate(a):
    if val!=mx:
        print(mx)
    else:
        print(a_s[1])

Submission status: Accepted

Solution code:
n = int(input())
nlist = []
for i in range(n):
  nlist.append(int(input()))
  
s = sorted(nlist, reverse=True)

for i in nlist:
  if i == s[0]:
    print(s[1])
  else:
    print(s[0])

Submission status: Accepted

Solution code:
# coding: UTF-8
import math
import sys
import copy

numlist = []
for line in sys.stdin.readlines():
  numlist.append(int(line.rstrip()))
N = numlist.pop(0)

nlist = copy.deepcopy(numlist)
Amax1 = max(nlist)
nlist.remove(Amax1)
Amax2 = max(nlist)

for num in numlist:
  if num != Amax1:
    print(Amax1)
  else:
    print(Amax2)

Submission status: Accepted

Solution code:
n = int(input())
a = list(int(input()) for i in range(n))
M = max(a)

if a.count(M) > 1:
  for i in range(n):
    print(M)
elif n == 1:
  print(M)
else:
  M2 = sorted(set(a))[-2]
  for i in range(n):
    if a[i] == M:
      print(M2)
    else:
      print(M)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
A=[int(input()) for i in range(n)]
B=sorted(A)
if B[-1]==B[-2]:
  C=[B[-1] for i in range(n)]
  print(*C,sep='\n')
else:
  max_A=B[-1]
  max_A2=B[-2]
  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())
A = [int(input()) for i in range(N)]

x = A[:]
x.sort()
Amax = x[N-1]
Amax2 = x[N-2]
print("")
for a in A:
    if a < Amax:
        print(Amax)
    elif a == Amax:
        print(Amax2)

Submission status: Accepted

Solution code:
import copy
n = int(input())
l=[int(input()) for x in range(n)]
ll=copy.copy(l)
ll.sort()
setl=list(set(l))
setl.sort()
m=max(l)

for i in range(n):
    if len(setl)==1:
        print(m)
    else:
        second=ll[-2]
        if l[i]==m:
            print(second)
        else:
            print(m)

Submission status: Accepted

Solution code:
n = int(input())
l = [int(input()) for i in range(n)]
l2 = sorted(l)
c2 = l.index(l2[-2])
c = l.index(max(l))
d = max(l)
for i in range(n):
  if i != c:
    print(d)
  else:
    print(l2[-2])

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
B = A[:]
B.sort()
B.reverse()
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)]
m=max(a)
i=a.index(m)

for j in range(n):
    if j!=i:
       print(m)
    else:
        del a[i]
        print(max(a))

Submission status: Accepted

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

first = max(A)
count, index = A.count(first), A.index(first)
A.sort()
second = A[-2]

if count > 1:
    ANSWERS = [first] * n
    for answer in ANSWERS:
        print(answer)
else:
    ANSWERS = [first] * n
    ANSWERS[index] = second
    for answer in ANSWERS:
        print(answer)

Submission status: Accepted

Solution code:
N = int(input())
A = [(int(input()), i) for i in range(N)]
A.sort(key=lambda x:x[0])
idx = [0] * N
for i in range(N): idx[A[i][1]] = i

for i in range(N):
    j = idx[i]
    ans = A[-1]
    if j == N-1: ans = A[-2]
    print(ans[0])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
f, s = sorted(a, reverse=True)[:2]
idx = a.index(f)
if f == s:
    for _ in range(n):
        print(f)
else:
    for i in range(n):
        if i == idx:
            print(s)
        else:
            print(f)

Submission status: Accepted

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

A_max = max(A)

if A.count(A_max) > 1:
    A_second_max = A_max
else:
    A_second_max = max([0 if i == A_max else i for i in A])

for j in A:
    if j == A_max:
        print(A_second_max)
    else:
        print(A_max)

Submission status: Accepted

Solution code:
n = int(input())
l = []
m1, m2 = 0, 0

for i in range(n):
    a = int(input())
    l.append(a)
    if a >= m1:
        m1, m2 = a, m1
    elif a >= m2:
        m2 = a


for e in l:
    if e != m1:
        print(m1)
    else:
        print(m2)

Submission status: Accepted

Solution code:
import sys

N = int(input())

one = (0, 0)
two = (0, 0)
for i, A in enumerate(map(int, sys.stdin.readlines())):
    if A > one[0]:
        two = one
        one = (A, i)
    elif A > two[0]:
        two = (A, i)

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

Submission status: Accepted

Solution code:
N = int(input())

one = (0, 0)
two = (0, 0)
for i in range(N):
    A = int(input())
    if A > one[0]:
        two = one
        one = (A, i)
    elif A > two[0]:
        two = (A, i)

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

Submission status: Accepted

Solution code:
N=int(input())
A = [int(input()) for i in range(N)]
m=max(A)
m2=sorted(A)[-2]
m_i=A.index(m)

ans=[m]*N
ans[m_i]=m2

print('\n'.join(list(map(str,ans))))

Submission status: Accepted

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

Submission status: Accepted

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

ls_as = sorted(ls_a, reverse=True)
fst = ls_as[0]
snd = ls_as[1]

for i in range(n):
	if ls_a[i] != fst:
		print(fst)
	elif ls_a[i] == fst:
		print(snd)