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:
from fractions import gcd
import math


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    a = [int(input()) for i in range(n)]
    m = max(a)
    mi = a.index(m)
    m2 = max(a[:mi] + a[mi+1:])
    for i in range(n):
        if a[i] == m:
            print(m2)
        else:
            print(m)
main()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
#s=input()
#l=list(map(int,input().split()))
N=int(input())
A=[]
B=[]
for i in range(N):
    a=int(input())
    A.append(a)
    B.append(a)
A.sort(reverse=True)
for i in range(N):
    if A[0]==B[i]:
        print(A[1])
    else:
        print(A[0])

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    s = sorted(A)
    for a in A:
        if a == s[-1]:
            print(s[-2])
        else:
            print(s[-1])
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for _ in range(n):
    x=int(input())
    a.append(x)
b=sorted(a)
p=b[-1]
q=b[-2]
cnt=0
for y in a:
    if y==p:
        cnt+=1
if cnt>=2:
    for i in range(n):
        print(p)
else:
    for i in range(n):
        if a[i]==p:
            print(q)
        else:
            print(p)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
B = [A[i] for i in range(N)]
B.sort()
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
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
a = [ni() for _ in range(n)]
b = [ai for ai in a]

first = max(a)
a.remove(first)
second = max(a)

for bi in b:
    print(first if bi != first else second)

Submission status: Accepted

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

sA = sorted(A)
for a in A:
    if a == sA[-1]:
        print(sA[-2])
    else:
        print(sA[-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[[int(input()),i]for i in range(n)]
a.sort()
c=a[-1][0]
d=a[-2][0]
e=a[-1][1]
for i in range(n):
  if i==e:print(d)
  else:print(c)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = [(int(input()), i) for i in range(n)]
a.sort(reverse=True)
if a[0][0] == a[1][0]:
    for i in range(n):
        print(a[0][0])
else:
    ans = [0]*n
    for ai, i in a:
        if ai == a[0][0]:
            ans[i] = a[1][0]
        else:
            ans[i] = a[0][0]
    for i in ans:
        print(i)

Submission status: Accepted

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


def main():
    N = int(input())
    A = [(int(input()), i) for i in range(N)]
    A.sort(reverse=True)
    for i in range(N):
        if A[0][1] == i:
            print(A[1][0])
        else:
            print(A[0][0])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = inp()
AA = [inp() for _ in range(N)]
x = sorted(AA)
M1 = x[-1]
M2 = x[-2]

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    n = int(input())
    arr = [0] * n
    for i in range(n):
        arr[i] = int(input())
    
    l = [0] * n
    r = [0] * n
    
    l[0] = arr[0]
    r[~0] = arr[~0]
    for i in range(1, n):
        l[i] = max(l[i - 1], arr[i])
        r[~i] = max(r[~(i - 1)], arr[~i])
    
    print(r[1])
    for i in range(1, n - 1):
        print(max(l[i - 1], r[i + 1]))
    print(l[~1])
    
    return 0

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
N = int(input())
A = [None]*N
mx = -1
mx2 = -1
for i in range(N):
	A[i] = int(input())
	if mx <= A[i]:
		mx2 = mx
		mx = A[i]
	elif mx2 < A[i]:
		mx2 = A[i]


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

Submission status: Accepted

Solution code:
import sys

n = int(input())
aaa = list(map(int, sys.stdin.readlines()))
bbb = [(a, i) for i, a in enumerate(aaa)]
bbb.sort()
am1, im1 = bbb[-1]
am2, im2 = bbb[-2]
for i in range(n):
    if i == im1:
        print(am2)
    else:
        print(am1)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 5 + 10)





def main():
    num = int(input())
    data = [int(input()) for i in range(num)]

    aaa = max(data)


    if data.count(aaa) >= 2:
        for i in range(num):
            print(aaa)
    else:
        bbb = 0
        for j in range(num):
            if data[j] == aaa:
                continue
            bbb = max(data[j], bbb)

        for i in range(num):
            if data[i] == aaa:
                print(bbb)
            else:
                print(aaa)





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)

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)[::-1]
mx = b[0]
mx2 = b[1]

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

Submission status: Accepted

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

Submission status: Runtime Error

Solution code:
sn = int(input())
arr = [int(input()) for _ in range(n)]
arr.sort()
mx = arr[-1]
sc = arr[-2]

for ele in arr:
    if ele == mx:
        print(sc)
    else:
        print(mx)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for i in rnage(n):
  a.append(int(input()))
print(max[1:])
m = max(a)
for i in range(1,n):
  if a[i] != m:
    print(m)
  else:
    print(max(a[:i],a[i+1:]))

Submission status: Runtime Error

Solution code:
N, D = map(int, input().split())
 
# 前から最適に配置せよ
# 一人目は, 1,...,D, D+1, D+2,...,2D+1 を監視
# 二人目は, 2D+2,..., 3D+2, ...,4D+2 を監視
# x人まで繰り返すと、1,...,x(2D+1)まで監視できる
 
# x(2D+1) > N を満たす最小のxは？
# x_min = ceil(N/(2D+1))
 
# ceil(B/A) = floor((A+B-1)/A)
print((N+2*D) // (2*D+1))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
 
# M_list = index(max(A_1,...,A_N))
# M = max(A)
# sub_M = sub_max(A)

# iがM_listに含まれるときにはsub_Mを出力
# それ以外ではMを出力

M = max(A)
sub_M = 0
for i in range(N):
  if i not in M_list:
    sub_M = max(sub_M, A[i])
    
M_list = []
for i in range(N):
  if A[i] == M: M_list.append(i)
    
for i in range(N):
  if i in M_list: print(sub_M)
  else: print(M)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))

ans = 'Yes'
for i in range(N-1, 0, -1):
  if A[i] > A[i-1]: A[i-1] -= 1
    if A[i] > A[i-1]:
      ans = 'No'
      break

print(ans)

Submission status: Runtime Error

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

l = []
r = []
l_max = 0
r_max = 0
for i in range(n):
    l_max = max(l_max, a_l[i])
    r_max = max(r_max, a_l[-i-1])
    l.append(l_max)
    r.append(r_max)
for i in range(n):
    if i == 0:
        t_l = 0
    else:
        t_l = l[i-1]
    if i == n-1:
        t_r = 0
    else:
        t_r = r[-i-2]
    print(max([t_l,t_r]))

Submission status: Runtime Error

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


l = []
r = []
l_max = 0
r_max = 0
for i in range(n):
    l_max = max(l_max, a_l[i])
    r_max = max(r_max, a_l[-i-1])
    l.append(l_max)
    r.append(r_max)
for i in range(n):
    if i == 0:
        t_l = 0
    else:
        t_l = l[i-1]
    if i == n-1:
        t_r = 0
    else:
        t_r = r[-i-2]
    print(max([t_l,t_r]))

Submission status: Runtime Error

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

# max(A_2,A_3,...,A_N)
# max(A_1,A_3,...,A_N)
# max(A_1,A_2,...,A_(N-1))

M_1 = max(A)
M_2 = max(A.replace(M_1, 0))

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

Submission status: Runtime Error

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

A = sorted(A)
print(sum(A[1:])

Submission status: Runtime Error

Solution code:
n=int(input())
a = [int(input()) for _ in range(n)]
b = max(l)
c = a.index(b)
for i in range(n):
        if i == c:
                print(max(sorted(a)[:n-1]))
        else:
                print(b)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

def solve(n,a):
  d = Counter(a)
  d_lst = list(sorted(d.keys()))
  first = d_lst[-1]
  second = d_lst[-2]
  if d[first] != 1:
    return [first]*n
  else: # first は一つだけ
    return [second if a[i] == first else first for i in range(n)]

print(*solve(N,a),sep="\n")

Submission status: Runtime Error

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

m1, m2 = sorted(A, reversed=True)[0:2]
for a in A:
    print(m2 if a == m1 else m1)

Submission status: Runtime Error

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

b = sorted(a)

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
sa = sorted(a)
am, asl = sa[-1], sa[-2]
print(*[asl if ai == am else am for ai in a], sep='\n')

Submission status: Runtime Error

Solution code:
N=int(input())
l=[]
l.append(int(input()))
l.append(int(input()))
m1=max(l)
mx=min(l)
for _ in range(N-2):
  l.append(int(input()))
  if l[-1] >= m1:
    m2 = m1
    m1 = l[-1]
  elif l[-1] > m2:
    m2 = l[-1]
for i in range(N):
  if l[i] == m1:
    print(m2)
  else:
    print(m1)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
sa = a.sort()
am, asl = sa[-1], sa[-2]
for i in range(n):
    print(asl if a[i] == am else am)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
for _ in range(n):
  l.append(int(input()))
m=max(l)
mc=l.count(m)
s=sorted(set(l))[-2]
for i in l:
  if i==m:
    if mc>1:
      print(m)
    else:
      print(s)
  else:
    print(m)

Submission status: Runtime Error

Solution code:
n = int(input())

max_1 = 0
max_2 = 0
max_index = 0

for i in range(n):
	item = int(input())
    if item >= max_1:
        max_1, max_2 = item, max_1
        max_index = i
    elif item > max_2:
        max_2 = item

for i in range(n):
    ans = max_2 if i == max_index else max_1
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

max_1 = 0
max_2 = 0
max_index = 0

for i in range(n):
 	item = int(input())
    if item >= max_1:
        max_1, max_2 = item, max_1
        max_index = i
    elif item > max_2:
        max_2 = item

for i in range(n):
    ans = max_2 if i == max_index else max_1
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

max_1 = 0
max_2 = 0
max_index = 0

for i in range(n):
  	item = int(input())
    if item >= max_1:
        max_1, max_2 = item, max_1
        max_index = i
    elif item > max_2:
        max_2 = item

for i in range(n):
    ans = max_2 if i == max_index else max_1
    print(ans)

Submission status: Runtime Error

Solution code:
loop = int(input())
nums = [int(input()) for i in range(loop)]
for i in range(0, loop):
    subNums = nums
    del subNums[i]
    print(max(subNums))

Submission status: Runtime Error

Solution code:
a = [int(input()) for i in range(n)]
m = max(a)
p = a.index(m)
s = max(a)
for i in range(n):
    if i != p:
        print(m)
    else:
        print(s)

Submission status: Runtime Error

Solution code:
a = [int(input()) for i in range(n)]
m = max(a)
p = a.index(m)
a.remove(m)
s = max(a)
for i in range(n):
    if i != p:
        print(m)
    else:
        print(s)

Submission status: Runtime Error

Solution code:
a = [int(input()) for i in range(n)]
m = max(a)
print(a)
p = a.index(m)
a.remove(m)
s = max(a)
print(s)
for i in range(n):
    if i != p:
        print(m)
    else:
        print(s)

Submission status: Runtime Error

Solution code:
l,r=map(int,input().split())
a=2018
for i in range (l,min(r,l+2019)):
  for j in range(i+1,min(r+1,i+2019)):
    c= ((i%2019)*(j%2019))%2019
    if c<a:
      a=c
print(a)

Submission status: Runtime Error

Solution code:
L=list()
N=int(input())
for i in range(N):
  a=int(input())
  L.append(a)
L=L.sorted(L)
c=L[-1]
d=L[-2]
for i in range(N):
  if L[i]==c:
    print(d)
  else:
    print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: str(sys.stdin.buffer.readline().rstrip())
rs = lambda: map(str, sys.stdin.buffer.readline().split())
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

n = ri()
a = [ri() for _ in range(n)]
for i in range(n):
  print(max(max(a[0: i]), max(a[i+1: n])))

Submission status: Runtime Error

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

maxa = max(a)
maxb = max(a)
cntmax = a.count(maxa)
if cntmax >= 2:
    for i in range(n):
        print(maxa)
    exit()
else:
    maxi = a.index(maxa)
    if maxi >= 1:
        x = max(a[:maxi])
    if maxi < n - 1 :
        y = max(a[maxi+1:])
    maxb = max(x,y)

for i in a:
    if i == maxa:
        print(maxb)
    else:
        print(maxa)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def solve():
    n=int(input())
    max1=0
    count=0
    num=[]
    def append(num1):
        num.append(num1)
    for i in range(n):
        a=int(input())
        if max1<a:
            count=1
            max1=a
        elif max1==a:
            count+=1
        append(a)
    if count!=1:
        for i in range(n):
            print(num[i])
    else:
        for i in range(n):
            if num[i]==max1:
                print(max(max(num[:i]),max(num[i+1:])))
            else:
                print(max1)
solve()

Submission status: Runtime Error

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

l = sorted(a, reverse=True)
m = a.index(a(max))
for i in range(n):
    if i == m:
        print(l[1])
    else:
        print(l[0])

Submission status: Runtime Error

Solution code:
n=int(input())
l=[int(input()) for i in range(n)]
for j in range(n):
    l2=l
    l2[i]=0
    print(max(l2))

Submission status: Runtime Error

Solution code:
# リストのうちmaxのインデックス以外は全てmaxを出力、maxのインデックスは2番目に大きい値を出力する
n = int(input())
a = list(int(input()) for _ in range(n))

# リストのmaxとmaxのインデックスを取得
a_max = max(a)
max_index_all = [i for i, x in enumerate(a) if x == a_max]

# リストからmaxを全部削除し、2番目に大きい値を取得
for i in max_index_all:
    a.pop(i)
a_second_max = max(a)


for i in range(n):
    # maxのインデックスでは、2番目に大きな値を出力
    if i in max_index_all:
        print(a_second_max)
    # max以外のインデックスでは、maxを出力
    else:
        print(a_max)

Submission status: Runtime Error

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

base=max(a)
maxkosu=a.count(base)
if maxkosu>1:
  for i in range(N):
    print(base)
else:
  maxidx=a.index(base)
  reigai=max(max(a[:maxidx]), max(a[maxidx+1:]))
  for i in range(N):
    if i==maxidx:
      print(reigai)
    else:
      print(base)

Submission status: Runtime Error

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

for i in range(N):
    if M[N-1]>A[i]:
        print(M[N])
    elif M[N-1]==A[i]:
        print(M[N-1])

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
for i in range(n):
  b=int(input())
  a.append(b)
s=a.copy()
for i in range(n):
  if s[i]==max(s):
    print(s[i])
  else:
    del s[i]
    print(max(s))

Submission status: Runtime Error

Solution code:
import copy
n = int(input())
a = [int(input()) for _ in range(n)]
b = (copy.copy(a)).sort(reverse=True)
m = max(a)

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

Submission status: Runtime Error

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

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

  M = max(A)
for i in range(N):
  if M == A[i]:
    ans = max(max(A[0:i]),max(A[i+1:N]))
    print(ans)
  else:
    print(M)

Submission status: Runtime Error

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

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

for i in range(N):
  ans = max(A[0:i].extend(A[i+1:N]))
  print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
for i in range(n):
    li_s = max(a[:i])
    li_g = max(a[i+1:])
    print(max(li_s,li_g))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

# check
set_A = list(set(A))
for a in A:
    print(max([sa for sa in set_A if sa != a]))

Submission status: Runtime Error

Solution code:
n = int(input())
ai = []
for i in range(n):
  ai[i] = int(input())
bi = ai[:]
bi.sort()
num1 = bi[-1]
num2 = bi[-2]
for i in ai:
  if i == num1:
    print(num2)
  else:
    print(num1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=max(a)
k=a.index(m)
a.sort()
m2=a[n-2]
ans=[m]*n
ans[k]=m2
for aa in ans:
  print(aa)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=max(a)
for i in range(n):
  if a[i]!=m:
    print(m)
  else:
    print(a.sort()[n-2])

Submission status: Runtime Error

Solution code:
n = int(input())
top_val = 0
top_idx = set()
semi_top = 0

for i in range(n):
  a = int(input())
  if a > top_val:
    semi_top = top_val
    top_val = a
    top_idx.clear()
    top_idx.add(i)
  elif a == top_val:
    top_idx.add(i)

if len(top_idx) > 1:
  semi_top = top_val

print("\n".join([semi_top if i in top_idx else top_val for i in range(n)]))

Submission status: Runtime Error

Solution code:
N=int(input())

seq=[]

for i in range(N):

    a= int(input())
    
    seq.append(a)

numbers=set(seq)
numbers=sorted(numbers,reverse=True)

A_max=numbers[0]

if len(numbers)>=2:
    A_second = numbers[1]

for k in range(N):
    if seq[k]==A_max:
        print(A_second)
    else:
        print(A_max)

# 2.両端から
# left=[0]
# for i in range(N-1):
#     left_i=max(left[i],seq[i])

#     left.append(left_i)

# right=[0]

# for j in range(N-1):
#     right_j = max(right[j],list(reversed(seq))[j])

#     right.append(right_j)

# right = list(reversed(right))

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

Submission status: Runtime Error

Solution code:
inNum = int(input())
intArr = []

sortArr = []
while(inNum > 0):
    tempNum =int(input())
    intArr.append(tempNum)
    inNum = inNum-1
    if(not tempNum in sortArr):
        sortArr.append(tempNum)
sortArr.sort()
sortArr.reverse()

for x in intArr:
    if(not x == sortArr[0]):
        print(sortArr[0])
    if(x == sortArr[0]):
        print(sortArr[1])

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
  inNum = int(input())
  intArr = []

  sortArr = []
  while(inNum > 0):
      tempNum =int(input())
      intArr.append(tempNum)
      inNum = inNum-1
      if(not tempNum in sortArr):
          sortArr.append(tempNum)
  sortArr.sort()
  for x in intArr:
      if(not x == sortArr[-1]):
          print(sortArr[-1])
      if(x == sortArr[-1]):
          print(sortArr[-2])

Submission status: Runtime Error

Solution code:
A = [int(s) for s in input().split()]
first, second = sorted(A)[::-1][:2]
for a in A:
    print(first if a != first else second)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
maxi = max(a)
for i in range(n):
    if a[i] != maxi:
        print(maxi)
    else:
        b = a.pop(a[i])
        print(max(a))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [None for _ in range(N)]
for i in range(N):
  A[i] = int(input())
B = [[] for _ in range(N)]
for i in range(N):
  B[i] = [b for b in A if b != A[i]]
MAX = [None for _ in range(N)]
for i in range(N):
  MAX[i] = max(B[i])
for i in range(N):
  print(MAX[i])

Submission status: Runtime Error

Solution code:
N = int(input())
A = [None for _ in range(N)]
for i in range(N):
  A[i] = int(input())
B = [[] for _ in range(N)]
for i in range(N):
  B[i] = [b for b in A if b != A[i]]
MAX = [None for _ in range(N)]
for i in range(N):
  MAX[i] = max(B[i])
  print(MAX[i])

Submission status: Runtime Error

Solution code:
m = max(l)
ans = [m]*n
if len(set(l)) == 1:
    for i in ans:
        print(i)
else:
    x = sorted(set(l))[-2]
    a = l.index(m)
    ans[a] = x
    for i in ans:
        print(i)

Submission status: Runtime Error

Solution code:
n = int(input())
l = []
for i in range(n):
    l.append(int(input()))
m = max(l)
x = sorted(set(l))[-2]
ans = [m]*n
a = [index for index, value in enumerate(l) if value == m]
for i in a:
    ans[i] = x
[print(i) for i in ans]

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
MAX = max(a)
se = list(reversed(sorted(set(a))))[1]
for i in range(n):
    if a[i] == MAX:
        print(se)
    else:
        print(MAX)

Submission status: Runtime Error

Solution code:
#Coding:Utf-8
import sys
input=sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
ans=[0 for i in range(N)]

for i in range(N):
    ans[(A[i]-1)]=i+1

for l in range(N):
    print(ans[l],end=" ")

print("")

Submission status: Runtime Error

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

max_value=max(A)
max_index=A.index(max_value)
second_value=A.sort()[-2]

for j in range(N):
    if j==max_index:
        print(second_value)
    else:
        print(max_value)

Submission status: Runtime Error

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

max_value=max(A)
max_index=A.index(max_value)
second_value=A.sort()[-2]

for j in range(N):
    if i==max_index:
        print(second_value)
    else:
        print(max_value)

Submission status: Runtime Error

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

B = sorted(A, reverse=True)
max_first = B[0]
max_second = B[1]

for i in range(N):
	answer = max_first
    if A[i] == max_first:
        answer = max_second
    print(answer)

Submission status: Runtime Error

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

B = sorted(A, reverse=True)
max_first = B[0]
max_second = B[1]
max_third = B[2]

for i in range(N):
  if A[i] != max_first:
    print(max_first)
  elif A[i] != max_second:
    print(max_second)
  else:
    print(max_third)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
for i in range(N):
	A.append(input())
 
B = sorted(A, reverse=True, key=number)
max_first = B[0]
max_second = B[1]
max_third = B[2]
 
for i in range(N):
	if A[i] != max_first:
		print(max_first)
    else if A[i] != max_second:
		print(max_second)
    else:
		print(max_third)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
for i in range(N):
  A.append(input())
 
B = sorted(A, reverse=True, key=number)
max_first = B[0]
max_second = B[1]
max_third = B[2]
 
for i in range(N):
    if A[i] != max_first:
        print(max_first)
    elif A[i] != max_second:
        print(max_second)
    else:
        print(max_third)

Submission status: Runtime Error

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    # 左から埋めていく場合と
    # 右から埋めていく場合
    #A = []
    #for i in range(n):
    #    A.append(int(input()))
    A = [input() for _ in range(n)]
    
    left = [0] * (n+1)
    right = [0] * (n+1)
    for i in range(1,n+1):
        left[i] = max(left[i-1],A[i-1])
    for i in range(n-2,-1,-1):
        right[i] = max(right[i+1],A[i+1]) # right[i]なのか
    for i in range(n):
        print(max(left[i],right[i]))
if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
input = sys.stdin.readline
A = [int(input()) for i in range(N)]
B = sorted(A)
B.reverse()
for j in range(N):
  if A[j] == B[0]:
    print(B[1])
  else:
    print(B[0

Submission status: Runtime Error

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


sorted_A = list(reversed(sorted(A)))

maxiuam = sorted_A[0]

is_there_tow_maximum = A.count(maxiuam) >= 2
if is_there_tow_maximum:
    answer = (str(maxiuam) + "\n") * N
    print(answer)
    exit()

second = None
for Ai in sorted_A:
    if Ai < maxiuam:
        second = Ai
        break

answer = [second if Ai == maxiuam else maxiuam for Ai in A)]
answer = "\n".join(map(str, answer))

print(answer)

Submission status: Runtime Error

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


sorted_A = list(reversed(sorted(A)))

maxiuam = sorted_A[0]

is_there_tow_maximum = A.count(maxiuam) >= 2
if is_there_tow_maximum:
    answer = (str(maxiuam) + "\n") * N
    print(answer)
    exit()

second = None
for Ai in sorted_A:
    if Ai < maxiuam:
        second = Ai
        break

answer = answer.append(second if Ai == maxiuam else maxiuam for Ai in A)
answer = "\n".join(map(str, answer))

print(answer)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
a1 = sorted(a)
if a1[n-1]==a1[n-2]:
  flag = True ## true = have repeat
  maxone = a1[n-1]
else:
  flag = False ## false = no repeat
  maxone = a1[n-1]
  maxtwo = a1[n-2]
for i in range(n):
  if a[i]==1max and flag==True: print(maxone)
  elif a[i]==1max and flag==False: print(maxtwo)
  elif a[i]!=1max: print(maxone)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
a1 = sorted(a)
if a1[n-1]==a1[n-2]:
  flag = True ## true = have repeat
  1max = a1[n-1]
else:
  flag = False ## false = no repeat
  1max = a1[n-1]
  2max = a1[n-2]
for i in range(n):
  if a[i]==1max and flag==True: print(1max)
  elif a[i]==1max and flag==False: print(2max)
  elif a[i]!=1max: print(1max)

Submission status: Runtime Error

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