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: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
max = max(A)
if A.count(max) >=2:
    for i in range(N):
        print(max)
else:
    M = A.index(max)
    for i in range(M):
        print(max)
    print(max(A.remove(max)))
    for i in range(M+1,N):
        print(max)

Submission status: Runtime Error

Solution code:
import copy
n=int(input())
A=[int(input()) for i in range(n)]
B=copy.copy(A)
for i in range(n):
    A.pop(i)
    print(max(A))
    A = B

Submission status: Runtime Error

Solution code:
n = int(input())
mx = 0
smx = 0
mxi = 0
for i in range(n):
  ai = int(input())
  if a[i] > mx:
    smx = mx
    mx = a[i]
    mxi = i
  elif a[i] > smx:
    smx = a[i]
for j in range(mxi):
  print(mx)
print(smx)
for j in range(mxi+1,n):
  print(mx)

Submission status: Runtime Error

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

    for n in range(N):
        tmp = A.copy()
        tmp.pop(n)
        print(max(tmp))


if __name__ == '__main__':
    q3()

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
mx = max(a)
mxi = a.index(mx)
mx2 = a[:mxi] + a[mxi+1:]

for i in range(n):
    if i == mxi: print(mx2) 
    else: print(mn)

Submission status: Runtime Error

Solution code:
n = int(input())
a1 = int(input())
a2 = int(input())
if a[0] >= a[1]:
    maxa1 = a1
    maxa2 = a2
    res = 0
else:
    maxa1 = a2
    maxa2 = a1
    res = 1

for i in range(2, n):
    a_ = int(input())
    if maxa1 <= a_:
        maxa2 = maxa1
        maxa1 = a_
        res = i
    elif maxa2 <= a_:
        maxa2 = a_

for i in range(n):
    if i == res:
        print(maxa2)
    else:
        print(maxa1)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
best_cnt=0
[a.append(int(input())) for _ in range(n)]
b = sorted(a)
if len(set(b))==1:
  best=better=b[-1]
else:
  best=list(set(b))[-1]
  better=list(set(b))[-2]
for i in range(n):
  if a[i]==best:
    best_cnt+=1
    
for i in range(n):
  if a[i] == best:
    if b_cnt==1:
      print(better)
    else:
      print(best)
  else:
    print(best)

Submission status: Runtime Error

Solution code:
import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))
c = [i for i, x in enumerate(a) if x == b[0]] #最大値の位置

for i in range(n):
    if a[i] == b[0]: #最大値だったら
        print(b[1]) #最大値から2番目を出力
    else: #そうでなければ
        print(b[0]) #最大値を出力

Submission status: Runtime Error

Solution code:
import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))
c = [i for i, x in enumerate(a) if x == b[0]] #最大値の位置

for i in range(n):
    if i in c: #最大値だったら
        print(b[1]) #最大値から2番目を出力
    else: #そうでなければ
        print(b[0]) #最大値を出力

Submission status: Runtime Error

Solution code:
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
a_max = max(A)[0]
count = A.count(a_max)

for i in range(N):
	if A[i] < a_max and count >= 2:
		print(a_max)
	else:
		b_max = 0
		for j in range(N):
				if A[j] == a_max:
					continue
				if A[j] > b_max:
					b_max = A[j]
		print(b_max)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
a_max = max(A)[0]
count = A.count(a_max)

for i in range(N):
	if A[i] < a_max and count >= 2:
		print(a_max)
	else:
		b_max = 0
		for i in range(N):
				if A[i] == a_max:
					continue
				if A[i] > b_max:
					b_max = A[i]
		print(b_max)

Submission status: Runtime Error

Solution code:
n = int(input())
num = [list(map(int, input())) for _ in range(n)]
Sort_num = sorted(num)
for i in range(n):
  if num[i] == Sort_num[i-1]:
    print(Sort_num[i-2]
  else:
    print(Sort_num[i-1])

Submission status: Runtime Error

Solution code:
#C
from collections import Counter
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
first = sorted(set(a))[-1]
if len(a) == 1 or sorted(set(a))[0] == sorted(set(a))[-1]:
    pass
else:
    second = sorted(set(a))[-2]
for i in a:
    if i != first:
        print(first)
    else:
        print(second)

Submission status: Runtime Error

Solution code:
#C
from collections import Counter
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
first = sorted(set(a))[-1]
if sorted(set(a))[0] == sorted(set(a))[-1]:
    pass
else:
    second = sorted(set(a))[-2]
for i in a:
    if i != first:
        print(first)
    else:
        print(second)

Submission status: Runtime Error

Solution code:
N = input()
A=[]
for i in range(N-1):
    A.append(int(input()))
B=sorte(A, reverse=True)
for i in range(N-1):
    if A[i] == 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)]

for i in range(n):
  if i == 0:
    ans = max(a[1:n])
  elif i == n-1:
    ans = max(a[0:n-1])
  else:
    ans = max(a[0:i],a[i+1:n])
  print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
max1 = max(A)
index = []
A2 = sorted(A)[1]
for i in range(N):
    if(A[i] == max1):
        print(max2)
    else:
        print(max1)

Submission status: Runtime Error

Solution code:
_, *a = map(int, open(0).read().split())
s = sorted(a)
for i in a:
    print(s[(i < b[-1])-2])

Submission status: Runtime Error

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

sort_a = sorted(list(set(a)))

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

Submission status: Runtime Error

Solution code:
def main():
	n = int(input())
	# n,m = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	l = [str(input()) for i in range(n)]
	#R行C列
	# a = [list(map(int,input().split())) for x in range(m)]
	# print(' '.join(map(str,)))
	m = max(l)
	# i = 0
	print(max(l[1:n]))

	# 0 < i < n
	for i in range(1,n-1):
		if l[i] == m:
			print(max( max(l[0:i]),max(l[i+1:n-1])))
		else:
			print(m)
	
	
	print(max(l[:n-1]))

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
def main():
	n = int(input())
	# n,m = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	l = [str(input()) for i in range(n)]
	#R行C列
	# a = [list(map(int,input().split())) for x in range(m)]
	# print(' '.join(map(str,)))

	# i = 0
	print(max(l[1:n]))
	m = max(l[1:n])

	# 0 < i < n
	for i in range(1,n):
		if l[i] == m:
			print(max( max(l[0:i]),max(l[i+1:n])))
		else:
			print(m)


if __name__ == '__main__':
	main()

Submission status: Runtime Error

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

for i in l:
	if i<k[-1]:
    	print(k[-1])
	if i==k[-1]:
		print(k[-2])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

  max_left = [0] * N
  max_right = [0] * N

  ary = []

  for i in range(N):
    v = int(input())
    ary.append(v)

  for i in range(N - 1):
    max_left[i+1] = max(max_left[i], ary[i])

  for i in range(N - 1, 0, -1):
    max_right[i-1] = max(max_right[i], ary[i])

  for i in range(N):
	v = max(max_left[i], max_right[i])
	print(v)

main()

Submission status: Runtime Error

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

  max_left = [0] * N
  max_right = [0] * N

  ary = []

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

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

  for i in range(N - 1, 0, -1):
    max_right[i-1] = max(max_right[i], ary[i])

  for i in range(N):
	v = max(max_left[i], max_right[i])
	print(v)

main()

Submission status: Runtime Error

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

  max_left = [0] * N
  max_right = [0] * N

  ary = []

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

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

  for i in range(N - 1, 0, -1):
    max_right[i-1] = max(max_right[i], ary[i]):

  for i in range(0, N):
	v = max(max_left[i], max_right[i])
	print(v)

main()

Submission status: Runtime Error

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

  left = [0] * N
  right = [0] * N

  ary = []

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

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

  max_right = 0
  for i in range(N - 1, 0, -1):
    max_right[i-1] = max(max_right[i], ary[i]):

  for i in range(0, N):
    print(max(max_left[i], max_right[i]))

main()

Submission status: Runtime Error

Solution code:
N = int(input())
A_list = []
for i in range(N):
    A = int(input())
    A_list.append(A)
sort_A = sorted(A_list, reverse = True)
k = 0
while (1):
    if sort_A[k] != sort_A[k+1]:
        A_second = sort_A[k+1]
        break
    k += 1
for i in range(N):
    if A_list[i] == sort_A[0]:
        print(A_second)
    else:
        print(sort_A[0])

Submission status: Runtime Error

Solution code:
N=int(input())
list=[]
for i in range(N):
  A=int(input())
  list.append(A)
l=sorted(list,reverse=True)
k=set(list)
A_1=k[0]
A_2=k[1]
for j in range(N):
  if list[j]!=A_1:
    print(A_1)
  else:
    print(list[1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
a=[]
for _ in range(N):
  a_=int(input())
  a.append(a_)
x=max(a)
if a.count(x)>=2:
  for i in range(N):
    print(x)
else:
  for i in range(N):
    if a[i]==x:
      print(a.sort(-2))
    else:print(x)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
M = max(A)
c = A.count(M)
a = list(set(A))
a.sort(reverse=True)

for i in range(N):
  if A[i] != M:
    print(M)
  elif:
    if c >= 2:
      print(M)
    elif:
      print(a[1])

Submission status: Runtime Error

Solution code:
n=int(input())
a=[-1]+list(map(int,input().split()))

t=((n+1)+2-1)//2

ans=[-1]+[0 for i in range(n)]
ans[t:]=a[t:]

for i in range(t-1,0,-1):
 t_sum=sum(ans[i+i::i])
 if a[i]%2==t_sum%2:
  ans[i]=0
 else:
  ans[i]=1

m=ans.count(1)
ans_l=[]
for i in range(n+1):
 if ans[i]==1:
  ans_l.append(i)
print(m)
if ans_l:
 print(*ans_l)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
 
N = int(readline())
A = np.zeros(N+2,np.int32)
A[1:-1] = np.array(read().split(),np.int32)

N = ir()
A = np.zeros(N+2, np.int32)
A[1:-1] = np.array(read().split(),np.int32)

left_max = np.maximum.accumulate(A[:-2])
right_max = np.maximum.accumulate(A[::-1])[::-1][2:]
answer = np.maximum(left_max, right_max)
print('\n'.join(answer.astype(str)))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

read = sys.stdin.buffer.read
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.zeros(N+2, np.int32)
A[1:-1] = np.array(read().split(),np.int32)

left_max = np.maximum.accumulate(A[:-2])
right_max = np.maximum.accumulate(A[::-1])[::-1][2:]
answer = np.maximum(left_max, right_max)
print('\n'.join(answer.astype(str)))

Submission status: Runtime Error

Solution code:
# import itertools
# import math

import sys
input = sys.stdin.readline


def solve(N, A):
    for i in range(N):
        tmp = A
        tmp.pop(i)
        print(max(tmp))


N = int(input())
# S = input()
# A, B = map(int, input().split())
# A = list(map(int, input().split()))


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


solve(N, A)

Submission status: Runtime Error

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

lerge1, lerge2  = sorted(A)[-2:]
for i in range(n):
    if a[i]==m1:
        pritn(m2)
    else:
        print(m1)

Submission status: Runtime Error

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


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

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

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


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]"):
    s = [A[0]] * (N)
    e = [A[N-1]] * (N)
    for i in range(1, N):
        s[i] = max(s[i-1], A[i])
    for i in reversed(range(0, N-1)):
        e[i] = max(e[i+i], A[i])

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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]"):
    s = [A[0]] * (N)
    e = [A[N-1]] * (N)
    for i in range(1, N):
        s[i] = max(s[i-1], A[i])
    for i in reversed(range(N-1)):
        e[i] = max(e[i+i], A[i])

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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]"):
    s = [A[0]] * (N)
    e = [A[N-1]] * (N)
    for i in range(1, N):
        s[i] = max(s[i-1], A[i])
    for i in reversed(range(N-1)):
        e[i] = max(e[i+i], A[i])

    for i in range(N):
        if i == 0:
            print(e[i+1])
        elif i == N-1:
            print(s[i-1])
        else:
            print(max(s[i-1], e[i+1]))
        
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]"):
    s = [A[0]] * (N)
    e = [A[N-1]] * (N)
    for i in range(1, N):
        s[i] = max(s[i-1], A[i])
    for i in range(N-2, -1, -1):
        e[i] = max(e[i+i], A[i])

    for i in range(N):
        if i == 0:
            print(e[i+1])
        elif i == N-1:
            print(s[i-1])
        else:
            print(max(s[i-1], e[i+1]))
        
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]"):
    s = [A[0]] * (N)
    e = [A[-1]] * (N)
    for i in range(1, N):
        s[i] = max(s[i-1], A[i])
    for i in range(N-2, -1, -1):
        e[i] = max(e[i+i], A[i])

    for i in range(N):
        if i == 0:
            print(e[i+1])
        elif i == N-1:
            print(s[i-1])
        else:
            print(max(s[i-1], e[i+1]))
        
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
*H, = map(int, input().split())
H.sort(reverse=True)
if len(H) - K <= 0:
    print(0)
else:
    print(sum(H[K:]))

Submission status: Runtime Error

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

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

    max_first = max(num_list)
    max_second = tmp[1]
    
    for num in num_list:
        if num == max_first:
            print(max_second)
        else:
            print(max_first)
        
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

m = max(a)

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

Submission status: Runtime Error

Solution code:
n = int(input())
nums = []
for i in range(n):
  nums.append(int(input()))
cache = sorted(nums)
maximum = nums[0]
second = nums[1]
if maximum == second:
  flag = True
else:
  flag = False
for i in nums:
  if i == maximum and !flag:
    print(second)
  else:
    print(maximum)

Submission status: Runtime Error

Solution code:
n = int(input())
nums = []
for i in range(n):
  nums.append(int(input()))
cache = sorted(nums)
maximum = nums[0]
second = nums[1]
if maximum == second:
  flag = True
for i in nums:
  if i == maximum && !flag:
    print(second)
  else:
    print(maximum)

Submission status: Runtime Error

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

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

for i in range(N):    
    if list_A[i] == A:
    	list_B = sorted(list_A, reverse=True)
     	B = list_B[1]
      	print(B)
    else:
        print(A)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
alist=[int(input()) for i in range(n)]
b=alist.sort(reverse=True)
for a in alist:
    if a < b[0]:
        print(b[1])
    elif b[0] <= a:
        print(b[0])

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
largest = 0
second_largest = 0
for i in range(n):
    temp = int(input())
    if temp > largest:
        largest = temp
    elif largest >= temp > second_largest:
        second_largest = temp
    else:
        continue
    a.append(temp)

for i in range(n):
    if a[i] == largest:
        print(second_largest)
    else:
        print(largest)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
A_sorted = sorted(A)
for i in range(N):
    if A[i] != A_sorted[-1]:
        print(A_sorted[-1])
    else:
        j = len(A_sorted) - 1
        count = 0
        while A[i] == A_sorted[j] and count =< 0:
            j -= 1
            count += 1
        print(A_sorted[j])

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
A_sorted = sorted(A)
for i in range(N):
    if A[i] != A_sorted[-1]:
        print(A_sorted[-1])
    else:
        j = len(A_sorted) - 1
        while A[i] == A_sorted[j]:
            j -= 1
        print(A_sorted[j])

Submission status: Runtime Error

Solution code:
import copy



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

for i in range(N):
   # B = copy.deepcopy(A)
    tmp = A[i]
    a[i] = 0
    ans = max(A)
    a[i] = tmp
    print(ans)

Submission status: Runtime Error

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

x=max(A)
count=(A.count(x))
index=[]
if count!=1:
    for i in range(N):
        print(x)
else:
    B=copy.copy(A)
    B.remove(x)
    y=max(B)
    for i in range(N):
        if A[i]==x:
            print(y)
        else:
            print(x)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for _ in range(n):
    A = int(input())
    a.append(A)
    
s = sorted(a)
for i in range(n):
    if max(a) == a[i]:
        print(ans[-2])
    else:
        print(max(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b=sorted(a,reverse=True)
max_a=b[0]
max_a2=b[1]

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

Submission status: Runtime Error

Solution code:
n=int(input())
l=[int(input()) for i in range(n)]
m=max(l)
nums=[i for i in range(n)]
for num in nums:
  if(l[num]!=m):
    print(m)
  else:
    s=[x for x in l if x!=m]
    print(max(s))

Submission status: Runtime Error

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

if b.count(m)>=2:
    for i in range(a):
        print (m)
else:
    b.sort(reverce=True)
    m2=b[1]
    for i in range(a):
        if b[i]==m:
            print(m2)
        else:
            print (m)

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())

if a<=0 and 0<=b:
  print("Zero")  
elif a < 0 and min(b-a,-a)%2 == 0:
  print("Negative")
else:
  print("Positive")

Submission status: Runtime Error

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

MAX_1 = max(A)
MAX_2 = sorted(set(A))[-2]

for i in range(N):
    if A[i] == MAX_1:
        print(MAX_2)
    else:
        print(MAX_1)

Submission status: Runtime Error

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

for i in range(n):
  v[n-1]=a[0:i]+a[i+1:n]
  print(max(v))

Submission status: Runtime Error

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

for i in range(n):
  print(max(a-a[i]))

Submission status: Runtime Error

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

for i in range(n):
  print(max(a-a[i]\n))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
maxa = max(A)
for i in range(N):
    if maxa == A[i]:
        tmp = A.pop(i)
        print(max(A))
        insert(i,tmp)
    else:
        print(maxa)

Submission status: Runtime Error

Solution code:
n = int(input()) #1行目のNを取得する
s = [int(input() for i in range(n))] #複数行の数値の入力を取得

for i in range (n):
    a = s.pop(0)
    ans = max(s)
    print(ans)
    s.append(a)

Submission status: Runtime Error

Solution code:
n=int(input())
for _ in range(n):
  a.append(int(input()))
l=[l[0]]*n
for i in range(1,n):
  l[i] = max(a[i],l[i-1])
a.reverse()
r=[r[0]]*n
for i in range(1,n):
  r[i] = max(a[i],r[i-1])
for i in range(n):
  print(max(l[i-1],r[n-i-1]))

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
b=collections.Counter(a)
d=list(b.items())
d.sort(lambda x:-x[1])
if d[0][1]==1:
  for i in range(n):
    if a[i]==int(d[0][0]):
      print(int(d[1][0]))
    else:
      print(int(d[0][0]))
else:
  for i in range(n):
    print(int(d[0][0]))

Submission status: Runtime Error

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

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

b.sort()
m = 0
l = n+1

for i in range(n):
    m = 0
    l = n+1
    if a[i] != b[-1]:
        print(b[-1])
        continue
    while a[i] != b[(m+l)//2]:
        if a[i] < b[(m+l)//2]:
            l //= 2
        else:
            m = i
    tmp = b[(m+l)//2]
    b[(m+l)//2] = 0
    print(max(b))
    b[(m+l)//2] = tmp

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
for i in range(n):
  k=int(input())
  a.append(k)
  
for j in range(n):
  a.remove(a[j])
  a.sort()
  print(a[n-2])
  a.append(a[j])

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
maxnum = max(A)
for i in range(N):
    if i == A.index(maxnum):
        tmp = A
        del tmp[tmp.index(max(tmp))]
        print(max(tmp))
    else:
        print(maxnum)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
maxnum = max(A)
for i in range(N):
    if i == maxindex:
        tmp = A
        del tmp[tmp.index(max(tmp))]
        print(max(tmp))
    else:
        print(maxnum)

Submission status: Runtime Error

Solution code:
n=int(input())

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

large=max(s)

for i in range(n):
  if s[i]!=large:
    print(large)
  if s[i]==large:
    t=s #tはsのコピー用。
    t.pop(i)
    print(max(t))

Submission status: Runtime Error

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

for j in range(0,n):
  a.append(int,input())
  
x=max(a)
y=a.index(x)
del a[y]
z=max(a)

for i in range(0,n):
  if i!=y:
    print(x)
  else:
    print(z)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(int,input().split(), for _ in range(0,n))
x=max(a)
y=a.index(x)
del a[y]
z=max(a)

for i in range(0,n):
  if i!=y:
    print(x)
  else:
    print(z)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))

value=max(a)
index=a.index(max(a))

for i in range(n):
  if i==index:
    b=a.pop(i)
    print(max(a))
  else:
      print(value)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
val=max(a)
inx=a.index(val)

for i in range(0,n):
  if i==inx:
    del a[inx]
    print(max(a))
  else:
    print(val)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=max(a)
y=a.index(x)
del a[y]
z=max(a)

for i in range(0,n):
  if i!=y:
    print(x)
  else:
    print(z)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=max(a)
y=a.index(x)

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=max(a)
y=a.index(x)

for i in range(0,n):
  if i!=y:
    print(x)
  else:
    a.pop(y)
    print(max(a))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=max(a)
y=a.index(x)
for i in range(0,n):
  if i!=y:
    print(x)
  else:
    del a(x)
    print(max(a))

Submission status: Runtime Error

Solution code:
n = int(input())
an = []
max_1 = 1
max_2 = 1
count = 1
for i in range(n):
    a = int(input())
    if a > max_1:
        tmp = max_1
        max_1 = a
        count = 1
        max1_index = [i]
        max_2 = tmp
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 >  a > max_2:
        max_2 = a
    an.append(a)
    
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    for i in range(n):
        print(max_1)

Submission status: Runtime Error

Solution code:
n = int(input())
an = []
max_1 = 1
max_2 = 1
count = 1
for i in range(n):
    a = int(input())
    if a > max_1:
        max_1 = a
        count = 1
        max1_index = [i]
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 > a and a > max_2:
        max_2 = a
        max2_index = i
    an.append(a)
    
    
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    for i in range(n):
        print(max_1)