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 math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n = i()
a = hi(n)
maxa = max(a)
b = sorted(a, reverse=True)
snda = b[1]
if maxa == snda:
    for i in range(n):
        print(maxa)
else:
    for i in range(n):
        if maxa == a[i]:
            print(snda)
        else:
            print(maxa)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(list(set(A)))
max_v = B[-1]
max_c = A.count(max_v)
for i in range(N):
    tmp = A[i]
    if tmp != max_v:
        print(max_v)
    else:
        if max_c > 1:
            print(max_v)
        else:
            print(B[-2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
from collections import deque

def input():
    return sys.stdin.readline().rstrip()

N = int(input())
que = deque([int(input()) for i in range(N)])
tmp = 0
max_num1 = sorted(que)[-1]
max_num2 = sorted(que)[-2]

for i in range(N):
    tmp = que.popleft()
    if tmp != max_num1:
        print(max_num1)
    else:
        print(max_num2)
    que.append(tmp)

Submission status: Accepted

Solution code:
N = int(input())
A = MAX = [0]*N
max_1 = max_2 = index = 0
for i in range(N):
  A[i] = int(input())
  if A[i] >= max_1:
    max_2 = max_1
    max_1 = A[i]
  elif A[i] > max_2:
    max_2 = A[i]
for i in range(N):
  if A[i] == max_1:
    print(max_2)
  else:
    print(max_1)

Submission status: Accepted

Solution code:
a = []
c = []
n = int(input())
max_i = 0
max_s = 0
b = False
for i in range(n):
    aa = int(input())
    a.append(aa) 
    c.append(aa)   
    if max_i < aa : max_i = aa

c.remove(max_i)
max_s = max(c)

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

Submission status: Accepted

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

# input
N = int(input())
A = list()
for _ in range(N):
    A.append(int(input()))

# solve & output
ans = copy.copy(A)
ans.sort()
m = ans[-1]
for i in range(N):
    if A[i] != m:
        print(m)
    else:
        print(ans[N - 2])

Submission status: Accepted

Solution code:
import copy

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

result = max(A)
ind = A.index(result)

for i in range(N):
    if i == ind:
        a = copy.deepcopy(A)
        a.remove(result)
        print(max(a))
    else:
        print(result)

Submission status: Accepted

Solution code:
N = int(input())
C = list(map(int,[input() for _ in range(N)]))
# 1番目と2番目の大きさの数を取り出す
first = -1
second = -2
for i in range(N):
    if first <= C[i]:
        second = first
        first = C[i]
    elif second < C[i]:
        second = C[i]
    
for j in range(N):
    if C[j] == first:
        print(second)
    else:
        print(first)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A = [int(input()) for i in range(N)]
A = np.array(A)
first = max(A)
arg = A.argsort()
first_idx = arg[-1]
second_idx = arg[-2]
second = A[second_idx]
for i in range(len(A)):
  if i==first_idx:
    print(second)
  else:
    print(first)

Submission status: Accepted

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

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

if n == 1:
    print(a[0])
else:
    s = sorted(a, reverse=True)[0]
    t = sorted(a, reverse=True)[1]

    for i in a:
        if i == s:
            print(t)
        else:
            print(s)

Submission status: Accepted

Solution code:
n = int(input()) 
t = [int(input()) for i in range(n)]
m2 = sorted(t)[-2]
m = max(t)
for i in range(n):
	if t[i] != m:
		print(m)
	else:
		print(m2)

Submission status: Accepted

Solution code:
a = int(input())
b = [int(input()) for _ in range(a)]
c = [0] * a
c[0] = b[0]
c[1] = max(b[1], c[0])
d = [0] * a
d[0] = b[-1]
d[1] = max(b[-2], d[0])
for i in range(2, len(b)):
    c[i] = max(c[i-1], b[i])
    d[i] = max(d[i-1], b[-i-1])
c.insert(0, 0)
d.insert(0, 0)
for i in range(len(c)-1):
    print(max(c[i], d[-i-2]))

Submission status: Accepted

Solution code:
n=int(input())
a=list(int(input()) for i in range(n))
b=[0]
c=[0]
for i in range(n):
    b.append(max(b[i],a[i]))
    c.append(max(c[i],a[-i-1]))
del b[n]
del c[n]
 
for i in range(n):
    d=b[i]
    e=c[n-1-i]
    print(max(d,e))

Submission status: Accepted

Solution code:
N=int(input())
A = [int(input()) for i in range(N)]
maxval = max(A)
argmaxval = A.index(maxval)
for i,a in enumerate(A):
  if i==argmaxval:
    B = A[:]
    B[i]=0
    print(max(B))
  else:
    print(maxval)

Submission status: Accepted

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

# input
N = int(input())
A = list()
for _ in range(N):
    A.append(int(input()))

# solve & output
ans = copy.copy(A)
ans.sort()
m = ans[-1]
for i in range(N):
    if A[i] != m:
        print(m)
    else:
        print(ans[N - 2])

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    a_list = [int(input()) for _ in range(n)]
    maximum = max(a_list)
    count = a_list.count(maximum)
    if count == 1:
        second = max(set(a_list) - set([maximum]))
    for a in a_list:
        if count > 1:
            print(maximum)
            continue
        if maximum == a:
            print(second)
        else:
            print(maximum)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

b = sorted(a)
maxnum = b[-1]
nextmaxnum = b[-2]

if maxnum == nextmaxnum:
  for i in range(n):
    print(maxnum)
else:
  for i in range(n):
    if a[i] == maxnum:
      print(nextmaxnum)
    else:
      print(maxnum)

Submission status: Accepted

Solution code:
n = int(input())
max1 = 0
max2 = 0
index = 0
for i in range(n):
    a = int(input())
    new_max = max(a, max1)
    if (a == new_max and max2 <= max1) or (a == new_max and max2 <= max1 and a == max1):
        max2 = max1
        index = i
    elif (a != new_max and max2 <= a) or (a != new_max and max2 <= a and a == max1):
        max2 = a
    max1 = new_max

for i in range(n):
    if i != index:
        print(max1)
    else:
        print(max2)

Submission status: Accepted

Solution code:
import numpy as np
n= int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
    
b = np.array(a)
b = np.sort(b)[::-1]

ans = [0]*n

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

Submission status: Accepted

Solution code:
# ABC 134, C -

n = int(input())

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

B = sorted(A)



m = B[len(B)-1]
m_ind = A.index(m)

m2 = B[len(B)-2]
for i in range(n):
    if m != m2:
        if i == m_ind:
            print(m2)
        else:
            print(m)
    else:
        print(m)

Submission status: Accepted

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

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

nums_sorted = sorted(nums,reverse=True)
max1 = nums_sorted[0]
max2 = nums_sorted[1]

for num in nums:
    if(num!=max1):
        print(max1)
    else:
        print(max2)

Submission status: Accepted

Solution code:
N, *d = map(int, open(0).read().split())
allmax = max(d)
allMaxCount = d.count(allmax)
for i in range(N):
    max = 0
    if(allMaxCount > 1 or d[i] != allmax):
        max = allmax
    else:
        for j in range(N):
            if(i == j):
                continue
            if d[j] > max:
                max = d[j]
                if max == allmax:
                    break
    print(max)

Submission status: Accepted

Solution code:
n = int(input())
l = [int(input()) for i in range(n)]
ll = sorted(l, reverse = True)
m1 = ll[0]
m2 = ll[1]

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

Submission status: Accepted

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

sort = temp[:]

sort.sort()

maximum = sort[-1]


for i in temp:
	if i != maximum:
		print(maximum)

	else:
		print(sort[-2])

Submission status: Accepted

Solution code:
import heapq
n = int(input())
a_list = [int(input()) for _ in range(n)]
a_list_heap = list(map(lambda x:(-1)*x,a_list))
heapq.heapify(a_list_heap)
max_num = a_list_heap[0]*(-1)

for i in range(len(a_list)):
    if a_list[i] != max_num:
        print(max_num)
    else:
        tmp = heapq.heappop(a_list_heap)
        print(a_list_heap[0]*(-1))
        heapq.heappush(a_list_heap,tmp)

Submission status: Accepted

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

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

array_sorted = sorted(array, reverse=True)
max_index = array.index(array_sorted[0])
max_value = array_sorted[0]
second_value = array_sorted[1]

for i in range(N):
  if array[i] == max_value:
    print(second_value)
  else:
    print(max_value)

Submission status: Accepted

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

import numpy as np

mi=np.argmax(x)

y=np.array(x)

for i in range(n):
	if i!=mi:
		print(x[mi])
	else:
		z=np.ones(n)
		z[i]=0
		print(int(max(y*z)))

Submission status: Accepted

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

A_max = max(A_copy)
A_copy.remove(A_max)
A_next = max(A_copy)
for i in A:
    if i == A_max:
        print(A_next)
    else:
        print(A_max)

Submission status: Accepted

Solution code:
n = int(input())
s = {}
for i in range(n):
    s[i] = int(input())

max_v = max(s.values())
max_k = max(s,key=s.get)
s.pop(max_k)
max_v2 = max(s.values())
max_k2 = max(s,key=s.get)

for i in range(n):
    if(i==max_k):
        print(max_v2)
    else:
        print(max_v)

"""
for i in range(n):
    temp = s[i]
    s.pop(i)
    max_v = max(s.values())
    print(max_v)
    s[i]=temp
"""

Submission status: Accepted

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

m_l = [0]
m_r = [0]

for i in range(n):
  m_l.append(max(m_l[i], l[i]))
  m_r.append(max(m_r[i], l[-(i+1)]))
m_r = m_r[::-1]
#print(m_l) 
#print(m_r)

for i in range(n):
  print(max(m_l[i], m_r[i+1]))

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    
A_MAX = max(A)
B = len([k for k in A if k == A_MAX])


if len(A) != B:
    C = -B-1
    D = sorted(A)
    A_MAX2 = D[C]

for j in A:
    if j == A_MAX:
        if B > 1:
            print(A_MAX)
        else:
            print(A_MAX2)
    else:
        print(A_MAX)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
max_1_idx = np.argmax(a)
max_1_val = a[max_1_idx]
a[max_1_idx] = -1
max_2_val = np.max(a)
for i in range(n):
    if i == max_1_idx:
        print(max_2_val)
    else:
        print(max_1_val)

Submission status: Accepted

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

numset = set(arr)
maxval = max(numset)
count = 0

if len(numset) == 1:
    for i in range(n):
        print(maxval)
else:
    numset.remove(maxval)
    semimax = max(numset)
    for j in range(n):
        if arr[j] == maxval:
            count +=1
    for i in range(n):
        if arr[i] == maxval and count == 1:
            print(semimax)
        else:
            print(maxval)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
nums = [int(input()) for _ in range(N)]
nums = np.array(nums)
max_num = max(nums)
max_index = np.where(nums == nums.max())[0]

if len(max_index) == 1:
  for i in range(len(nums)):
    if i == max_index[0]:
      print(sorted(nums)[-2])
    else:
      print(max_num)
else:
  for i in range(len(nums)):
    print(max_num)

Submission status: Accepted

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

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

Max = max(a)
if(a.count(Max)>1):
    for _ in range(n):
        print(Max)
else:
    for i in range(n):
        if(a[i]==Max):
            a[i]=0
            print(max(a))
        else:
            print(Max)

Submission status: Accepted

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

index = A.index(max(A))
A.sort()
max_ = A[-1]
second_max = A[-2]

if max_ == second_max:
    for _ in range(N):
        print(max_)
else:
    for i in range(N):
        if i == index:
            print(second_max)
        else:
            print(max_)

Submission status: Accepted

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

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

max_list = sorted(A, reverse=True)
max_index = A.index(max(A))

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

Submission status: Accepted

Solution code:
n = int(input())

a = []
b = set()
for _ in range(n):
    tmp = int(input())
    a.append(tmp)
    b.add(tmp)

max_num = max(b)
c = b - {max_num}
if len(c) == 0 or a.count(max_num) >= 2:
    second_max_num = max_num
else:
    second_max_num = max(c)

for elem in a:
    if not elem == max_num:
        print(max_num)
    else:
        print(second_max_num)

Submission status: Accepted

Solution code:
import numpy as np

now_max = -1
prev_max = 100000000
left_max = -1
right_max = -1
right_max_index = 0

N = int(input())
A_list = [int(input()) for _ in range(N)]
np_A_list = np.array(A_list)
for i, A in enumerate(A_list):
    # 右端
    if i == len(A_list) - 1:
        print(left_max)
        break
    if right_max_index == i:
        slc = np_A_list[i + 1:]
        right_max = slc.max()
        right_max_index = len(np_A_list) - 1 - slc[::-1].argmax()

    if left_max > right_max:
        now_max = left_max
        print(left_max)
    else:
        now_max = right_max
        print(right_max)
    
    if prev_max < now_max:
        left_max = right_max = now_max
        right_max_index = 10000000
    
    prev_max = now_max
    if left_max < A:
        left_max = A

Submission status: Accepted

Solution code:
N = int(input())

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

A.sort(key=lambda x :x[1],reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
N=int(input()) 
a=[int(input()) for i in range(N)]
b=sorted(a)
n=0
c=a.index(max(a))
for n in range(N):
    if n==c:
        print(b[-2])
    else:
        print(b[-1])

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
maxA = max(A)
secondA = sorted(A)[-2]
for j in range(N):
    if (A[j] != maxA):
        print(maxA)
    else:
        print(secondA)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input())for i in range(N)]
T=A.copy()
A.sort()
max1=A[-1]
mcount=A.count(max1)
max2=A[-2]
for i in range(N):
    if T[i]==max1 and mcount==1:
        print(max2)
    else:
        print(max1)

Submission status: Accepted

Solution code:
N = int(input())

A = []

for n in range(N):
    A.append([n, int(input())])
As = sorted(A, reverse=True, key=lambda x: x[1])

for n in range(N):
    i = 0    
    if n == 0:
        if A[0] == As[0]:
            print(As[1][1])
        else:           
            print(As[0][1])
    else:
        while i < n:
            if A[n] == As[i]:
                i+=1
                print(As[i][1])
                break

            elif A[n][1] > As[i][1]:
                    i += 1
            else:
                print(As[i][1])
                break

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
 
MAX = 0
MAX_index = []
MAX_sec = 0
for i in range(n):
    a = int(input())
    if MAX == a:
        MAX_index.append(i)
    elif MAX < a:
        if len(MAX_index)==i:
            MAX_sec = MAX
        MAX_index = [i]
        MAX = a
    elif MAX_sec < a:
        MAX_sec = a
    
#print(MAX_index)
        
if len(MAX_index)==1:
    for i in range(n):
        if i==MAX_index[0]:
            print(MAX_sec)
        else:
            print(MAX)
else:
    for i in range(n):
        print(MAX)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

A_set = set(A)
A_setlist = list(A_set)
Anp = np.array(A)
Amax = max(A)
maxidx = np.where(Anp==Amax)[0]

if(len(A_setlist)==1):
    for i in range(0,N):
        print(A_setlist[0])
else:
    if(len(maxidx)>1):
        ansNp = np.ones(N)*Amax
    else:
        Anp_bk =np.copy(Anp)
        Anp[Anp==Amax] = -1
        Anp2list = list(Anp)
        Amax2 = max(Anp2list)
        ansNp = np.where(Anp_bk==Amax,Amax2,Amax)
    for i in range(0,N):
        print(int(ansNp[i]))

Submission status: Accepted

Solution code:
a=[]
b=int(input())
c=[]
i=0
while i<b:
    a.append(int(input()))
    i+=1
for x in a:
    c.append(x)
c.sort()

i=1

if c[-1]!=c[-2]:
    while i<=b:
        if a[i-1]!=c[-1]:
            print(c[-1])
        else:
            print(c[-2])
        i+=1
else:
    while i<=b:
        print(c[-1])
        i+=1

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    al = [(i, int(input())) for i in range(n)]

    al.sort(key = itemgetter(1), reverse = True)

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

Submission status: Accepted

Solution code:
n = int(input())
import numpy as np
a = np.array([int(input()) for _ in range(n)])
M = max(a)
if np.sum(a==M) >= 2:
  [print(M) for _ in range(n)]
else:
  result = [M]*n
  result[np.argmax(a)] = sorted(a)[-2]
  [print(i) for i in result]

Submission status: Accepted

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

FIRST = max(A)
if A.count(FIRST) > 1:
    for i in range(N):
        print(FIRST)
else:
    SECOND = max([a for a in A if a != FIRST])
    for a in A:
        if a == FIRST:
            print(SECOND)
        else:
            print(FIRST)

Submission status: Accepted

Solution code:

import numpy as np

N = int(input())
A = []
B = []

for _ in range(N):
    putin = int(input())
    A.append(putin)
    B.append(putin)

MAX = int(np.max(A))
A.remove(MAX)
MAX2 = int(np.max(A))

for i in range(N):
    if B[i] == MAX:
        print(MAX2)
    
    else:
        print(MAX)

Submission status: Accepted

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

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

As = ld = sorted(A, reverse=True)
# print(As)
m = As[0:2]
# print(m)
for i in range(N):
    if A[i] == m[0]:
        print(m[1])
    else:
        print(m[0])

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

max = [0, 0]
max2 = 0

n = int(input())

for i in range(n):
    sub = int(input())
    if(max2 < sub):
        if(max[0] < sub):
            max2 = max[0]
            max[0] = sub
            max[1] = i
        else: 
            max2 = sub

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

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    Ap = copy.copy(A)

    A.sort()
    maxA = A[-1]
    A2 = A[-2]

    if maxA == A2:
        for _ in range(N):
            print(maxA)
    else:
        for a in Ap:
            if a == maxA:
                print(A2)
            else:
                print(maxA)
    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().strip())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)
m = 0
m2 = 0
var = 0
z = 0
for k in range(N):
  a = grid[k][0]
  if a > m:
    m2 = m
    m = a
    z = k
    if var > 0:
      var = 0
  elif a == m:
    var = var+1
  elif a > m2: 
    m2 = a
if var ==0:
  for k in range(N):
    if k == z:
      print(m2)
    else:
      print(m)
if var > 0:
  for k in range(N):
    print(m)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

max1 = 0
max1_ind = 0
max2 = 0
max2_ind = 0
 
for i in range(n):
    if max2 <= a[i]:
        if max1 <= a[i]:
            max2 = max1
            max2_ind = max1_ind
            max1 = a[i]
            max1_ind = i
            
        else:
            max2 = a[i]
            max2_ind = i
    
for j in range(n):
    if j == max1_ind:
        print(max2)
    else:
        print(max1)

Submission status: Accepted

Solution code:
n = int(input())

biggest = 0
biggest_arg = 0
second_biggest = 0
second_biggest_arg = 0

for i in range(n):
  num = int(input())
  if num >= biggest:
    second_biggest = biggest
    second_biggest_arg = biggest_arg
    
    biggest = num
    biggest_arg = i
  elif num >= second_biggest:
    second_biggest = num
    second_biggest_arg = i

for i in range(n):
  if i == biggest_arg:
    print(second_biggest)
  else:
    print(biggest)

Submission status: Accepted

Solution code:
import copy
N = int(input())
A = [int(input()) for i in range(N)]
B = copy.copy(A)
Max_1 = max(A)
B.remove(Max_1)
Max_2 = max(B)

for i in A:
    if i == Max_1:
        print(Max_2)
    else:
        print(Max_1)

Submission status: Accepted

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

n = int(input())

a = []

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

a_sorted = sorted(a, key = lambda k:k[1])
max_index = a_sorted[-1][0]

#print(a_sorted)

a_max = a_sorted[-1][1]
a_sec_max = a_sorted[-2][1]

for i in range(0,n):
    if i != max_index:
        print(a_max)
    else:
        print(a_sec_max)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

right = [0]
left = [0]

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
        
a = [(int(input()), i) for i in range(n)]
a.sort()
max_, max_index = a[-1]

for i in range(n):
  if i != max_index:
  	print(max_)
  else:
  	print(a[-2][0])

Submission status: Accepted

Solution code:
n = int(input())
s = []
p = []
for i in range(n):
    s.append(int(input()))
    
p = s[:] 
s.sort()
for i in p:
    if i != s[-1]:
        print(s[-1])
    else:
        print(s[-2])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
tmp = max(A)
li = list(A)
li.sort(reverse=True)
if len(li)==1:
    tmp2 = li[0]
else:
    tmp2 = li[1]
for i in range(N):
    if A[i] != tmp:
        print(tmp)
    else:
        print(tmp2)

Submission status: Accepted

Solution code:

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

max_ = max(li)
max_i = li.index(max_)
li.pop(max_i)
max2 = max(li)
res = [max_]*n
res[max_i] = max2

for a in res:
    print(a)

Submission status: Accepted

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

    max_value = max(A)
    max_index = A.index(max_value)

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

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = []
ans = []
m = 0
sec = 0
c = 0
for i in range(n):
    num = int(input())
    a.append(num)
    m = max(num, m)

for i in range(n):
    if a[i] < m:
        sec = max(a[i], sec)

c = a.count(m)

if c == 1:
    for i in range(n):
        if a[i]==m:
            ans.append(sec)
        else:
            ans.append(m)
else:
    for i in range(n):
        if a[i]==m:
            if c>0:
                ans.append(m)
                c -= 1
            else:
                ans.append(sec)
        else:
            ans.append(m)

for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
import heapq
n = int(input())
q = []
for i in range(n):
  heapq.heappush(q, [-int(input()), i])
mx_1, idx = heapq.heappop(q)
mx_2, _ = heapq.heappop(q)
for i in range(n):
  if i == idx:
    print(-mx_2)
  else:
    print(-mx_1)

Submission status: Accepted

Solution code:
count = int(input())
nlist = []
for i in range(count):
    a = int(input())
    nlist.append(a)
mlist = tuple(nlist)
biggest = max(mlist)
nlist.remove(biggest)
c = max(nlist)

for i in range(count):
    if mlist[i] == biggest:
        print(c)
    else:
        print(biggest)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

m = max(a)
l = [m] * n
index = a.index(m)
a.remove(m)
nm = max(a)
l[index] = nm
for j in range(0, n):
    print(l[j])

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
A = np.array([int(input()) for i in range(n)])
idxs = np.argsort(A)
m1 = A[idxs[-1]]
m2 = A[idxs[-2]]
for i in range(n):
  if i != idxs[-1]:
    print(m1)
  else:
    print(m2)

Submission status: Accepted

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

sort_A = sorted(A)
max = sort_A[N - 1]
sec = sort_A[N - 2]

count = A.count(max)

if count == 1:
  p = A.index(max)
  
  for i in range(p):
    print(max)
  
  print(sec)
  
  for j in range(p,N - 1):
    print(max)

else:
  for k in range(N):
    print(max)

Submission status: Accepted

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

sorted_num = sorted(number_list)
number_max = sorted_num[-1]
number_second_max = sorted_num[-2]

if number_max == number_second_max:
  output_always_max = True
else:
  output_always_max = False

for number in number_list:
  if output_always_max:
    print(str(number_max))
  else:
    if number == number_max:
      print(str(number_second_max))
    else:
      print(str(number_max))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
if len(R) >= 2:
  max_v2 = R[1]
else:
  max_v2 = R[0]
R2 = sorted(A, reverse=True)
if R2[0] == R2[1]:
  signal = 1
else:
  signal = 0
  
for i in range(N):
  if A[i] == max_v and signal == 0:
    print(max_v2)
  else:
    print(max_v)

Submission status: Accepted

Solution code:
N=int(input())
I=[int(input()) for i in range(N)]
r=max(I)
if I.count(r)>=2:
	for j in range(N):
		print(r)
else:
	for k in range(N):
		X=int(I[k])
		if X!=r:
			print(r)
		else:
			I.remove(I[k])
			print(max(I))
			I.insert(k,X)