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
import sys
# import bisect
# import math
import numpy as np
# from fractions import gcd
# import itertools

"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n = ip.I()
    a = np.array(ip.ILS(n))

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


main()

Submission status: Runtime Error

Solution code:
n = int(input())
numList  = [input() for i in range(n)]
maxVal = max(numList)
workList = numList[:]
secondVal = max(workList.remove(maxVal))
for num in numList:
  if num != maxVal:
    print(maxVal)
  else
    print(secondVal)

Submission status: Runtime Error

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

x = sorted(A)

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

Submission status: Runtime Error

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

x=sorted(A)

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

Submission status: Runtime Error

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

b = a.sort()
c = a.reverse()
 
for i in range(N):
        if a[i]!=c[0] :
                print(c[0])
        else:
                print(c[1])

Submission status: Runtime Error

Solution code:

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

# S = sorted(A)
# MAXS = max(A)
# two = S[-2]
# print("MAX {} two {}".format(MAXS,two))
# count = S.count(max(S))
#
# for i in range(N):
#     if A[i] == MAXS:
#         if count > 1:
#             print(MAXS)
#         else:
#             print(two)
#     else:
#         print(MAXS)

#


c = a.index(max(a))
m = max(a)
a.sort()
d = a[-2]
for i in range(n):
    if i == c:
        print(d)
    else:
        print(m)




# S = sorted(A)
# MAXS = max(A)
#
# for i in range(N):
#     if A[i] == MAXS:
#         print(S[-2])
#     else:
#         print(S[-1])


# #
# for i in range(N):
#
#     if i == 0:
#         print(max(A[1:]))
#
#     elif i == N-1:
#         print(max(A[:i]))
#
#     else:
#         low = max(A[0:i])
#         high = max(A[i+1:])
#
#         if high > low:
#             print(high)
#         else:
#             print(low)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
m = max(A)
ans = [m for _ in range(N)]
if A.count(M) > 1:
    print('\n'.join(ans))
    exit()
AA = A[:]
AA.remove(M)
mm = max(AA)
for n in range(N):
    if A[n] == m:
        ans[n] = mm
        break
print('\n'.join(ans))

Submission status: Runtime Error

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

S = sorted(A)
MAXS = max(A)

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

Submission status: Runtime Error

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


S = sorted(A)
MAXS = max(A)

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

Submission status: Runtime Error

Solution code:

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

S = sorted(A)
MAXS = max(A)

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

Submission status: Runtime Error

Solution code:

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

# S = sorted(A)
# MAXS = max(A)
# two = S[-2]
# print("MAX {} two {}".format(MAXS,two))
# count = S.count(max(S))
#
# for i in range(N):
#     if A[i] == MAXS:
#         if count > 1:
#             print(MAXS)
#         else:
#             print(two)
#     else:
#         print(MAXS)

#

# 
# c = a.index(max(a))
# m = max(a)
# a.sort()
# d = a[-2]
# for i in range(n):
#     if i == c:
#         print(d)
#     else:
#         print(m)




S = sorted(A)
MAXS = max(A)

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

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for j in range(N)]
k = [int(j) for j in s]
for i in range(0,N-1):
    if max(k) != k[i]:
        print(max(k))
    else:
        t = k[:i]
        u = k[i+1:]
        print(max(max(t, u, key=max)))
del k[N-1]
print(max(k))

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
B = A.copy()
B.sort()
print(B)

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

Submission status: Runtime Error

Solution code:
import copy
import numpy as np

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

B = np.array([])
for i in range(N):
    B = copy.copy(A)
    np.delete(B, i)
    print(max(B)

Submission status: Runtime Error

Solution code:
import numpy as np
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(a[:n].extend(a[n+1:])))

Submission status: Runtime Error

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

for i in range(N):
	k = A.pop(0)
	if k == B[N]:
		print(B[N])
	else:
		print(amax)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for j in range(N)]
k = [int(j) for j in s]
for i in range(0,N-1):
    if max(k) != k[i]:
        print(max(k))
    else:
        t = k[:i]
        u = k[i+1:]
        print(max(max(t, u, key=max)))

Submission status: Runtime Error

Solution code:
N = int(input())
l = []
for i in range(N):
    a = int(input())
    l.append(a)
 
cnt = 0
for i in range(len(l)):
    nl = l
    l = 0
    print(max(nl))
    cnt += 1

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(N):
	k = A.pop(0)
    if k == B[N]:
      print(B[N])
	else:
	  print(amax)

Submission status: Runtime Error

Solution code:
import math
x = input().split(" ")
x = [int(s) for s in x]
for i in range(1,x[0] + 1):
    y = x
    y.pop(i)
    y.pop(0)
    print(y)

Submission status: Runtime Error

Solution code:
N = int(input())
arg = list(map(int, input().split()))
x = [0]*N

for i in range(N, N//2, -1):
  if arg[i-1] == 0:
    x[i-1] = 0
  else:
    x[i-1] = 1

for i in range(N//2, 0, -1):
  others = 0
  for j in range(N, i, -1):
    if j % i == 0:
      others += arg[j-1]
  if arg[i-1] % 2 != others % 2:
    x[i-1] = 1
  else:
    x[i-1] = 0
    
ans = []
if max(x) == 0:
  print(0)
else:
  for index in range(len(x)):
    if x[index] != 0:
      ans.append(index+1)
  print(len(ans))
  print(*ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list()
for i in range(N) :
	A.append(int(input()))
C = list()
for i in range(N) :
	B = copy.deepcopy(A)
	B[i] = 0
	C.append(max(B))
	
for i in range(N) :
	print(C[i])

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for j in range(N)]
k = [int(j) for j in k]
for i in range(0,N-1):
    if max(k) != k[i]:
        print(max(k))
    else:
        t = k[:i]
        u = k[i+1:]
        print(max(max(t, u, key=max)))

Submission status: Runtime Error

Solution code:
seq = []
length = int(input())
for n in range(length):
    num = int(input())
    seq.append(num)
for n in range(length):
    del seq[n]
    print(seq.sort[-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

S = sorted(A)
MAXS = max(A)

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(int(input()) for i in range(n))
if a.count(max(a))==1:
  for y in range(n):
  	if a[y]==max(a):
  		a.remove(a[y])
  		print(max(a))
  	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=[int(input()) for i in range(n)]
for i in range(n):
  print(max(a[:n]+a[n+1:])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

temp_list = sorted(a)
m = temp_list[n-1]


for x in temp_list[::-1]:
  if x == m:
    continue
  else:
    m_dash = x
    break

for a_i in a:
  if a_i == m:
    print(m_dash)
  else:
    print(m)

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 = A[0]
  for i in range(N):
    print(val)
  sys.exit()

else:
  second_max = sorted(A_set)[-2]

tmp_max = max(set(A))
tmp_max_list = [i for i, x in enumerate(A) if x == tmp_max]

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

for i in range(N):
  print(tmp_list[i])

Submission status: Runtime Error

Solution code:
N=int(input())
L=[]
T=[]
for _ in range(N):
  x=int(input())
  L.append(x)
  if x not in T:
    T.append(x)

T.sort()
if not L.count(T[len(T)-1])<N//3
  T.reverse()

for i in range(N):
  for j in range(len(T)):
    if T[j]!=L[i]:
      print(T[j])
      break
    elif len(T)==1:
      print(T[j])

Submission status: Runtime Error

Solution code:
N = int(input())
s = [int(input()) for j in range(N)]
for i in range(0,N-1):
    if max(s) != s[i]:
        print(max(s))
    else:
        t = s[:i]
        u = s[i+1:]
        print(max(max(t, u, key=max)))

Submission status: Runtime Error

Solution code:
N = int(input())
s = [int(input()) for j in range(N)]
for i in range(0,N-1):
    if max(s) != s[i]:
        print(max(s))
    else:
        t = s[:i]
        u = s[i+1:]
        print(max(max(t, u, key=max))

Submission status: Runtime Error

Solution code:
N = int(input())
s = [int(input()) for j in range(N)]
for i in range(0,N):
    if max(s) != s[i]:
        print(max(s))
    else:
        t = s[:i]
        u = s[i+1:]
        print(max(max(t, u, key=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 left_max>=right_max:
        print(left_max)
    else:
        if n==right_max:
            if i ==N-1:
                right_max=0
            else:
                right_max = max(Arr[i+1:])
    
        print(right_max)
    
    if i == N-1:
        return
    
    left_max=max(n,left_max)
    return funct(i + 1, left_max, right_max)


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

Submission status: Runtime Error

Solution code:
N=int(input())
L=[]
T=[]
for _ in range(N):
  x=int(input())
  L.append(x)
  if x not in T:
    T.append(x)

T.sort()
if not L.count(T[len(T)-1])<N//75:
  T.reverse()

for i in range(N):
  for j in range(len(T)):
    elif T[j]!=L[i]:
      print(T[j])
      break
    elif len(T)==1:
      print(T[j])

Submission status: Runtime Error

Solution code:
N = int(input())
s = int([input() for j in range(N)])
for i in range(0,N):
    if max(s) != s[i]:
        print(max(s))
    else:
        t = s[:i]
        u = s[i+1:]
        print(max(max(t, u, key=max))

Submission status: Runtime Error

Solution code:
N=int(input())
L=[]
T=[]
for _ in range(N):
  x=int(input())
  L.append(x)
  if x not in T:
    T.append(x)

T.sort()
if not L.count(T[len(T)-1])!<N//75:
  T.reverse()

for i in range(N):
  for j in range(len(T)):
    elif T[j]!=L[i]:
      print(T[j])
      break
    elif len(T)==1:
      print(T[j])

Submission status: Runtime Error

Solution code:
N = int(input())

List = []
for n in range(N):
	List.append(int(input()))
	List.reverse()

if N%2!=0:
	for i in range(N):
		Ni = List[i]
		List.pop()
		l_max = max(List[0:N/2])
		r_max = max(List[N/2:N])
		if l_max>=r_max:
			print(l_max)
		else:
			print(r_max)
		List.reverse()
		List.append(Ni)
            
         
else:
	for i in range(N):
		Ni = List[i]
		List.pop()
		l_max = max(List[0:int(N//2)])
		r_max = max(List[int((N//2)-1):N])
		if l_max>=r_max:
			print(l_max)
		else:
			print(r_max)
		List.reverse()
		List.append(Ni)

Submission status: Runtime Error

Solution code:

N = int(input())
if 2 <= N <= 200000:
    Input = [input() for i in range(N)]

result = []
n = N
s = 1
m = 2

 
for i in range(N):

    if 1 <= Input[s] <= 200000 or 1 <= Input[m] <= 200000:
        break
    
    if n <= m:
        m = 0
    if n <= s:
        s = 0

    if Input[s] < Input[m]:
        result.append(Input[m])
        m  += 1
        s  += 1
    else:
        result.append(Input[s])
        m  += 1
        s  += 1


for i in  range(len(result)):
    print(result[i])

Submission status: Runtime Error

Solution code:

N = int(input())
if 2 <= N <= 200000:
    Input = [input() for i in range(N)]

result = []
n = N
s = 1
m = 2


for i in range(N):

    if n <= m:
        m = 0
    if n <= s:
        s = 0

    if Input[s] < Input[m]:
        if 1<= Input[m] <= 200000 :
            result.append(Input[m])
            m  += 1
            s  += 1
    else:
        if 1<= Input[s] <= 200000 :
            result.append(Input[s])
            m  += 1
            s  += 1


for i in  range(len(result)):
    print(result[i])

Submission status: Runtime Error

Solution code:
A = stdin.read().split('\n')
A.pop(len(A)-1)
B = []
for i in range(0, int(A[0])):
    B = copy.copy(A)
    B.pop(0)
    B.pop(i)
    print(max(B))

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for i in range(N)]
for i in range(0,N):
    if max(s) != s[i]:
        print(max(s))
    else:
        t = s[:i]
        u = s[i+1:]
        print(max(max(t, u, key=max))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
nplst=np.array([int(input()) for i in range(n)])
m=np.max(nplst)
ans=np.ones(n,dtype="int32")*m
if len(np.where(nplst==m)[0])==1:
  q=int(np.where(nplst==m)[0])
  ans[q]=max(max(nplst[:q]),max(nplst[q+1:]))
a_int = ans.astype(np.str)
print("\n".join(a_int))

Submission status: Runtime Error

Solution code:
import math
x = input().split(" ")
x = [int(s) for s in x]
for i in range(1,x[0] + 1):
    x.pop(i)    
    print(max(x))

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for i in range(N)]
for i in range(0,N):
    if max(s) != s[i]:
        print(max(s))
    else:
        t = s[:i-1]
        u = s[i+1:]
        print(max(max(t, u, key=max))

Submission status: Runtime Error

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

TempMax=max(A)
for j in range(N):
    if A[j] == Tempmax:
        B = copy.copy(A)
        print(max(B.pop(j))
    else: print(TempMax)

Submission status: Runtime Error

Solution code:
N = int(input())
A =[]
for i in range(N):
  A.append(int(input()))
m = max(A)
j = m.index(A)
for k in range(N):
  if k != j:
    print(m)
  else:
    B = A[:]
    del B[j]
    print(max(B))

Submission status: Runtime Error

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

for i in a:
    a.remove(i)
    print( max(b) )
    a.append(i)

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=[]
m=[]
for i in range(n):
  a.append(int(input()))
m.append(a.index(max(a)))
m.append(a.pop(m[0]))
m.append(max(a))

for i in range(m[0]):
  print(m[1])
  
print(m[2])

for i in range(m[0]+1,n):
  print(m[i])

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
nplst=np.array([int(input()) for i in range(n)])
m=max(nplst)
ans=np.ones(n,dtype="int32")*m
if len(np.where(nplst==m))==1:
  q=int(np.where(nplst==m)[0])
  ans[q]=max(max(nplst[:q]),max(nplst[q+1:]))
a_int = ans.astype(np.str)
print("\n".join(a_int))

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 j == 0:
        print(max(a[j+1:N]))
    elif j == N:
        print(max(a[0:j]))
    else:
        if max(a[0:j]) > max(a[j+1:N]):
            print(max(a[0:j]))
        else:
            print(max(a[j:N]))

Submission status: Runtime Error

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

num = max(a)
try:
    num2 = max([k for k in a if k != num])
except:
    pass
for i in range(n):
    if a[i] < num:
        print(num)
    else:
        print(num2)

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 j == 0:
        print(max(a[j+1:N])
    elif j == N:
        print(max(a[0:N])
    else:
        if max(a[0:j]) > max(a[j:N]):
            print(max(a[0:j]))
        else:
            print(max(a[j:N]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import copy


n=int(input())
a = [0] * n
c = [0] * n

for i in range(n):
  a[i]=int(input())
  
b = copy.deepcopy(a)
  
b = list(set(b))
list.sort(b, reverse=True)

for i in range(len(b)):
  c[i] = b.count(a)

if n == 2:
  print(a[1])
  print(a[0])
  
else:
  for i in range(n):
    for j in range(len(b)):
      if a[i] < b[j]:
        print(b[j])
        break
      elif a[i] == b[j] and c[j] == 0:
        print(b[j+1])
        break

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
max_list = a.index(max(a))
max_a = max(a)
if len(max_list) == 1:
  sec_max = sorted(a)[1]
else:
  sec_max = max_a

for i in range(n):
  if i in max_list:
    print(sec_max)
  else:
    print(max_a)

Submission status: Runtime Error

Solution code:
import copy

n = int(input())

a = []

for i in range(1, n+1):
    a.append(int(input()))
    i += 1

for j in range(1, n+1):
    b = copy.deepcopy(a)
    del b[j-1]
    print(max(b)

Submission status: Runtime Error

Solution code:
import numba

@numba.jit  # ここだけ追加
def a(N,s):
    N = int(input())
    s = [int(input()) for i in range(N)]
    for k in s:
        m = s.pop(0)
        print(max(s))
        s.append(m)
N = int(input())
s = [int(input()) for i in range(N)]
a(N,s)

Submission status: Runtime Error

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        token = lines[0].split()
        n = int(token[0])
        for i in range(n):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        token = lines[0].split()
        n = int(token[0])

    a = []
    for i in range(1, n+1):
        a.append(int(lines[i]))

    return (n, a)


def solve(n, a):


    result = []
    x = -1
    y = a[0]
    z = max(a[1:])
    w = z
    for i in range(n):
        b = a[:i]
        c = [a[i]]
        d = a[i+1:]
        if i == 0:
            pass
        elif i == 1:
            x = a[0]
            y = a[1]
            if a[1] < w:
                z = w
            else:
                z = max(a[2:])
            w = max(x, z)
        else:
            x = max(a[i], x)
            y = a[i]
            if a[i] < w:
                z = w
            else:
                if d:
                    z = max(d)
                else:
                    z = -1
            w = max(x, z)
        
        print(w)


def main():
    # 出力

    solve(*parse_input())

if __name__ == '__main__':

    main()

Submission status: Runtime Error

Solution code:
import copy


n=int(input())
a = [0] * n
c = [0] * n

for i in range(n):
  a[i]=int(input())
  
b = copy.deepcopy(a)
  
b = list(set(b))
list.sort(b, reverse=True)

for i in range(len(b)):
  c[i] = b.count(a)

print(a)
print(b)
print(c)

if n == 2:
  print(a[1])
  print(a[0])
  
else:
  for i in range(n):
    for j in range(len(b)):
      if a[i] < b[j]:
        print(b[j])
        break
      elif a[i] == b[j] and c[j] == 0:
        print(b[j+1])
        break

Submission status: Runtime Error

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

num = max(a)
num2 = max([k for k in a if k != num])
for i in range(n):
    if a[i] < num:
        print(num)
    else:
        print(num2)

Submission status: Runtime Error

Solution code:
import copy


n=int(input())
a = [0] * n
c = [0] * n

for i in range(n):
  a[i]=int(input())
  
b = copy.deepcopy(a)
  
b = list(set(b))
list.sort(b, reverse=True)

for i in range(len(b)):
  c[i] = b.count(a)

print(a)
print(b)
print(c)

if n == 2:
  print(a[1])
  print(a[0])
  
else:
  for i in range(n):
    for j in range(len(b)):
      if a[i] < b[j]:
        print(i,b[j])
        break
      elif a[i] == b[j] and c[j] == 0:
        print(i,b[j+1])
        break

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [int(input()) for _ in range(n)]
max = max(a)
for i in range(n):
    index = a.pop(i)
    if index == max:
        print(max(a))
    else:
        print(max)
    a.insert(i, index)

Submission status: Runtime Error

Solution code:
import copy
import sys
def input():
    return sys.stdin.readline()[:-1]
  
 
n=int(input())
num_list=[int(input()) for i in range(n)]
 
buf = [None] * N
 
for i in range(n):
  buf = copy.copy(num_list)
  buf.pop(i)
  print(max(buf))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

a = np.array([int(input()) for _ in range(n)])
[print(np.amax(np.amax(a[:i]), np.amax(a[i+1:]))) for i in range(n)]

Submission status: Runtime Error

Solution code:
N = int(input())
A = [input() for i in range(N)]
ans = 0
Max1 = max(A)
Max2 = sorted(set(A))[-2]
indexes = [i for i, x in enumerate(A) if x == Max1]
for i in range(N):
    ans = Max2 if len(indexes) < 2 and A[i] == Max1 else Max1
    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list()
for i in range(N) :
	A.append(int(input()))
a = max(A)
B = sorted(set(A))
b = B[-2]
for i in range(N) :
	if(A[i] == a) :
		print(b)
	else :
		print(a)

Submission status: Runtime Error

Solution code:
n=input()
n=int(n)
a=[]
for i in range(n):
  s=input()
  a.append(s)
if int(max(a))>=0:
  m=max(a)
else:
  m=min(a)
k=a.index(m)
a.remove(m)
for j in range(k):
  print(m)
if int(max(a))>=0:
  print(max(a))
else:
  print(min(a))
for t in rang

Submission status: Runtime Error

Solution code:
N = int(input())
A = list()
for i in range(N) :
	A.append(int(input()))
a = max(A)
B = sorted(set(nums))
b = B[-2]
for i in range(N) :
	if(A[i] == a) :
		print(b)
	else :
		print(a)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
a = int(input())

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

for j in range(a):
  thisnums = nums
  thisnums[j] = 0
  print(max(thisnums))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import itertools

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

max_list = [0] + list(itertools.accumulate(a, func=max))
max_list_r = [0, *itertools.accumulate(reversed(a), func=max)][::-1]
# print(max_list)
# print(max_list_r)
for i in range(n):
    print(max(max_list[i], max_list_r[i + 1]))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
lst=[]
for i in range(n):
  a=int(input())
  lst.append(a)
nplst=np.array(lst)
m=max(lst)
ans=np.ones(n)*m
if len(nplst[nplst==m])==1:
  q=lst.index(m)
  ans[q]=max(max(nplst[:q]),max(nplst[q+1:]))
for i in range(n):
  print(int(ans[i]))

Submission status: Runtime Error

Solution code:
n=int(input())
x=[]
for i in range(n):
  x.append(int(input()))
cnt = [0] * 10
for i in range(n):
  for j in range(n):
    if i is not j and cnt[i] < x[j]:
      cnt[i]=x[j]
for i in range(n):
  print(cnt[i])

Submission status: Runtime Error

Solution code:
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())
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:
        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())
list = []
for i in range(n):
    list += [int(input())]

max = max(list)
for i in range(n):
    a = list[i]
    if a == max:
        del list[i]
        print(max(list))
        list.insert(i,a)
    else:
        print(max)

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:
from sys import stdin

readline = stdin.readline


def nf():
    """
    入力全て(EOFまで)を`int iter`に変換
    """
    return map(int, open(0).read().split())


def main():
    n, *l = nf()
    al = list(l)
    for i in range(n):
        ma = max([*al[:i], *al[i+1:]])
        print(ma)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
		L.append( max(L[-1], a) )

R=[]
for i,a in enumerate(A[::-1]):
	if i==0:
		R.append(a)
	else:
		R.append( max(R[-1], a) )

R=R[::-1]


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

Submission status: Runtime Error

Solution code:
n=int(input())
a=
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])