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:
# -*- coding: utf-8 -*-

N = int(input())

values = [0]*N
value_count_map = {}
for i in range(N):
    in_value = int(input())
    values[i] = in_value
    value_count = 0
    if in_value in value_count_map:
        value_count = value_count_map[in_value]
    value_count_map[in_value] = value_count + 1

sorted_values = sorted(value_count_map.keys(), reverse=True)
max_value = sorted_values[0]
next_max_value = sorted_values[1]
for row in range(N):
    if value_count > 1:
        print(max_value)
    elif values[row] == max_value:
        print(next_max_value)
    else:
        print(max_value)

Submission status: Runtime Error

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

N = int(input())

values = [0]*N
value_count_map = {}
for i in range(N):
    in_value = int(input())
    values[i] = in_value
    value_count = 0
    if in_value in value_count_map:
        value_count = value_count_map[in_value]
    value_count_map[in_value] = value_count + 1

for row in range(N):
    row_value = values[row]
    if row_value != max_value:
        max_value = max(value_count_map.keys())
        print(max_value)
    elif value_count_map[row_value] != 1:
        max_value = max(value_count_map.keys())
        print(max_value)
    else:
        # if row value is a unique max value
        value_count = value_count_map.pop(row_value)
        max_value = max(value_count_map.keys())
        print(max_value)
        value_count_map[row_value] = value_count

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

for cnt in range(n):
     j = i[0:n-1]
     del(j[cnt-1])
     b = max(j)
    print(b)

Submission status: Runtime Error

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

for cnt in range(n):
     j = i[0:n]
     del(j[cnt-1])
     a = max(j)
    print(b)

Submission status: Runtime Error

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

for cnt in range(n):
    b = max(i[0:cnt-2,cnt:n])
    print(b)

Submission status: Runtime Error

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

for cnt in range(n):
    b = max(i[0:cnt-2,cnt:n]
    print(b)

Submission status: Runtime Error

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

for cnt in range(n):
    a = i[cnt]
    i[cnt] = 0
    b = max(i)
    print(b)
    i[cnt] = a

Submission status: Runtime Error

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

for cnt in range(n):
    a = i[cnt]
    i[cnt] = 0
    b = max(i)
    print(b)

Submission status: Runtime Error

Solution code:
n = int(input())
a_max = 0
data = [int(input()) for i in range(n)]
a_max = max(data)
flag = True if a_max == a_max(data.remove(a_max)) else False
for i in range(n):
  if data[i] == a_max and not flag:
    tmp = data.pop(data[i])
    print(max(data))
    data.append(tmp,0)
    
  else:
  	print(a_max)

Submission status: Runtime Error

Solution code:
n = int(input())
a_max = 0
data = [int(input()) for i in range(n)]
a_max = max(data)
flag = True if a_max == a_max(data.remove(a_max)) else False
for i in range(n):
  if data[i] == a_max and not flag:
    tmp = data.pop(data[i])
    print(max(data))
    data.append(tmp)
    
  else:
  
  	print(a_max)

Submission status: Runtime Error

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

sorted_A = sorted(list(set(A)),reverse=True)

max_idx = [x == sorted_A[0] for x in A]

ans = [sorted_A[0]] * N
if max_idx.count(True) == 1: ans[A.index(sorted_A[0])] = sorted_A[1]
print(ans)

Submission status: Runtime Error

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

sorted_A = sorted(list(set(A)),reverse=True)

max_idx = [x == sorted_A[0] for x in A]

ans = [sorted_A[0]] * N
if max_idx.count(True) == 1: ans[A.index(sorted_A[0])] = sorted_A[1]

Submission status: Runtime Error

Solution code:

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
print('n a',n,a)
for i in range(n):
	a.append(int(input()))
print('As',a)
max1 = max(a)
location1 = a.index(max1)
print('1st MAX',max1,'INDEX',location1)
a.remove(a[location1])
max2 = max(a)
print('2nd MAX',max2)
if max1 == max2:
    print('1=2')
    for i in range(n):
        print(max1)
else:
    print('1!=2')
    for i in range(n):
    	if i == location1:
            print(max2)
        else:
            print(max1)

Submission status: Runtime Error

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

A_max = max(A)
AA = []
for a in A:
  if a != A_max:
    AA.append(a)
A_second = max(AA)

for i in range(len(A)):
  if A[i] == A_max:
    print(A_second)
  else:
    print(A_max)

Submission status: Runtime Error

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

M = max(lis)

for i in range(n):
    if lis[i] == M:
        lis2 = lis[:i] + lis[(i+1):]
        print(max(lis2))
    else:
        print(M)

Submission status: Runtime Error

Solution code:
import sys

numbers = []
for line in sys.stdin:
    numbers.append([int(s) for s in line.split()])

max =[]  
for i in range(1, numbers[0] + 1):
    for number in numbers:
        if(number != i):
            max.append(i)
            
    print(max)
    max.clear()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

max_num = max(s)
max_ind = s.index(mux_num)
s.remove(max_num)
max2_num = max(s)
 
for i in range(N):
    if i == max_ind:
        print(max2_num)
    else:
        print(max_num)

Submission status: Runtime Error

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

L = []
R = []

for a in A:
    if len(L) == 0:
        L.append(a)
    L.append(max(L[-1]), a)

A.reverse()
for a in A:
    if len(R) == 0:
        R.append(a)
    R.append(max(R[-1]), a)

R.reverse()

print(R[0])
for i in range(1, N-1):
    print(max(L[i-1], R[i+1]))
print(L[len(L)-2])

Submission status: Runtime Error

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


# for i in range(N):
#     buf = s.copy()
#     buf.pop(i)
#     ans = max(buf)
#     print(ans)


max_ind = [i for i, a in enumerate(s) if a == max(s)]
max_num = max(s)
max2_num = sorted(set(s))[-2]

for i in range(N):
    if (np.array(max_ind) == i).any():
        print(max2_num)
    else:
        print(max_num)

Submission status: Runtime Error

Solution code:
N=int(input())
lis=[]
for i in range(N):
  lis.append(int(input())
lis2=sorted(lis)
ma1=lis2[-1]
ma2=lis2[-2]

for i in range(N):
  if lis[i] == ma1:
    print(ma2)
  else:
    print(ma1)

Submission status: Runtime Error

Solution code:
n = int(input())
lis = []
for i in range(n):
  lis.append(int(input()))
num1 = lis.sort()[0]
num2 = lis.sort()[1]

for i in range(n):
  if lis[i] == num1:
    print(num2)
  else:
    print(num1)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
m1, m2 = sorted(set(a))[n - 2:]
if a.count(m1) > 1:
    for _ in range(n):
        print(m1)
else:
    for x in a:
        print(m1) if x == m2 else print(m2)

Submission status: Runtime Error

Solution code:
n=int(input())
i=0
b=[]
pos=0
maxi=0
while(i<n):
  k=int(input())
  b.append(k)
  if(k>maxi):
    pos=i
    maxi=k
  i+=1
b.sort()
ns=b[n-2]
i=0
while(i<n):
  if(i==posi)
  	print(ns)
  else:
    print(b[i])
  i+=1

Submission status: Runtime Error

Solution code:
Prog = [a_1, a_2, a_3, ..., a_N]
for i in Prog:
	imitation_Prog = Prog
    print(max(imitation_Prog.remove(i))

Submission status: Runtime Error

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

def max_pick(A,i):
  A.pop(i-1)
  z=A[0]
  for j in range(1,N-1):
    if z<A[j]:
      z=A[j]
  return z

for i in range(1,N+1):
  M=max_pick(list,i)
  print(M)

Submission status: Runtime Error

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

def max_pick(list,i):
  list.pop(i-1)
  z=list[0]
  for j in range(1,N-1):
    if z<list[j]:
      z=list[j]
  return z

for i in range(1,N+1):
  print(max_pick(list,i))

Submission status: Runtime Error

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

def max_pick(list,i):
  list.pop(i-1)
  z=list[0]
  for j in range(1,N-1):
    if z<list[j]:
      z=Alist[j]
  return z

for i in range(1,N+1):
  print(max_pick(list,i))

Submission status: Runtime Error

Solution code:

#include <stdio.h>

int main(void) {
	int n;
	scanf("%d", &n);
	int a[200000];
	int i;
	int j;
	int ans;
	for (i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
	}
	for (i = 1; i <= n; ++i) {//iは排除する配列
		for (j = 1; j <= n; ++j) {//判定
		start:
			ans = 0;
			if (j == i) {
				++j;
				goto start;
			}

			if (a[j] >= ans) {
				ans = a[j];
			}
		}
		scanf("%d\n", ans);
	}
	return 0;
}

Submission status: Runtime Error

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

def max_pick(A,i):
  A.pop(i-1)
  z=A[0]
  for j in range(1,N-1):
    if z<A[j]:
      z=A[j]
  return z

for i in range(1,N+1):
  print(max_pick(list,i))

Submission status: Runtime Error

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

def max_pick(A,i):
  A.pop(i-1)
  z=A[0]
  for j in range(1,N-1):
    if z<A[j]:
      z=A[j]
  return z

for i in range(1,N+1):
  print(max_pick(list,i))

Submission status: Runtime Error

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

def max_pick(A,i):
  A.pop(i-1)
  z=A[0]
  for j in range(1,N-1):
    if z<A[j]:
      z=A[j]
  return z

answer=[]
for i in range(1,N+1):
  answer.append(max_pick(list,i))

for num in answer:
  print(num)

Submission status: Runtime Error

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

def max_pick(A,i):
  A.pop(i-1)
  z=A[0]
  for j in range(1,N-1):
    if z<A[j]:
      z=A[j]
  return z

answer=[]
for i in range(1,N+1):
  answer.append(max_pick(list,i))

print(answer)

Submission status: Runtime Error

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

def max_pick(A,i):
  A.pop(i-1)
  z=A[0]
  for j in range(1,N-1):
    if z<A[j]:
      z=A[j]
  return z

answer=[]
for i in range(1,N+1):
  answer.append(max_pick(list,i))

print(answer)

Submission status: Runtime Error

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

def max_pick(A,i):
  A.pop(i-1)
  z=A[0]
  for j in range(1,N-1):
    if z<A[j]:
      z=A[j]
  return z

answer=[]
for i in range(1,N+1):
  answer.append(max_pick(list,i))

print(answer)

Submission status: Runtime Error

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

def max_pick(A,i):
  A.pop(i-1)
  z=A[0]
  for j in range(1,N-1):
    if z<A[j]:
      z=A[j]
  return z

answer=[]
for i in range(0,N):
  answer.append(max_pick(list,i))

print(answer)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
 
for _ in range(N):
    A.append(int(input()))
    
    
for i in range(N):
    if A[i] >= a:
        b = a
        a = A[i]
    elif A[i] > b:
        b = A[i]
 
for i in range(N):
    if A[i] < a:
        print(a)
    else:
        print(b)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
ma=0
for i in range(n):
    a.append(int(input()))
for j in range(n):
    if(ma=a[j]):
        for h in range(n):
            if(h!=j):
                if(ma<a[h]):
                    ma=a[h]
        print(str(ma))

Submission status: Runtime Error

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

maxa = max(a[0],a[1])
mina = min(a[0],a[1])

for i in range(2,n):
    if a[i] >= maxa:
        mina = maxa
        maxa = a[i]
    elif a[i] >mina:
        mina = a[i]

for i in range(n):
    if a[i] == maxa:
        print(mina)
    else:
        print(maxa)
å

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
left=[0]
for i in a:
  left.append(max(left[-1],i))
right=[0]
for i in reversed(a):
  right.append(max(right[-1],i))
right.reverse()
for i in range(n):
  print(max(left[i],right[n-i]))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
left=[0]
for i in a:
  left.append(max(left[-1],i))
right=[0]
for i in reversed(a):
  right.append(max(right[-1],i))
right.reverse()
for i in range(n):
  print(max(left[i],right[i+1]))

Submission status: Runtime Error

Solution code:
l=[int(input()) for _ in range(int(input()))]
for i in l:
    g=[j for j in l if j!= i]
    print(max(g))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
list=[]
for i in range(N):
  list.append(int(input()))
M=max(list)
L=[i for i, v in enumerate(list) if v == M]
n=len(L)
if n>1:
  for i in range(N):
    print(M)
elif:
  del list[L[0]]
  M2=max(list)
  for i in range(N):
    if i == L[0]:
      print(M2)
    elif:
      print(M)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [0] * n

for i in reversed(range(n)):
    for j in range(i + 1, n, i + 1):
        x = 1
        k = j
        while k < n:
            x ^= b[k - 1]
            k += j
        if x == a[i]:
            b[i] = 1

print(sum(b))
for i in range(n):
    if b[i] == 1:
        print(i + 1)

Submission status: Runtime Error

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

for v in a:
  if v == sorted[0]:
    print(sorted[1])
  else:
    print(sorted[0])

Submission status: Runtime Error

Solution code:
n = int(input())
no1 = -1
no1_i = -1
no2 = -2
no2_i = -1
S = []
for _ in range(n):
    S.append(int(input()))

for i in range(n):
  	if s[i] > no1:
    	no1_i = i
    	no1 = s[i]
    elif s[i] > no2:
    	no2_i = i
    	no2 = s[i]
      
for i in range(n):
 	if no1_i == i:
    	print(no2)
    else:
    	print(no1)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys, math, bisect, random, itertools
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    print(n*n*3)
    return

#B
def B():
    n, d = LI()
    print((n-1)//(2*d+1)+1)
    return

#C
def C():
    n = II()
    a = IR(n)
    b = a[::1]
    b.sort()
    for i in range(n):
        if a[i] == b[-1]:
            print(b[-2])
        else:
            print(b[-1])
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Runtime Error

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

for i in range(N):
  b = a[:]
  b.pop(i)
  print(max(b)

Submission status: Runtime Error

Solution code:
l=[]
t=int(input())
b=0
c=0
for i in range(t):
    a=int(input())
    if(a>b):
        b=a
    else if(b>a and a>c):
        c=a
    l.append(a)
for i in range(0,t):
    if(l[i]!=b):
        print(b)
    else:
        print(c)

Submission status: Runtime Error

Solution code:
l=[]
t=int(input())
b=0
c=0
for i in range(t):
    a=int(input())
    if(a>b):
        b=a
    else if(b>a and a>c):
            c=a
    l.append(a)
for i in range(0,t):
    if(l[i]!=b):
        print(b)
    else:
        print(c)

Submission status: Runtime Error

Solution code:
n = input()
a = []
for i in range(n):
  a.append(input())
maxNum = max(a)
secoundMax = sorted(a)[-2]
for i in a:
  if a == maxNum:
    print(secoundMax)
  else:
    print(maxNum)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
p=a[::]
m=max(a)
a.delete(m)
m2=max(a)
for i in p:
  if i==m:
    print(m2)
  else:
    print(m)

Submission status: Runtime Error

Solution code:
import heapq
from collections import defaultdict
cnt = defaultdict(int)
N = int(input())
A = list(map(int, input().split()))
# A = []
# for i in range(N):
#     A.append(int(input()))
ans = 0
_ans = []
buff = [0 for i in range(N)]
for i in range(N-1, -1, -1):
    if i > N//2:
        buff[i] = A[i]
    else:
        _m = 0
        # for j in range(i, N, max(1, i)):
        #     _m += buff[j]
        # _m = sum(buff[i:N])
        for j in range(i*2, N, max(1, i)):
            _m += buff[j]
        if _m % 2 != A[i]:
            buff[i] = 1
            ans += 1
            _ans.append(i+1)

mm = 0
for i in range(ans):
    if buff[i] == 1:
        mm = i

print(sum(buff))
print(*_ans)

Submission status: Runtime Error

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

def main():
    n = int(input())
    A = list(map(int, [input() for _ in range(n)]))
    SA = sorted(set(A))
    ma, ma2 = SA[-1], SA[-2]
    ans = [ma if i != ma else ma2 for i in A]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
import math
import copy
a = int(input());
b = [int(input()) for i in range(a)];
c = 0;
first = max(b);
g = b.copy();
h = list(g.index(first));
del g[h];
second = max(g);

for i in range(a):
    if max(b) > b[i]:
        print(first);
    elif first == b[i]:
        print(second);

Submission status: Runtime Error

Solution code:
n = int(input())

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

x = int(0)
y = int(0)

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

for i in range(n):
    x = max(a[:i])
    y = max(a[i + 1:])
    print(max(x,y))

Submission status: Runtime Error

Solution code:
N = int(input())
L=[]
i = 0
s = 0
M2 = 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]
for s in range(1,N):
    if L[s] == M:
        continue
    else:
        if L[s] > M2:
            M2 = L[s]
for i in range(0,N):
    if L[i] == M:
        print(M2)
    else:
        print(M)
N = int(input())
L=[]
i = 0
s = 0
M2 = 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]
for s in range(1,N):
    if L[s] == M:
        continue
    else:
        if L[s] > M2:
            M2 = L[s]
for i in range(0,N):
    if L[i] == M:
        print(M2)
    else:
        print(M)

Submission status: Runtime Error

Solution code:

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

B=copy.copy(S)
B.sort()
if N>2:
	C=int(B[N-1])
	D=int(B[N-2])
	for i in S:
		if int(i)>=C:
			print(D)
		else:
			print(C)

else:
	print(S[1])
	print(S[0])

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
#'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N = int(input())
A = [int(input()) for _ in range(N)]
largest_num = 0
largest_ind = -1
second_large_num = 0

for i in range(N):
	if A[i] > largest_num:
		second_large_num = largest_num
		largest_num = A[i]
		largest_ind = i
	elif A[i] > second_large_num:
		second_large_num = A[i]
		
for i in range(N):
	if i == largest_ind:
		print(second_large_num)
	else:
		print(largest_num)

Submission status: Runtime Error

Solution code:
N = int(input())
S = []
for _ in range(N):
    S.append(input())  # S += [input()] とも書ける

B=S.copy()
B.sort()
if N!=2:
	C=int(B[N-1])
	D=int(B[N-2])
	for i in S:
		if int(i)>=C:
			print(D)
		else:
			print(C)

else:
	print(S[1])
	print(S[0])

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A, reversed = 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())
a = [int(input()) for i in range(n)]
c = sorted(a,reverse=True)
if a.count(max(a))>1:
    for i in n:
        print(max(a))
else:
    for i in range(n):
        if i==a.index(max(a)):
            print(c[1])
        else:
            print(max(a))

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
for p in range(N):
	A+=[int(input())]
B=A.copy()
B.sort()
if N!=2:
	C=int(B[N-1])
	D=int(B[N-2])
	for i in A:
		if i==C:
			print(D)
		else:
			print(C)

else:
	print(A[1])
	print(A[0])

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
for n in range(N):
	A+=[int(input())]
B=A.copy()
B.sort()
if N!=2:
	C=int(B[N-1])
	D=int(B[N-2])
	for i in A:
		if i==C:
			print(D)
		else:
			print(C)

else:
	print(A[1])
	print(A[0])

Submission status: Runtime Error

Solution code:
N = int(input())
M = 1
prev_M = 0
A = []
for i in range(N):
  a = int(input())
  A += [a]
  if a == M:
    prev_M = M
  elif a > M:
    M = a
for i in range(N):
  if a[i] != M:
    print(M)
  else:
    print(prev_M)

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())

X=[]
for x in range(N):
    X.append(int(input()))

Y=[]
Y=np.sort(X)[::-1]

for i in range(N):
    ans=s[0]
    if ans==X[i]:
        ans=s[1]
    print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
for n in range(N):
	A+=[int(input())]
B=A.copy()
B.sort()
if N==2:
	C=int(B[-1])
	D=int(B[-2])
	for i in A:
		if i==D:
			print(C)
		else:
			print(D)

else:
	print(A[1])
	print(A[0])

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
for n in range(N):
	A.append(int(input()))
B=A.copy()
B.sort()
C=int(B[-1])
D=int(B[-2])
for i in range(N):
	if A[i]>D:
		print(D)
	else:
		print(C)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())

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

A_set = set(A)
if len(A_set)==1:
  val = max(A_set)
  for i in range(N):
    print(val)
  sys.exit()

second_max = sorted(A_set)[-2]
#print(A_set)
#print(second_max)
#print('--')

tmp_max = max(set(A))
tmp_max_list = [i for i, x in enumerate(A) if x == tmp_max]
#print(tmp_max_list)
if tmp_max_list > 1:
  for i in range(N):
    print(tmp_max)
  sys.exit()

tmp_list = [tmp_max] * N
tmp_list[A.index(tmp_max)]=tmp_max
#[式 for 任意の変数名 in イテラブルオブジェクト if 条件式]
#l_odd = [i for i in l if not i % 2 == 0]
for i in range(N):
  print(tmp_list[i])

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
for n in range(N):
	A.append(int(input()))
B=A.copy()
B.sort()
C=B[N-1]
D=B[N-2]
for i in range(N):
	if A[i]>D:
		print(D)
	else:
		print(C)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
for n in range(N):
	A.append(input())
B=A.copy()
B.sort()
C=B[N-1]
D=B[N-2]
for i in range(N):
	if A[i]>D:
		print(D)
	else:
		print(C)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
ma = max(a)
sma = sorted(A)[-2]

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

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())

A = np.array([])

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

ans = np.max(A)
j = np.argmax(A)
ans2 = np.max(np.delete(A,j))

for i in range(N):
	if i == j:
		print(int(ans2))
		continue
	print(int(ans))

Submission status: Runtime Error

Solution code:
for _ in range(N):
    A.append(int(input()))
    
for i in range(N):
    if A[i] >= a:
        b = a
        a = A[i]
    elif A[i] > b:
        b = A[i]
 
for i in range(N):
    if A[i] < a:
        print(a)
    else:
        print(b)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
for n in range(N):
	A.append(input())
B=A.copy()
B.sort()
C=B[N-1]
D=B[N-2]
for i in range(N):
	if A[i]==C:
		print(D)
	else:
		print(C)

Submission status: Runtime Error

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

max_index=np.argmax(A)
a_max=int(A[max_index])
a_second=int(np.amax(np.delete(A,max_index)))
A[:]=a_max
A[max_index]=a_second
for a in A:
    print(int(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())

A = np.array([])

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

ans = np.max(A)
j = np.argmax(A)
ans2 = np.max(np.delete(A,j))

for i in range(N):
	if i == j:
		print(int(ans2))
		continue
	print(int(ans))