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)]
ma=max(a)
aa=sorted(a,reverse=True)
for i in a:
    if i !=ma:
        print(ma)
    else:
        print(aa[1])

Submission status: Accepted

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

Ls = sorted(L, reverse=True)
for i in range(N):
    if L[i] == Ls[0]:
        print(Ls[1])
    else:
        print(Ls[0])

Submission status: Accepted

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

global_max = max(a)
count = 0
for i in range(n):
    if a[i] == global_max:
        count += 1
    if count == 2:
        break

for i in range(n):
    if a[i] == global_max:
        if count == 1:
            print(max(a[:i] + a[i + 1:]))
        else:
            print(global_max)
    else:
        print(global_max)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
li = []
for i in range(n):
    li.append(ni())
sli = sorted(li)
for i in range(n):
    if sli[-1] != li[i]:
        print(sli[-1])
    else:
        print(sli[-2])

Submission status: Accepted

Solution code:
n = int(input())
arr = [int(input()) for _ in range(n)]
sorted_arr = sorted(arr, reverse=True)
result = []

for a in arr:
  multi_same_num_flag = False
  for m in sorted_arr:
    if m > a:
      result.append(str(m))
      break
    elif m == a:
      if not multi_same_num_flag:
        multi_same_num_flag = True
        continue
      else:
        result.append(str(m))
        break
    elif m < a:
      result.append(str(m))
      break


print('{}'.format('\n'.join(result)))

Submission status: Accepted

Solution code:
import math
import sys
import numpy as np
from collections import defaultdict, deque, Counter 
from itertools import accumulate, product, permutations,combinations, combinations_with_replacement
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd

max_value = 1000000000
min_value = -1000000000
sys.setrecursionlimit(max_value)


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


argmax = np.argmax(a_list)
max_value = np.max(a_list)
second_max_value = np.max(a_list[:argmax] + a_list[argmax+1:])

for i in range(n):
    if i == argmax:
        print(second_max_value)
    else:
        print(max_value)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
li = list(int(stdin.readline().rstrip()) for _ in range(n))
li_to = sorted(li)
one = li_to[-1]
two = li_to[-2]
for i in range(n):
    if one == li[i]:
        print(two)
    else:
        print(one)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
a_m = max(a)
a_i = a.index(a_m)
a.sort()
for i in range(len(a)):
  if i == a_i:
    print(a[-2])
  else:
    print(a_m)

Submission status: Accepted

Solution code:

N = int(input())

A = []

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

maxA=max(A)
maxAi=A.index(maxA)

A[maxAi] = 0
maxA2 = max(A)

for i in range(N):
    if i == maxAi :
        print(maxA2)
    else :
        print(maxA)

Submission status: Accepted

Solution code:
N=int(input())
l=[]
for i in range(N):
  l.append(int(input()))
l_max=max(l)
i=l.index(l_max)
if i==0:
  l1=l[1:]
  print(max(l1))
  for a in range(N-1):
    print(l_max)
elif i==N:
  l1=l[:N]
  for a in range(N-1):
    print(l_max)
  print(max(l1))
else:
  l1=l[:i]+l[i+1:]
  for a in range(i):
    print(l_max)
  print(max(l1))
  for a in range(N-i-1):
    print(l_max)

Submission status: Accepted

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

for i in range(N):
  if i == A[0][1]:
    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()))
    
A_sorted = sorted(A)
A_max1 = A_sorted[-1]
A_max2 = A_sorted[-2]

if A_max1 == A_max2:
    for i in range(N):
        print(A_max1)
else:
    max_idx = A.index(A_max1)
    for i in range(N):
        if i==max_idx:
            print(A_max2)
        else:
            print(A_max1)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LIN(N)
    A_ = sorted(A,reverse = True)
    A_1 = A_[0]
    A_2 = A_[1]
    for a in A:
        if a == A_1:
            print(A_2)
        else:
            print(A_1)
    



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
A = sorted([(int(input()), i) for i in range(n)],
           key=lambda a: -a[0])
for i in range(n):
    j = 0
    while A[j][1] == i:
        j += 1
    print(A[j][0])

Submission status: Accepted

Solution code:
n=int(input())
a_list=[int(input()) for i in range(n)]
a_sort=sorted(a_list)
a1=a_sort[-1]
a2=a_sort[-2]

for a in a_list:
    if a==a1:
        print(a2)
    else:
        print(a1)

Submission status: Accepted

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

maxa = 0
maxa1 = 0
maxcnt = 0
for i in range(n):
    ai = int(input())
    a.append(ai)
    if maxa < ai:
        maxa1 = maxa
        maxa = ai
        maxcnt = 0
    elif maxa == ai:
        maxcnt += 1
    elif maxa1 < ai:
        maxa1 = ai

for i in range(n):
    if a[i] == maxa:
        if maxcnt > 0:
            print(maxa)
        else:
            print(maxa1)
    else:
        print(maxa)

Submission status: Accepted

Solution code:
n = int(input())
nums = [int(input()) for _ in range(n)]
sorted_nums = sorted(nums)
for num in nums:
    if num < sorted_nums[-1]:
        print(sorted_nums[-1])
    else:
        print(sorted_nums[-2])

Submission status: Accepted

Solution code:
my_max=0
my_sec=0
cnt=0
n=int(input())
a=[0]*n
r_n =range(n)
for i in r_n:
  a[i]=int(input())
  if my_max<a[i]:
    my_max=a[i]
  elif my_sec<a[i]:
    my_sec=a[i]
    
for i in r_n:
  if my_max==a[i]:
    cnt+=1
    
for i in r_n:
  if my_sec!=0:
    if my_max!=a[i]:
      print(my_max)
    elif cnt>1:
      print(my_max)
    else:
      print(my_sec)
  else:
    print(my_max)

Submission status: Accepted

Solution code:
#全体の最大値が入っているときは、それが部分列の最大値になるので、わざわざ計算しなくて良い
#こういうことに先気づかないと、TLEになる
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))

a_max = max(a)
max_idx = a.index(a_max)
c = a.count(a_max)

for i in range(n):
  if i!=max_idx:
    print(a_max)
  elif i==max_idx and c>=2:
    print(a_max)
  else:
    a.remove(a[i])
    print(max(a))

Submission status: Accepted

Solution code:
import math
import copy
import sys
import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList



# ===CODE===

n = getInputNum()

a = getSomeInputInt(n)

sorted_a= sorted(a, reverse=True)

maxNum = sorted_a[0]
second = sorted_a[1]

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

Submission status: Accepted

Solution code:
r=[int(input()) for _ in range(int(input()))]
maxValue=max(r)

r2=r[:]
r2.remove(maxValue)
nextValue=max(r2)

for item in r:
  print(maxValue if item!=maxValue else nextValue)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
one=max(a)
two=max(a[:a.index(one)]+a[a.index(one)+1:])
for i in range(n):
    print(two if a[i]==one else one)

Submission status: Accepted

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

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

p = a.index(max(a))

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

Submission status: Accepted

Solution code:
import copy

N = int(input())

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

m = max(A)
flag = 1
for n in range(N):
    if flag == 1 and A[n] == m:
        t = copy.deepcopy(A)
        del t[n]
        print(max(t))
        flag = 0
        continue

    print(m)

Submission status: Accepted

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

k = [i for i, x in enumerate(a) if x == m]

if len(k)>=2:
	for i in a:
		print(m)
else:
	b = []
	b += a
	mi = b.index(m)
	b.pop(mi) 
	m2 = max(b)
	for i in a:
		if i != m:
			print(m)
		else:
			print(m2)

Submission status: Accepted

Solution code:
import copy

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

chinpo = max(A)
B = copy.copy(A)
B.remove(max(A))
chinchin = max(B)

for i in range(A.index(max(A))):
    print(chinpo)
print(chinchin)
for i in range(A.index(max(A))+1,N):
    print(chinpo)

Submission status: Accepted

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

for i in range(N):
  i = int(input())
  A.append(i)
  
ma = max(A)
sa = sorted(A)

for k in range(N):
  if ma != A[k]:
    print(ma)
  else:
    print(sa[-2])

Submission status: Accepted

Solution code:
n = int(input())
arr = []
queue = []
from heapq import heappush, heappop
for i in range(n):
    a = int(input())
    heappush(queue, -a)
    arr.append(a)
first = -heappop(queue)
second = -heappop(queue)
for a in arr:
    print(first if a != first else second)

Submission status: Accepted

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

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

SA = sorted(A)
mx = max(A)

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

Submission status: Accepted

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

max = max(a)
max2 = sorted(a)[-2]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
A=[int(input())for _ in range(n)]
M=max(A)
m=sorted(A)[-2]
for i in range(n):
    a=A[i]
    if a<M:
        print(M)
    else:
        print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N =int(input())
A = [int(input()) for i in range(N)]
mx1=max(A)
mx1p = A.index(max(A))
Awomax=A
Awomax[mx1p]=0
mx2=max(Awomax)
ans = [mx1]*N
ans[mx1p] = mx2
for i in range(N):
    print(ans[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from copy import deepcopy

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

B = deepcopy(A)
B.sort(reverse=1)
max_a = B[0]
max_b = B[1]

if A.count(max_a) == 1:
	for a in A:
		if a == max_a:
			print(max_b)
		else:
			print(max_a)
else:
	for a in A:
		print(max_a)

Submission status: Accepted

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

c = b.index(max(b))
b.sort(reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
n = int(input())
a_list = [ int(input()) for _ in range(n)]
max_val = max(a_list)
index = [a_list.index(max_val)]
tmp_list = copy.copy(a_list)
for i, a in enumerate(a_list):
  if 2 <= len(index):
    print(max_val)
  elif i in index:
    tmp_list.pop(i)
    print(max(tmp_list))
    tmp_list = copy.copy(a_list)
  else:
    print(max_val)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
max_A = max(A)
max_num = 0
for i in range(N):
    if A[i] == max_A:
        # 最大値が複数ある場合の計算削減
        max_num += 1
        if max_num > 1:
            print(max_A)
        else:
            print(max(A[:i] + A[i + 1:]))
    else:
        print(max_A)

Submission status: Accepted

Solution code:
n = int(input())
a_lst = [0]*n
a_lst[0] = int(input())
a_lst[1] = int(input())
if a_lst[0] >= a_lst[1]:
    max = 0
    sec_max = 1
else:
    max = 1
    sec_max = 0

for i in range(2, n):
    a_lst[i] = int(input())
    if a_lst[i] > a_lst[max]:
        max = i
    elif a_lst[i] > a_lst[sec_max]:
            sec_max = i

for i in range(n):
    if i == max:
        print(a_lst[sec_max])
    else:
        print(a_lst[max])

Submission status: Accepted

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

newList = sorted(A,reverse=True)

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

Submission status: Accepted

Solution code:
import math


def solve():
    n = int(input())
    al = [int(input()) for _ in range(n)]
    l = al[:]
    l.sort()
    if len(l) == 1:
        f, s = l[0], l[0]
    else:
        f, s = l[-1], l[-2]
    for a in al:
        if a == f:
            print(s)
        else:
            print(f)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

max_1,max_2 = sorted(Alist,reverse=True)[:2]
for A in Alist:
    if A==max_1:
        print(max_2)
    else:
        print(max_1)

Submission status: Accepted

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

s=sorted(listA,reverse=True)[:2]
for i in listA:
    if s[0]==i:
        print(s[1])
    else:
        print(s[0])

Submission status: Accepted

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

L = [0] * (200000+1)
R = [0] * (200000+1)

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

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

#print(L)
#print(R)

for i in range(N):
    ans = max(L[i], R[i+1])
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
tmp = 0
for i in range(N):
    if A[i] > A[tmp]:
        tmp = i
maxA = A[tmp]
answer = [maxA]*N
B = sorted(A)
A[tmp] = -float("inf")
C = sorted(A)
answer[tmp] = C[-1]

print(*answer, sep="\n")

Submission status: Accepted

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

n = int(input())
l = []
for _ in range(n):
	l.append(int(input()))
p = sorted(l)
fm = p[-1]
sm = p[-2]
if fm == sm:
	for _ in range(n):
		print(fm)
else:
	for i in range(n):
		if l[i] == fm:
			print(sm)
		else:
			print(fm)

Submission status: Accepted

Solution code:
import copy
N = int(input())
A = list()
for i in range(N):
    A.append(int(input()))
s = sorted(A)[::-1]
m1 = s[0]
m2 = s[1]

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

Submission status: Accepted

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

max_value = max(A)
number = A.count(max_value)

if number > 1:
    for j in range(N):
        print(max_value)
else:
    position = A.index(max_value)
    A.remove(max_value)
    for j in range(N):
        if j == position:
            print(max(A))
        else:
            print(max_value)

Submission status: Accepted

Solution code:
N = int(input())
L = []
for i in range(N):
  k = int(input())
  L.append([k,i])
L.sort()
for i in range(N):
  if i == L[N-1][1]:
    print(L[N-2][0])
  else:
    print(L[N-1][0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
p = A.index(max(A))
m1, m2 = sorted(A, reverse=True)[:2]

for i in range(N):
    if i == p:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
p = A.index(max(A))
A.sort(reverse=True)
m1, m2 = A[0], A[1]

for i in range(N):
    if i == p:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
m = max(A)
p = A.index(m)
A.remove(m)
n = max(A)

for i in range(N):
    if i == p:
        print(n)
    else:
        print(m)

Submission status: Accepted

Solution code:
n = int(input())
a = []
a1 = a2 = 0
for i in range(n):
    ai = int(input())
    a.append(ai)
    if ai > a1:
        a1, a2 = ai, a1
    elif ai > a2:
        a2 = ai

for i in range(n):
    if a[i] == a1:
        print(a2)
    else:
        print(a1)

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = list(map(int, inputs))
    B = copy.copy(A)
    B.sort()
    first_num = B[-1]
    second_num = B[-2]
    ret = ''
    for a in A:
        if a == first_num:
            ret += str(second_num) + '\n'
        else:
            ret += str(first_num) + '\n'
    return ret.strip()


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
max_num = (0,0) #(数値,idx)
max_candi = (0,0) #(数値,idx)
for i in range(N):
    A = int(input())
    if max_candi[0] < A and max_num[0] < A:
        max_candi = max_num
        max_num = (A,i)
    elif max_candi[0] < A:
        max_candi = (A,i)

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

Submission status: Accepted

Solution code:
import numpy as np

N=int(input())
A=[]
for i in range(N):
  A.append(int(input()))
  
m1=np.max(A)
m1i=np.argmax(A)

A.remove(m1)
m2=np.max(A)

for i in range(N):
  if i!=m1i:
    print(m1)
  else:
    print(m2)

Submission status: Accepted

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

Submission status: Accepted

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

reverse_A = sorted(A, reverse=True)
max1 = reverse_A[0]
max2 = reverse_A[1]

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

Submission status: Accepted

Solution code:
N = int(input())
num_list = [int(input()) for i in range(N)]
max_num = max(num_list)
max_num_num = num_list.count(max_num)

for cnt in range(N):
  if num_list[cnt] == max_num and max_num_num == 1:
    print(max(num_list[0:cnt] + num_list[cnt+1:]))
  else:
    print(max_num)

Submission status: Accepted

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
b = a[:]
mx = max(b)
b.remove(mx)
mx2 = max(b)

for t in a:
    if t == mx:
        print(mx2)
    else:
        print(mx)

Submission status: Accepted

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

Submission status: Accepted

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

pre_max = 0
pre_max_2 = 0
forward = [0]
backward = [0]
for ii in range(1, N):
    pre_max = max(pre_max, A[ii-1])
    forward.append(pre_max)
    pre_max_2 = max(pre_max_2, A[-ii])
    backward.append(pre_max_2)

backward.reverse()

for ii in range(N):
    print(max(forward[ii], backward[ii]))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A_lis = [int(input()) for i in range(N)]
A_lis_sort = sorted(enumerate(A_lis),key = lambda x:x[1])
max_index = A_lis_sort[-1][0] 
for i in range(N):
  if i == max_index:
    print(A_lis_sort[-2][1])
  else:
    print(A_lis_sort[-1][1])

Submission status: Accepted

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

k = max(A)
if A.count(k) >= 2:
    for i in range(n):
        print(k)
else:
    for i in range(n):
        if A[i] < k:
            print(k)
        else:
            A[i] = 0
            print(max(A))

Submission status: Accepted

Solution code:
N = int(input())

nums = [int(input()) for x in range(N)]

a = sorted(nums)[-1]#max(nums)
b = sorted(nums)[-2]#max(nums.remove(max_num))



if a == b:
    for _ in nums:
        print(a)
else:
    for x in [b if x == a else a for x in nums]:
        print(x)

Submission status: Accepted

Solution code:
import sys
import copy
def input():
	return sys.stdin.readline().rstrip()
def main():
	N = int(input())
	A = [int(input()) for _ in range(N)]
	B = list(set(A))
	if (len(B) == 1) or (A.count(B[-1]) > 1):
		for i in range(N):
			print(B[-1])
	else :
		for i in range(N):
			if A[i] == B[-1]:
				print(B[-2])
			else:
				print(B[-1])
if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
N = int(input())

## no1,2の値を格納
no1_value = 0
no2_value = 0
for n in range(N):
  a = int(input())
  if a > no1_value:
    no1_value = a
    no1_key = n
  elif a > no2_value:
    no2_value = a
    no2_key = n


## 結果の出力
for n in range(N):
  if n == no1_key:
    print(no2_value)
  else:
    print(no1_value)

Submission status: Accepted

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

max_val = max(A)
count = A.count(max_val)

subset = list(set(A))
if len(subset) > 1:
  subset.remove(max_val)
  max_val_2 = max(subset)

for i, num in enumerate(A):
  if num < max_val:
    print(max_val)
  else:
    if count > 1:
      print(max_val)
    else:
      print(max_val_2)

Submission status: Accepted

Solution code:
n=int(input())
#l=[int(input()) for i in range(n)]
l=[]
mydic={}
for i in range(n) :
  s=int(input())
  l.append(s)
  if not s in mydic.keys() :
    mydic[s]=1
  else :
    mydic[s]=mydic[s]+1
l2=sorted(l,reverse=True)
#print(l)
#print(mydic)
mx=l2[0]
for i in range(n) :
  if l[i]==mx :
    if mydic[mx]==1 :
      print(l2[1])
    else:
      print(mx)
  else :
    print(mx)

Submission status: Accepted

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

if A.count(B) == 1:
    for i in range(0,N):
        if A[i] == B:
            A[i] = 0
            print(max(A))
        else:
            print(B)
else:
    for i in range(0,N):
        print(B)

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):
    print(b[0] if a[i] != b[0] else b[1])

Submission status: Accepted

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

x = b[0]
y = b[1]

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

Submission status: Accepted

Solution code:
import glob
import numpy as np
import collections


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\134\\C'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'


class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class C(Common):

    def resolve(self):

        seq_len = int(self.input_data())
        seq = np.zeros(seq_len, dtype=np.int)
        for i in range(seq_len):
            seq[i] = int(self.input_data())

        max_num = np.max(seq)
        times = collections.Counter(seq)[max_num]

        if times >= 2:
            for i in range(seq_len):
                print(str(max_num))
        else:
            for i in range(seq_len):
                if seq[i] != max_num:
                    print(str(max_num))
                else:
                    print(np.max(np.hstack((seq[0:i], seq[i+1:seq_len]))))


solver = C(REL_PATH)
solver.exec_resolve()

Submission status: Accepted

Solution code:
import copy
n = int(input())
l = []
for _ in range(n):
  l.append(int(input()))
m = max(l)
k = copy.copy(l)
k.remove(m)
m2 = max(k)
for i in range(0,n):
    if l[i] != m:
      print(m)
    else:
      print(m2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
sorted_A = sorted(A, reverse=True)

max_A = sorted_A[0]

for a in A:
    if max_A != a:
        print(max_A)
    else:
        print(sorted_A[1])

Submission status: Accepted

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

def solve():
    N = int(input())
    A = []
    max1_num, max2_num = 0, 0
    for i in range(N):
        a = int(input())
        A.append(a)

        if a >= max1_num:
            max1_num, max2_num = a, max1_num
        elif a > max2_num:
            max2_num = a

    """方針
    最大値と、2番めに大きい値を覚えておく。
    除く値が最大値のとき、答えは2番めに大きい値。それ以外は最大値が答え。
    """

    for a in A:
        if a == max1_num:
            print(max2_num)
        else:
            print(max1_num)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

max_d = [-1, -1]
semi_max_d = [-1, -1]

for i in range(n):
    if a[i] > max_d[1]:

        if max_d[1] > semi_max_d[1]:
            semi_max_d[0], semi_max_d[1] = max_d[0], max_d[1]

        max_d[0], max_d[1] = i, a[i]
    else:
        if a[i] > semi_max_d[1]:
            semi_max_d[0], semi_max_d[1] = i, a[i]

[print(semi_max_d[1]) if max_d[0] == i else print(max_d[1]) for i in range(n)]

Submission status: Accepted

Solution code:
N=int(input())
n1=0
n2=0
a=[]
for i in range(N):
    A=int(input())
    a.append(A)
    n2=max(n2,min(n1,A))
    n1=max(n1,A)
for i in range(N):
    if a[i]==n1:
        print(n2)
    else:
        print(n1)

Submission status: Accepted

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

for i in range(n):
  num = int(input())
  array.append(num)

sorta = sorted(array)
max1 = sorta[-1]
max2 = sorta[-2]

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