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 = []
r = 0
for i in range(N):
    A.append((int(input()), i))

A_sorted = sorted(A, reverse=True, key=lambda x: x[0])
A_sorted = list(enumerate(A_sorted))
A = sorted(A_sorted, key=lambda x: x[1][1])

for r, t in A:
    a, _ = t
    if r == 0:
        print(A_sorted[1][1][0])
    else:
        print(A_sorted[0][1][0])

Submission status: Accepted

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

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

_max = max(a)
max_idx = a.index(_max)
a.remove(_max)
second = max(a)
for i in range(n):
    if i == max_idx:
        print("{}".format(second))
    else:
        print("{}".format(_max))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N = int(input())

    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)
    ii = A.index(max(A))
    m = max(A)
    A.pop(ii)
    m2 = max(A)
    
    for i in range(N):
        if i == ii:
            print(m2)
        else:
            print(m)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
A = []
for _ in range(n):
  x = int(input())
  A.append(x)
standard = max(A)
counter = A.count(max(A))
for i in range(n):
  if A[i] != standard:
    print(standard)
  elif counter >=2:
    print(standard)
  else:
    temp = 0
    for t in range(n):
      if t != i:
        if A[t] >= temp:
          temp = A[t]
    print(temp)

Submission status: Accepted

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

b = sorted(a)
max1 = b[N-1]
max2 = b[N-2]

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

Submission status: Accepted

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

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

MAX = max(A)
MAX_i = numpy.argmax(A)
tmp = A.pop(MAX_i)
MAXsecond = max(A)
A.insert(MAX_i, tmp)

for i in range(0, N):
    if A[i] == MAX:
        print(MAXsecond)
    else:
        print(MAX)

Submission status: Accepted

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

A_l = [A[0]] #左から数えた最大値
A_r = [A[N-1]] #右から数えた最大値

for i in range(1,N-1):
    A_l.append(max(A_l[i-1],A[i]))

for i in range(1,N-1):
    A_r.append(max(A_r[i-1],A[-(i+1)]))

ans =[]
ans.append(A_r[N-2])
for k in range(N-2):
    ans.append(max(A_l[k],A_r[-(k+2)]))

ans.append(A_l[N-2])

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

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
m=max(a)
c=a.count(m)
i=a.index(m)
if(c!=1):
    for j in range(n):
        print(m)
else:
    a.remove(m)
    mm=max(a)
    for j in range(n):
        if(j==i):
            print(mm)
        else:
            print(m)

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input())

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

s_A = sorted(A, reverse=True)

max_a, second_a = s_A[0], s_A[1]

for i in range(n):
    if A[i] == max_a:
        print(second_a)
    else:
        print(max_a)

Submission status: Accepted

Solution code:
a = input()
a = int(a)

suuretu_list = []
kari_list = []

for i in range(a):
    b = int(input())
    suuretu_list.append(b)
    kari_list.append(b)

kari_list = sorted(kari_list)

c = max(suuretu_list)

d = suuretu_list.index(c)

for u in suuretu_list:
    if u != c:
        print(c)
    else:
        print(kari_list[-2])

Submission status: Accepted

Solution code:
def main():
  number_cnt = int(input())
  max_1 = 0
  max_2 = 0
  max_1_index = 0
  for i in range(number_cnt):
    tmp = int(input())
    if tmp > max_1:
      max_2 = max_1
      max_1 = tmp
      max_1_index = i
    elif tmp > max_2:
      max_2 = tmp
  for i in range(number_cnt):
    if i == max_1_index:
      print(max_2)
    else:
      print(max_1)
    
main()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
m = max(A)
A_i = A[:]
A_i.remove(m)
m_i = max(A_i)
for i in range(N):
    if A[i] == m:
        print(m_i)
    else:
        print(m)

Submission status: Accepted

Solution code:
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]

a = list(itertools.accumulate(A, max))
b = list(itertools.accumulate(A[::-1], max))[::-1]

for i in range(len(A)):
    r = 0
    if 0 <= i - 1 < N:
        r = max(r, a[i - 1])
    if 0 <= i + 1 < N:
        r = max(r, b[i + 1])
    print(r)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

b = sorted(a)

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

Submission status: Accepted

Solution code:
# C
N = int(input())
A=[]
for i in range(N):
    A.append(int(input()))
max1 = max(A)#一番手
max_index = A.index(max1)#index
A.remove(max1)
max2 = max(A)

for i in range(N):
    if i==max_index:
        print(max2)
    else:
        print(max1)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    li = [int(input()) for _ in range(n)]

    sorted_li = sorted(li)

    max_index = li.index(sorted_li[-1])

    for i in range(n):

        if i == max_index:
            print(sorted_li[-2])

        else:
            print(sorted_li[-1])

resolve()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
lmax = [0]
rmax = [0]
for i in range(N-1):
  lmax.append(max(lmax[i],A[i]))
  rmax.append(max(rmax[i],A[N-1-i]))
 
rmax = rmax[::-1]

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

Submission status: Accepted

Solution code:
n=int(input())
lst=[int(input()) for x in range(n)]
M=sorted(set(lst))[-1]
num=lst.count(M)
if num>=2:
  for x in lst:
    print(M)
else:
  m=sorted(set(lst))[-2]
  for x in lst:
    if x==M:
      print(m)
    else:
      print(M)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in [0] * N ]
M = max(A)
m = sorted(A)[-2]
for i in A:
  if i == M:
    print(m)
  else:
    print(M)

Submission status: Accepted

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

A1 = 0
A2 = 0
index = -1
for i in range(N):
    if A1 == 0:
        A1 = max(A1,A[i])
        index = i
    else:
        tmp = max(A2,A[i])
        if A1 <= A[i]:
            A2 = A1
            A1 = A[i]
            index = i
        elif A2 <= tmp:
            A2 = tmp

if A1 == A2:
    for i in range(N):
        print(A1)
else:
    for i in range(N):
        if i == index:
            print(A2)
        else:
            print(A1)

Submission status: Accepted

Solution code:
# 2019/07/20
# AtCoder Beginner Contest 134 - C

# Input
n = int(input())

# Input and Search Max and 2nd Max
a = list()
amax1st = -1
amax2nd = -1
for i in range(n):
    wka = int(input())
    if wka >= amax1st:
        amax2nd = amax1st
        amax1st = wka
    elif wka >= amax2nd:
        amax2nd = wka
        
    a.append(wka)

for i in range(n):
    if a[i] == amax1st:
        ans = amax2nd
    else:
        ans = amax1st
    # Output
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())

max1 = 0
max2 = 0
max1_id = 0
for i, a in enumerate(range(n)):
  a = int(input())
  if a > max1:
    max2 = max1
    max1 = a
    max1_id = i
  elif a > max2:
    max2 = a

for i in range(i+1):
  if i == max1_id:
    print(max2)
  else:
    print(max1)

Submission status: Accepted

Solution code:
N=int(input())
max1=0
second_max=0
ind=[]
for i in range(N):
  t=int(input())
  if second_max < t:
    if max1<t:
        second_max=max1
        max1=t
        ind.clear()
        ind.append(i)
    elif max1==t:
        second_max=max1
        ind.append(i)
    else:
        second_max=t
if len(ind)==1:
    for i in range(N):
      if i == ind[0]:
        print(second_max)
      else:
          print(max1)
else:
    for i in range(N):
          print(max1)

Submission status: Accepted

Solution code:
import copy

N = int(input())

A = []

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

max_A = max(A)

B = copy.deepcopy(A)

B.remove(max_A)

second_A = max(B)

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

Submission status: Accepted

Solution code:
N=int(input())
A = [int(input()) for i in range(N)]
B=sorted(A)
big=max(A)
flag=0
big2=B[-2]
for i in A:
    if i==big:
        print(big2)
    else:
        print(big)

Submission status: Accepted

Solution code:
n = int(input())
a = []
mx12 = [0,0]
for i in range(1,n+1):
    a.append(int(input()))
    if min(mx12) <= a[-1]:
        mx12.sort()
        mx12[0] = mx12[1]
        mx12[1] = a[-1]
mx12.sort()
for j in range(1,n+1):
    if a[j-1] == mx12[1]:
        print(mx12[0])
    else:
        print(mx12[1])

Submission status: Accepted

Solution code:
from sys import stdin
import heapq

N = int(stdin.readline().rstrip())
A = [int(input()) for i in range(N)]


tmp = heapq.nlargest(2, A)

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
A_max = max(A)
A_max_count = A.count(A_max)
if A_max_count != N:
  a_ = A[:]
  a_ = sorted(a_,reverse = True)
  A_next_max = a_[A_max_count]
else:
  A_next_max = A_max_count

for i in range(N):
  tmp = A[i]
  if tmp != A_max:
    print(A_max)
  else:
    if A_max_count == 1:
      print(A_next_max)
    else:
      print(A_max)

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

A_max = max(A)
C = A.count(A_max)

if C>=2:
    for l in range(N):
        print(A_max)
else:
    p = A.index(A_max)
    B = sorted(A,reverse=True)
    for k in range(N):
        if k==p:
            print(B[1])
        else:
            print(A_max)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    
    # A_ = np.array(A)
    # print(A)
    V = np.argmax(A)
    # print(V)
    MAX = max(A)
    # print(V)
    for _ in range(N):
        if _ == V:
            print(max(A[0:V]+A[V+1:N]))
        else:
            print(MAX)
                

    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
R=[]
max_ = 0
for i in range(N):
    max_ = max(max_, A[i])
    R.append(max_)
L=[]
max_ = 0
for i in reversed(list(range(N))):
    max_ = max(max_, A[i])
    L.append(max_)
L = list(reversed(L))
print(L[1])
for i in range(1, N-1):
    print(max(R[i-1], L[i+1]))
print(R[N-2])

Submission status: Accepted

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

for i in range(0, N):
    ai = int(input())
    A.append(ai)
    if max_a < ai:
        max_a = ai
        max_index = i

A.remove(max_a)

for i in range(0, N):
    if i != max_index:
        print(max_a)
    else:
        print(max(A))

Submission status: Accepted

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

if A[0] > A[1]:
    max_1, max_2 = A[0],A[1]
else:
    max_1, max_2 = A[1],A[0]

dict = {}
for i, a in enumerate(A):
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1
    if i >= 2:
        if a > max_1:
            max_2 = max_1
            max_1 = a
        elif a > max_2:
            max_2 = a

for a in A:
    if a == max_1:
        if dict[a] >= 2:
            print(max_1)
        else:
            print(max_2)
    else:
        print(max_1)

Submission status: Accepted

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

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

res = [str(max_value)] * N
res[max_index] = str(max(A))
print('\n'.join(res))

Submission status: Accepted

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

ans = []
cp = copy.copy(a) 
v_max = max(a)
cp.remove(v_max)
v_next = max(cp)

for i in a:
    #cp = a
    #print(i)
    if i == v_max:
        print(v_next)
    else:
        print(v_max)

#for i in a:
#    print(i)


#print(n)
#print(a)

Submission status: Accepted

Solution code:
import collections

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

a = collections.Counter(A)
a = sorted(a.items(), key=lambda x: -x[0])

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

Submission status: Accepted

Solution code:
N = int(input())

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

M1 = 0
M2 = 0

for i in range(N):
    if A[i] > M1:
        M1 = A[i]
    elif A[i] > M2:
        M2 = A[i]


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

Submission status: Accepted

Solution code:
n = int(input())
a = []
max_count = 0
maxi = 0
max_id = 0
for i in range(n):
  a.append(int(input()))
  if a[i]>maxi:
    max_count = 1
    max_id = i
    maxi = a[i]

  elif a[i]==maxi:
    max_count += 1
    
if max_count <= 1:
  for i in range(max_id):
    print(maxi)
  print(sorted(a, reverse=True)[1])
  for i in range(max_id + 1, n):
    print(maxi)
    
else:
  for i in range(n):
    print(maxi)

Submission status: Accepted

Solution code:
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
b=sorted(a)    
n_max=b[-1]
n_max2=b[-2]

for i in range(N):
    if a[i]==n_max:
        print(n_max2)
    else:
        print(n_max)

Submission status: Accepted

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

Submission status: Accepted

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

max1 = 0
max2 = 0

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

    if max1 < A[i]:
        max2 = max1
        max1 = A[i]

    elif max2 < A[i]:
        max2 = A[i]

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

Submission status: Accepted

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

a_sort = sorted(a)
max = a_sort[-1]
second = a_sort[-2]

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

Submission status: Accepted

Solution code:
n = int(input())

a = []
maximum = 0
second_maximum = 0
for i in range(n):
    input_num = int(input())
    a.append(input_num)
    if input_num > maximum:
        second_maximum = maximum
        maximum = input_num
    elif input_num > second_maximum:
        second_maximum = input_num
        
for a_num in a:
    if a_num == maximum:
        print(second_maximum)
    else:
        print(maximum)

Submission status: Accepted

Solution code:
N=int(input())
AN=[int(input()) for _ in range(N)]
ret=max(AN)
ANc=sorted(AN,reverse=True)
ret2=ANc[1]

for i in range(N):
    if ret != AN[i]:
        print(ret)
    else:
        print(ret2)

Submission status: Accepted

Solution code:
import copy

N = int(input())

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


max1 = max(A)

max_i = A.index(max1)
max2 = max(A[:max_i] + A[max_i+1:])


for i in range(N):
    if A[i] == max1:
        print(max2)

    else:
        print(max1)

Submission status: Accepted

Solution code:
N = int(input())
arr = []
for i in range(N):
  arr.append(int(input()))
max_inds = []
max_v = arr[0]
for i in range(N):
  if arr[i] > max_v:
    max_v = arr[i]
for i in range(N):
  if arr[i] == max_v:
    max_inds.append(i)
for i in range(N):
  if len(max_inds) >= 2:
    print(max_v)
  else:
    if i == max_inds[0]:
      cop = arr.copy()
      del cop[i]
      print(max(cop))
    else:
      print(max_v)

Submission status: Accepted

Solution code:
def calc(N, A):
    Amax = [0, 0]
    for a in A:
        if (a > Amax[0]):
            Amax[1] = Amax[0]
            Amax[0] = a
        elif (a > Amax[1]):
            Amax[1] = a
    result = ''
    for a in A:
        if (a == Amax[0]):
            result += str(Amax[1]) + '\n'
        else:
            result += str(Amax[0]) + '\n'
    return result


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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

n = input()
seq = [int(x) for x in sys.stdin.read().rstrip().split("\n")]
seq_max = max(seq)

# seq_max と同じ値を持つindexを探査
seq_max_indices = []
for i in range(0, len(seq)):
    if seq[i] == seq_max:
        seq_max_indices.append(i)

if len(seq_max_indices) == 1:
    seq_second_max = sorted(seq, reverse=True)[1]
    result = [str(seq_max) for x in range(len(seq))]
    result[seq_max_indices[0]] = str(seq_second_max)
    print("\n".join([str(x) for x in result]))
else:
    print("\n".join([str(seq_max) for x in range(len(seq))]))

Submission status: Accepted

Solution code:
N = int(input())
A_list = []
A_l = []
for i in range(N):
    A = int(input())
    A_list.append(A)
    A_l.append(A)
A_list.sort(reverse = True)

for j in range(N):
    if A_l[j] != A_list[0]:
        print(A_list[0])
    else:
        print(A_list[1])

Submission status: Accepted

Solution code:
N = int(raw_input())
A = [(int(raw_input()), i) for i in range(N)]
AS = sorted(A, key=lambda x:-x[0])
for i in range(N):
    if i != AS[0][1]:
        print AS[0][0]
    else:
        print AS[1][0]

Submission status: Accepted

Solution code:
import copy
n = int(input())
a = [int(input()) for _  in range(n)]
jisyo = {}
flag = False
if(a.count(max(a))!=1):
	flag = True
b = copy.deepcopy(a)
b.sort()
for i in a:
	if flag:
		print(b[-1])
	elif(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)]
m1, m2 = list(sorted(As, reverse=True))[:2]
for a in As:
  if a == m1:
     print(m2)
  else:
     print(m1)

Submission status: Accepted

Solution code:
#多行(1行目で行数)
n = int(input())
list_a = [int(input()) for i in range(n)]


ma = max(list_a)

i_ma = list_a.index(ma)
list_aa = list_a[:]
list_aa.pop(i_ma)

ma2 = max(list_aa)


# print(list_a)
# print(list_aa)
# print(ma, ma2)


for ai in list_a:
    if (ai == ma):
        print(ma2)
    else:
        print(ma)

Submission status: Accepted

Solution code:
n = int(input())

max_val = 0
sub_max_val = 0
max_count = 0
lst = []
for i in range(n):
    ai = int(input())
    lst.append(ai)
    if ai > max_val:
        sub_max_val = max_val
        max_val = ai
        max_count = 1
    elif ai == max_val:
        max_count += 1
    elif ai > sub_max_val:
        sub_max_val = ai

if max_count > 1:
    for i in range(n):
        print(max_val)
else:
    for i in range(n):
        if lst[i] == max_val:
            print(sub_max_val)
        else:
            print(max_val)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
m1 = max(a)
mi = a.index(m1)
m2 = max(a[:mi] + a[mi+1:])

for i in range(n):
    if i == mi:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
max1 = max(a)
ind = a.index(max1)
if ind == 0:
    a_ = a[1:len(a)]
elif ind == len(a)-1:
    a_ = a[0:len(a)-1]
else:
    a_ = a[0:ind] + a[ind+1:len(a)]
max2 = max(a_)
for i in range(n):
    if a[i] == max1:
        print(max2)
    else:
        print(max1)

Submission status: Accepted

Solution code:
a=[]
m1,m2=0,0
ct=0
t=input()
for i in range(t):
    n=input()
    a.append(n)
    if n>m1:
        m2=m1
        m1=n
        ct=i
    elif n>m2:
        m2=n
for i in range(t):
    if i==ct:
        print m2
    else:
        print m1

Submission status: Accepted

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

lis=sorted(li)
max1=lis[-1]
max2=lis[-2]
for i in li:
  if(i==max1):
    print(max2)
  else:
    print(max1)

Submission status: Accepted

Solution code:
N=int(input())
A = []
for n in range(N):
    A.append(int(input()))
import numpy as np
A_np = np.array(A)
A_max = A_np.max()
A_max_idx = A_np.argmax()
A_np_next = np.delete(A_np, A_max_idx)
A_next_max = A_np_next.max()
if A_max == A_next_max:
    for n in range(N):
        print(A_max)
else:
    for n in range(N):
        if n == A_max_idx:
            print(A_next_max)
        else:
            print(A_max)

Submission status: Accepted

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

def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

m = max(A)
maxindexlist = my_index_multi(A,m)

if len(maxindexlist) == 1:
    for i in range(N):
        if i != (maxindexlist[0]):
            print(m)
        else:
            A.pop(maxindexlist[0])
            print(max(A))
else:
    for i in range(N):
        print(m)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
a_max = max(a)
a_max_cnt = a.count(a_max)
a_max_i = a.index(a_max)

if a_max_cnt == 1:
  for i in range(n):
    if i==a_max_i:
      print(sorted(set(a))[-2])
    else:
      print(a_max)
else:
  for i in range(n):
    print(a_max)

Submission status: Accepted

Solution code:
def main():
  x = [int(input()) for _ in range(int(input()))]
  y = x[:]
  y.sort(reverse=True)

  for v in x:
    if v == y[0]:
      print(y[1])
    else:
      print(y[0])


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(0,n):
    o=int(input())
    l.append(o)
q=list(l)
q.sort(key=int,reverse=True)
for i in range(0,len(l)):
    if l[i]!=q[0]:
        print(q[0])
    else:
        print(q[1])

Submission status: Accepted

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

Submission status: Accepted

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

asort=sorted(a)
#print(asort)
for j in range(n):
    if a[j]!=asort[-1]:
        print(asort[-1])
    else:
        print(asort[-2])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a = arr[:]
arr.sort()

ma = arr[-1]
pma = arr[-2]

for x in a:
	if x == ma:
		print(pma)
	else:
		print(ma)

Submission status: Accepted

Solution code:
import numpy as np
from collections import defaultdict
from heapq import heappush, heappop
from math import ceil


def djkstra_adj_list(adj_list, src):
    dist = defaultdict(lambda: np.inf)
    dist[src] = 0

    prev = defaultdict(lambda: None)

    queue = []
    heappush(queue, (dist[src], src))

    while len(queue) > 0:
        dist_u, u = heappop(queue)
        vs = adj_list[u]
        for v, weight in vs:
            alt = dist_u + weight
            if alt < dist[v]:
                dist[v] = alt
                prev[v] = u
                heappush(queue, (alt, v))

    return dist, prev


def djkstra_adj_mat(adj_mat, src):
    dist = defaultdict(lambda: np.inf)
    dist[src] = 0

    prev = defaultdict(lambda: None)

    queue = []
    heappush(queue, (dist[src], src))

    while len(queue) > 0:
        dist_u, u = heappop(queue)
        vs = np.argwhere(adj_mat[u] > 0).flatten()
        for v in vs:
            weight = adj_mat[u, v]
            alt = dist_u + weight
            if alt < dist[v]:
                dist[v] = alt
                prev[v] = u
                heappush(queue, (alt, v))

    return dist, prev


def main():

    N = int(input())
    As = []
    for _ in range(N):
        A = int(input())
        As.append(A)
    As = np.array(As, dtype=np.int)

    i_max = np.argmax(As)

    A_max = As[i_max]
    if np.sum(As == A_max) > 1:
        for i in range(N):
            print(A_max)
    else:
        A_max2 = np.max(As[As != A_max])
        for i in range(N):
            if i == i_max:
                print(A_max2)
            else:
                print(A_max)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a_s_with_index = [(i, int(input())) for i in range(n)]
a_s = [a_i[1] for a_i in a_s_with_index]
a_s.sort()

for i, a_i in a_s_with_index:
    if  a_i == a_s[n-1]:
        a_max_i = n-2
    else:
        a_max_i = n-1

    print(a_s[a_max_i])

Submission status: Accepted

Solution code:
import sys
import numpy as np
from scipy.misc import comb
sys.setrecursionlimit(1000000)
 
n = int(input())

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

sort_a = sorted(a,reverse=True)

max_a = sort_a[0]
sec_a = sort_a[1]

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
A=[int(input()) for _ in range(n)]
B=sorted(A,reverse=True)
m1=B[0]
m2=B[1]
for a in A:
    if a==m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)
MAX1, MAX2 = B[-1], B[-2]

for i in A:
  if i == MAX1:
    print(MAX2)
  else:
    print(MAX1)

Submission status: Accepted

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

sorted_lst = sorted(lst)
max_1 = sorted_lst[-1]
max_2 = sorted_lst[-2]

for i in lst:
  if (i == max_1):
    print(max_2)
  else:
    print(max_1)

Submission status: Accepted

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

sorted_a_d = sorted(a_d.items(),key=lambda x:-x[1])
for i in range(N):
    if(sorted_a_d[0][0]!=i):
        print(sorted_a_d[0][1])
    else:
        print(sorted_a_d[1][1])

Submission status: Accepted

Solution code:
import sys

N = int(input())
aArr = list(map(int, sys.stdin))
tmpArr = sorted(aArr)
max = tmpArr[-1]
max2nd = tmpArr[-2]
for i in range(len(aArr)):
    if aArr[i] == max:
        print(max2nd)
    else:
        print(max)

Submission status: Accepted

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

a_l = []
for i in range(n):
    a_l.append(a[i][0])
a1 = sorted(a_l)
m1 = a1[-1]
m2 = a1[-2] 

for i in a_l:
    if i == m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    a = 0
    m = 0
    mi = 0
    mm = 0
    for i in range(N):
        a = int(input())
        if a > m:
            mm = m
            m = a
            mi = i
        elif a > mm:
            mm = a
    for i in range(N):
        if i == mi:
            print(mm)
        else:
            print(m)


main()

Submission status: Accepted

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

a_sort = sorted(a, key=lambda x: x[1], reverse=True)

for i, val in a:
    if i == a_sort[0][0]:
        print(a_sort[1][1])
    else:
        print(a_sort[0][1])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for n in range(N)]
tmp = A.copy()
A.sort()
fir, sec = A[N-1], A[N-2]
for n in range(N):
  if tmp[n] == fir:
    print(sec)
  else:
    print(fir)

Submission status: Accepted

Solution code:
n = int(input())
nums = [int(input()) for _ in range(n)]
max_num = max(nums)
max_cnt = len([i for i in nums if i == max_num])

for i in range(n):
  if nums[i] < max_num or max_cnt > 1:
    print(max_num)
  else:
    print(max(set(nums) - set([nums[i]])))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
maxidx = A.index(max(A))
Amax = max(A)
A.remove(Amax)
A2 = max(A)

for i in range(maxidx):
  print(Amax)
print(A2)
for i in range(maxidx+1,N):
  print(Amax)

Submission status: Accepted

Solution code:
import copy
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
tmp = copy.copy(a)
tmp.sort()
max_num = tmp[-1]
min_num = tmp[-2]
for i in range(n):
    if a[i] == max_num:
        print(min_num)
    else:
        print(max_num)

Submission status: Accepted

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

Submission status: Accepted

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

N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)
max_num = B[len(A)-1]

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input())  for i in range(n)]
b=list(a)
b.remove(max(a))
maxa=max(a)
maxb=max(b)
for i in range(n):
    if a[i] != maxa:
        print(maxa)
    else:
        print(maxb)