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:
import copy

n = int(input())
max_1 = None
max_2 = None

for i in range(n):
    a = int(input())
    if max_1 is None:
        max_i = [i]
        max_1 = a
    elif max_1 == a:
        max_i.append(i)
    elif max_2 < a:
        if max_1 < a:
            max_2 = max_1
            max_i = [i]
            max_1 = a
        else:
            max_2 = a
    
if len(max_i) >= 2:
    out_list = [max_1 for i in range(n)]
else:
    out_list = [max_1 for i in range(n)]
    out_list[max_i[0]] = max_2
    
print("\n".join(map(str, out_list)))

Submission status: Runtime Error

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

index = sorted([i for i, v in enumerate(A) if v == max(A)])
if len(index) == 1:
  for i in range(N):
    if i == index(0):
      print(sorted(A)[-2])
    else:
      print(max(A))
else:
  for _ in range(N):
    print(max(A))

Submission status: Runtime Error

Solution code:
n = int(input())
A = []
for i in range(n):
  a = int(input())
  A.append(a)
m = max(A)
m2 = sorted(set(A))[-2]
c = A.count(m)

bool = False
if c == 1:
  bool = True

for i in A:
  if bool and i==m:
    print(m2)
  else:
    print(m)

Submission status: Runtime Error

Solution code:
from itertools import combinations
import copy

n = int(input())
ls = [int(input()) for _ in range(n)]
p = 50
ans = 0
if n>p:p=n

def cul(n, x):
    l = len(x)
    b = [x[i] for i in range(l)]
    b.pop(n)
    return max(b)
    
for i in range(p):
    s = cul(i,ls[:p])
    print(s)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())

a = []
for i in range(N):
    a.append(int(input()))
a_max = 0
n_a_max = 0
all_max = max(a)
max_arg = np.argmax(a)

if(max_arg!=0):
    a_max = max(a[:max_arg])
if(max_arg!=N-1):
    n_a_max = max(a[max_arg+1:])

if(a_max>=n_a_max):
    next_max = a_max
else:
    next_max = n_a_max

for i in range(N):
    if a[i]==all_max:
        print(next_max)
    else:
        print(all_max)

Submission status: Runtime Error

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


def funct(i, left_max, right_max):
    n = Arr[i]

    if n==right_max:
        if i ==N-1:
            right_max=0
        else:
            right_max = max(Arr[i+1:])

    print(max(left_max, right_max))

    if i == N-1:
        return

    if n >left_max:
        if i==0:
            left_max=n
        elif i ==1:
            left_max=max(Arr[:1])
        else:
            left_max=n

    return funct(i + 1, left_max, right_max)


funct(0, 0, max(Arr[1:]))

Submission status: Runtime Error

Solution code:
n = int(input())
t = [int(input()) for i in range(n)]
for i in len(t):
  s = t[:]
  del s[i]
  print(max(s))

Submission status: Runtime Error

Solution code:
import sys

N = int(stdin.readline().restrip())
num_line = [stdin.readline().restrip() for _ in range(N)]
for i in range(N):
    save_num = num_line[i]
    num_line.pop(i)
    print(max(num_line))
    num_line.insert(i, save_num)

Submission status: Runtime Error

Solution code:
a = []
n = int(input())
for i in range(n) :
	x = int(input())
	a.append(x);
	pass
for i in range(n) :
	if i == 0:
		print(max(a[1:n]))
	elif i == n - 1:
		print(max(a[0:n - 1]))
	else :
		print(max(a[0:i], a[i+1:n]))

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for i in range(N)] 
for i in range(1, N):
  del s[i]
  print(max([s]))

Submission status: Runtime Error

Solution code:
n = int(stdin.readline().rstrip())
a = [int(stdin.readline().rstrip()) for x in range(n)]
for i in range(len(a)):
    b = []
    b.append(a[:i])
    b.append(a[i+1:])
    b = [flatten for inner in b for flatten in inner]
    print(max(b))

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
m1 = max(a)
m2 = sorted(set(a))[-2]
for j in range(n):
	if a[j] < m1:
		print(m1)
	elif a[j] == m1:
		if a.count(m1) > 1:
			print(m1)
		else:
			print(m2)
	else:
		print(m2)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list[int(input()) for i in range(n-1)]
if a[i]=max(a) for i in range(n-1):
  a.remove(a[i])
  print(max[a])
else:
  print(max[a])

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()) for _ in range(N))
B = sorted(A)
for i in range(N):
  if A[i-1] == B[0]:
    print(B[1])
  else:
    print(B[0])

Submission status: Runtime Error

Solution code:
N = int(input())
L=[]
i = 0
s = 0
for i in range (0,N):
    L.append(int(input()))
M = L[0]
for s in range(1,N):
    if  L[s] > M:
        M = L[s]
i = 0
for i in range(0,N):
    F = L[0]
    for s in range(1,N):
        if f == M:
            continue
        else:
            if L[s] == L[i]:
                continue
            else:
                if L[s] > F:
                    F = L[s]
    print(F)

Submission status: Runtime Error

Solution code:
data = []
res = []

data = [int(input()) for _n in range(int(input()))]

for n in range(i):
	res.append(max(data[0:n]+data[n+1:]))

for item in res:
	print(item)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for i in range(N)] 
for i in range(1, N):
  del s[i]
  print(max(s))

Submission status: Runtime Error

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


def funct(i, left_max, right_max):
    n = Arr[i]

    if n==right_max:
        if i ==N-1:
            right_max=0
        else:
            right_max = max(Arr[i+1:])

    print(max(left_max, right_max))

    if i == N-1:
        return

    if n >=left_max:
        if i==0:
            left_max=0
        elif i ==1:
            left_max=Arr[0]
        else:
            left_max=n



    return funct(i + 1, left_max, right_max)


funct(0, 0, max(Arr[1:]))

Submission status: Runtime Error

Solution code:
a = []
n = int(input())
for i in range(n) :
	x = int(input())
    a.append(x);
    pass
for i in range(n) :
  	if i == 0:
      	print(max(a[1:n])
    elif i == n - 1;
        print(max(a[0:n - 1])
    else :
		print(max(a[0:i], a[i+1:n])

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
import numpy as np

def main():
    N = int(input().strip())
    arr = np.zeros(N, np.int32)
    for i in range(N):
        arr[i] = int(input().strip())
    for i in range(N):
        arr2 = np.copy(arr)
        arr2[i] = 0
        print(arr2.max())


main()

Submission status: Runtime Error

Solution code:
n = int(input())

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

m1 = ls[0]

for i in range(1,n):
    if(ls[i] != m1):
        m2 = ls[i]
        break

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

Submission status: Runtime Error

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

li = [int(input()) for i in range(n)]
m = max(li)
for j in range(n):
  if m < li[j]:
    print(m)
  else:
    buf=li.pop(j)
    print(max(li))

Submission status: Runtime Error

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

for i in range(N):
  if i == A.index(max(A)):
    A.pop(i)
    A.sort
    print(A[N-2])
  else:
    print(max(A))

Submission status: Runtime Error

Solution code:
a = int(input()) 
b = [int(input()) for i in range(n)] 
for i in range(a):
  d=b[i]
  b.pop(i)
  print(max(b))
  b.insert(i,d)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())

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

all_max = max(a)
max_arg = np.argmax(a)

print(max(a[1:]))

for i in range(1,N-1):
    if i!=max_arg:
        print(all_max)
    else:
        a_max = max(a[:i])
        n_a_max = max(a[i+1:])
        if(a_max>=n_a_max):
            print(a_max)
        else:
            print(n_a_max)

print(max(a[:N-1]))

Submission status: Runtime Error

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

    li = [int(input()) for i in range(n)]
    m = max(li)
    for j in range(n):
      if m < li[j]:
        print(m)
      else:
        print(max(li))

Submission status: Runtime Error

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


def funct(i, left_max, right_max):
    n = Arr[i]
    if n >=left_max:
        if i==0:
            left_max=0
        elif i ==1:
            left_max=Arr[0]
        else:
            left_max=max(Arr[:i-1])
    if n>=right_max:
        if i ==N-1:
            right_max=0
        else:
            right_max = max(Arr[i+1:])

    print(max(left_max, right_max))

    if i == N-1:
        return

    return funct(i + 1, left_max, right_max)


funct(0, 0, max(Arr[1:]))

Submission status: Runtime Error

Solution code:
import copy

n = int(input())
max_1 = None
max_2 = None

for i in range(n):
    a = int(input())
    if max_1 is None:
        max_i = [i]
        max_1 = a
    elif max_1 == a:
        max_i.append(i)
    elif max_1 < a:
        max_2 = max_1
        max_i = [i]
        max_1 = a
    elif max_2 < a:
        max_2 = a
    
if len(max_i) >= 2:
    out_list = [max_1 for i in range(n)]
else:
    out_list = [max_1 for i in range(n)]
    out_list[max_i[0]] = max_2
    
print("\n".join(map(str, out_list)))

Submission status: Runtime Error

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

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

if maxnum == nextmaxnum:
  for i in range(n):
    print(maxnum)
else:
  for i in range(n):
    if a.pop(i) == maxnum:
      print(nextmaxnum)
    else:
      print(maxnum)

Submission status: Runtime Error

Solution code:
n = int(input())
t = [int(input()) for i in range(n)]
for i in range(len(t)):
  s = t
  gomi = s.pop(i)
  print(max(s))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for num in range(n):
	temp = a.copy()
	del temp[num]
	print(max(temp))

Submission status: Runtime Error

Solution code:
a = int(input()) 
b = [int(input()) for i in range(n)] 
for i in range(a):
  d=b[i-1]
  c=pop(b.i-1)
  print(max(c))
  b.insert(i-1.d)

Submission status: Runtime Error

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

max_A = max(A)
Second = A.copy()
Second.remove(max(max_A))
Second_A = max(Second)


max_index = [i for i, v in enumerate(A) if v == max_A]

one_max = (len(max_index) == 1)

answer = [max_A] * N
if one_max:
    for i in max_index:
        answer[i] = Second_A
for i in range(N):
    print(answer[i])

Submission status: Runtime Error

Solution code:
n = int(input())
t = [int(input()) for i in range(n)]
for i in len(t):
  s = t
  gomi = s.pop(i)
  print(max(s))

Submission status: Runtime Error

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

for num in range(n):
  temp = a.copy()
  del temp[num]
  print(max(temp))

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
m_num = max(a)
m_index = [i for i, x in enumerate(a) if x == m_num]
m2_num = sorted(set(a))[-2]

for i in range(n):
  if i in m_index:
    print(m2_num)
  else:
    print(m_num)

Submission status: Runtime Error

Solution code:
n = int(input())
alist = []
for i in range(n):
    a = int(input())
    alist.append(a)
for j in range(n):
    blist.extend(alist)
    blist.pop(j)
    print(max(blist))
    blist.clear()

Submission status: Runtime Error

Solution code:
n = int(input())
nums = []
for i in range(n):
  　nums.insert(int(input()))
for i in range(n):
    print(max(max(nums[0:i],nums[i+1:n+1])))

Submission status: Runtime Error

Solution code:
array = list(map(int, input().strip().split()))
n = array[0]
max = 0
t = len(array)
t = t-1
backup = 0

for i in range(n):
    backup = array[i+1]
    array[i+1] = 0

    for j in range(t):
        if(array[j+1] > max):
            max = array[j+1]      

    print(array)
    print(max)
    max = 0
    array[i+1] = backup

Submission status: Runtime Error

Solution code:
n = int(input())
l = []
y = []
for i in range(n):
  a = int(input())
  l.append(a)
for i in range(n):
  x = l[i]
  print(max(l.remove(x))

Submission status: Runtime Error

Solution code:
array = list(map(int, input().strip().split()))
n = array[0]
max = 0
t = len(array)
t = t-1
backup = 0
for i in range(n):
    backup = array[i+1]
    array[i+1] = 0
    for j in range(t):
        if(array[j+1] > max):
            max = array[j+1]      
    print(array)
    print(max)
    max = 0
    array[i+1] = backup

Submission status: Runtime Error

Solution code:
n = int(input())
alist = []
for i in range(n):
  a = int(input())
  alist.append(a)
for j in range(n):
  blist.extend(alist)
  blist.pop(j)
  print(max(blist))
  blist.clear()

Submission status: Runtime Error

Solution code:
a = int(input()) 
b = [int(input()) for i in range(n)] 
for i in range(a):
  c=pop(b.i-1)
  print(max(c))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
    nums = []
    for i in range(n):
        nums[len(nums):len(nums)] = int(input())
    for i in range(n):
        print(max(max(nums[0:i],nums[i+1:n+1])))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
import numpy as np
a = np.array([int(input()) for _ in range(n)])
M1,M2 = sorted(set(a))[::-1][0:2]
for b,i in zip(a==M1,a):
  if b:
    print(M2)
  else:
    print(M1)

Submission status: Runtime Error

Solution code:
N = int(input())

a = []
for i in range(N):
    a.append(int(input()))
  
for j in range(N):
    if a[j] < max(a):
        print(max(a))
    elif a[j]==max(a):
        if j != N-1:
            if max(a) == max(a[0:j]) or max(a) == max(a[j+1:N+1]):
                print(max(a))
            else:
                if max(a[0:j]) > max(a[j+1:N]):
                    print(max(a[0:j]))
                else:
                    print(max(a[j+1:N+1]))
        else:
            if max(a) == max(a[0:j]):
                print(max(a))
            else:
                print(max(a[0:j]))

Submission status: Runtime Error

Solution code:
n = int(input())
t = [int(input()) for i in range(n)]
for i in len(t):
  s = t
  s.pop(i)
  print(max(s))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
input = sys.stdin.readline


def main():
    N = int(input())
    A = np.array([int(input()) for _ in range(N)])

    for j in range(N):
        if j != A.index(max(A)):
            print(np.max(A))
        else:
            ans = [x for i, x in enumerate(A) if i != j]
            print(np.max(ans))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

count = A.count(max)

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n= int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
b = a
max = max(a)
for i in range(n):
    if a[i] == max:
        a[i] = 0
        print(max(a))
        a[i] = max
        
    else:
        print(max)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
array = list(map(int, input().strip().split()))
n = array[0]
backup = 0
for i in range(n):
    backup = array[i+1]
    array[i+1] = 0
    print(max(array))
    array[i+1] = backup

Submission status: Runtime Error

Solution code:
import copy

N = int(input())

a_list = []
for i in range(N):
    a_list.append(int(input()))
    
for i in range(N):
    tmp_list = copy.copy(a_list)
    if len(tmp_list) > 2:
        tmp_list = list(sorted(set(tmp_list), key=tmp_list.index))
        tmp_list.pop(i)
        print(max(tmp_list))
    else:
        tmp_list.pop(i)
        print(max(tmp_list))

Submission status: Runtime Error

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

for i in range(N):
  if A[i] == max_v:
    print(max_v2)
  else:
    print(max_v)

Submission status: Runtime Error

Solution code:
N = int(input())

a = []
for i in range(N):
    a.append(int(input()))
  
for j in range(N):
    if a[j] < max(a):
        print(max(a))
    elif a[j]==max(a):
        if j != N-1:
            if max(a) == max(a[0:j-1]) or max(a) == max(a[j+1:N]):
                print(max(a))
            else:
                if max(a[0:j-1]) > max(a[j+1:N]):
                    print(max(a[0:j-1]))
                else:
                    print(max(a[j+1:N]))
        else:
            if max(a) == max(a[0:j-1]):
                print(max(a))
            else:
                print(max(a[0:j]))

Submission status: Runtime Error

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

max_A = max(A)
Second = A.copy()
Second.remove(max(max_A))
second_A = max(Second)

max_index = [i for i, v in enumerate(A) if v == max_A]

answer = [max_A] * N
for i in max_index:
    answer[i] = second_A
for i in range(N):
    print(answer[i])

Submission status: Runtime Error

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

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

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

    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
amax = max(A)
for i in range(N):
	if amax==A[i]:
		print(amax)
	else:
		print(max(B))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	A = [int(input()) for _ in range(N)]
	maxNum = max(A)
	maxIndex = [i for i, x in enumerate(A) if x == max(A)]
	if len(maxIndex) > 1:
		for _ in range(N):
			print(maxNum)
	else:
		for i in range(N):
			if i != maxIndex[0]:
				print(maxNum)
			else:
				prev = max(max(A[:i]), max(A[i+1:]))
				print(prev)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
list = []
for i in range(0,n):
  list.append(int(input()))
  
new_list = sorted(list, reverse=True)
print lst in new_list:
  print(lst)

Submission status: Runtime Error

Solution code:
n = int(input())

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

a_max = max(a)
a_max_count = a.count(a_max)

if a_max_count > 1:
  for i in range(n):
    print(a_max)
    
else:
  for i in range(n):
    if a[i] == a_max:
      print(max(max(a[:i]), max(a[i+1:])))
      
    else:
      print(a_max)

Submission status: Runtime Error

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

biggest = max(alist)
cop = alist.copy()
cop.remove(biggest)
second = max(cop)

for i in range(x.index(biggest)):
  print(biggest)
print(second)
for i in range(len(x) - x.index(biggest) -1):
  print(biggest)

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
a = []
count = [0 for _ in range(2000001)]

for i in range(n):
    next = int(sys.stdin.readline())
    a.append(next)
    count[next]+=1
start = 0
for i in range(20000,0,-1):
    if count[i]>0:
        v1=i
        count[i]-=1
        start = i
        break
for i in range(start,0,-1):
    if count[i]>0:
        v2=i
        count[i]-=1
        start = i
        break
count[v1]+=1
count[v2]+=1
if count[v1]>1:
    for i in range(n):
        sys.stdout.write('{}\n'.format(v1))
else:
    for v in a:
        if v != v1:
            sys.stdout.write('{}\n'.format(v1))
        else:
            sys.stdout.write('{}\n'.format(v2))

Submission status: Runtime Error

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


def funct(i, left_max, right_max):
    n = Arr[i]
    if n >=left_max:
        if i==0:
            left_max=0
        else:
            left_max=max(Arr[:i])
    if n>=right_max:
        if i < N-1:
            right_max = max(Arr[i+1:])
        else:
            right_max=left_max
    print(max(left_max, right_max))

    if i == N-1:
        return

    return funct(i + 1, left_max, right_max)


funct(0, 0, max(Arr[1:]))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
max_v2 = R[1]

for i in range(N):
  if A[i] == max_v:
    print(max_v2)
  else:
    print(max_v)

Submission status: Runtime Error

Solution code:
n = int(input())
l = [0]*n
s = set()
f_max,s_max = 0,0
for i in range(n):
    a = int(input())
    l[i] = a
    
    if a not in s:
        s.add(a)

    if f_max < a:
        s_max = f_max
        f_max = a
    elif s_max < a < f_max:
        s_max = a

#s.sort()

if len(s)==1:
    for i in range(n):
        print(s[0])

    exit()

for i in range(n):
    #if l[i]==f_max:
    #    print(s_max)
    #else:
    #    print(f_max)
    #if l[i]==s[-1]:
    #    print(s[-2])
    #else:
    #    print(s[-1])
    s.remove(l[i])
    print(max(s))
    s.add(l[i])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
array = list(map(int, input().strip().split()))
n = array[0]
backup = 0
for i in range(n):
    backup = array[i]
    array[i] = 0
    print(max(array))
    array[i] = backup

Submission status: Runtime Error

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

one, two = sorted(list(set(A)), reverse=True)[:2]

for i in A:
    print(two if one == i else one)

Submission status: Runtime Error

Solution code:
import sys

#+++++
		
def main():
	n = int(input())
	ll=[int(input()) for _ in range(n)]
	
	mm = ll.sort()
	ma=mm[-1]
	mb=mm[-2]
	
	for i in ll:
		pp = ma if i != ma else mb:
		print(pp)
		
	
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Runtime Error

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

    for i in a_list:
        if i == max(a_list):
            a_list.sort()
            print(a_list[-2])
        else:
            print(max(a))

main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
A_m = max(A)
if A.count(max) >= 2:
    for i in range(N):
        print(A_m)
else:
    for i in range(N):
        if A[i] == A_m:
            del A[i]
            A_m_new = max(A)
            print(A_m_new)
        else:
            print(A_m)

Submission status: Runtime Error

Solution code:
A = [input() for i in range(N)]
maxA = max(A)
secA = sorted(A)[-2]
num=A.count(maxA)
#print(N,A,maxA,secA,num)

for i in range(N):
  if num>1:
    print(maxA)
  elif A[i]==maxA:
    print(secA)
  else:
    print(maxA)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
max_v2 = R[1]

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

Submission status: Runtime Error

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

for i in range(n):
    if m<a[i]:
        m=a[i]
        k=i

for j in range(n):
    if j==k:
        print(sorted(a)[-2])
    else:
        print(m)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
for i in range(N):
    A += input()
    A[i] = int(A[i])
task = 0
m = 0
for i in range(N):
    task = A.pop(i)
    m = max(A)
    print(m)
    A.insert(i,task)

Submission status: Runtime Error

Solution code:
n = int(input())
a = {}
#b = []
mx = -10000
#mx1 = -10000
for i in range(n):
    num = int(input())
    if num in a.keys():
        a[num] += 1
    else:
        a[num] = 1
    if mx < num:
        mx = num
        m = i

k = max(a.keys())
if len(a) > 1:
    #t = sorted(list(a.keys()))[-2]
    b = list(a.keys())
    b.pop(m)
    t = max(b)

if a[k] > 1:
    for i in range(n):
        print(k)
else:
    for i in range(n):
        if i == m:
            print(t)
        else:
            print(k)

Submission status: Runtime Error

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

r = [max([*a[0:i],*a[i+1:]]) for i in range(n)]

for answer in r:
     print(answer)

Submission status: Runtime Error

Solution code:
n=int(input())
s=[];
for i in range(n):
  s.append(int(input()))
ss=s
ss.sort()
a,b=ss[n-1],ss[n-2]
for i in range(n):
  print(s[i]==a?a:b)

Submission status: Runtime Error

Solution code:
import pandas as pd
from pandas import Series

N = int(input())
A = [int(input()) for _ in range(N)]
# 一番でかいやつと二番目のやつを見つける。
# 1番でかいやつが１つなら、基本最大値で、そいつがえらばれたら2番目の値教える。

max_val = max(A)
if sum(Series(A) == max_val) > 1:
    for i in range(0,N):
        print(max_val)
else:
    max_val_index = A.index(max_val)
    A[max_val_index] = 0
    sec_max_val = max(A)
    for i in range(0,N):
        if i == max_val_index:
            print(sec_max_val)
        else:
            print(max_val)
            
# 一番でかいやつが２つ以上いるなら、つねに1番の値を表示する。

Submission status: Runtime Error

Solution code:
input = sys.stdin.readline

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

for i in range(N):
    a = A.copy()
    del a[i]
    print(max(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import Collection

N = int(input())

a = []
for i in range(N):
  a.append() = int(input())
  
for j in range(N):
  if a[j] < max(a):
    print(max(a))
  elif a[j]==max(a):
    if max(a) == max(a[0:j-1]) or max(a) == max(a[j+1:N]):
      print(max(a))
    else:
      if max(a[0:j-1]) > max(a[j+1:N]):
      	print(max(a[0:j-1]))
      else:
     	print(max(a[j+1:N]))
  else:
    if max(a[0:j-1]) > max(a[j+1:N]):
      print(max(a[0:j-1]))
    else:
      print(max(a[j+1:N]))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
a = [0]*N
b = [0]*N
for i in range(N):
    a[i] = int(input())
    b[i] = int(input())
m = max(b)
b.remove(m)
n = max(b)

for i in range(N):
    if a[i] == m:
        print(n)
    else:
        print(m)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
max = 0
max_ind = 0
max2 = 0
max2_ind = 0

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

Submission status: Runtime Error

Solution code:
a=[int(input())for i in[0]*int(input())]
b=max(a)
if a.count(b)>1:print('\n'.join([b for i in range(len(a))]))
else:
  c=[b for i in a]
  c[a.index(b)]=max(a[:a.index(b)]+a[a.index(b)+1:])

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
A = np.array([int(input()) for i in range(n)])
for i in range(n):
  m = np.max(A)
  if A[i] == m:
    mask = A != A[i]
    print(np.max(A[mask]))
  else:
    print(m)