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 _ in range(n)]

for i in range(n):
    t = a[:]
    print(max(t.pop(i)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
x=[]
x+=list(int(input()) for i in range(N))
L==x
L.sort()
Max=L[N-1]
a=x.index(Max)
Maxsecond=L[N-2]
b=x.index(Maxsecond)
if Max==Maxsecond:
    for j in range(N):
        print(Max)
else:
    for k in range(N):
        if k==a:
            print(Maxsecond)
        else:
            print(Max)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a_max = max(a)
b = a
b.remove(max(b))
b_max = max(b)
for j in range(n):
  if a[j] == a_max:
    print(b_max)
  else:
    print(a_max)

Submission status: Runtime Error

Solution code:
import numpy as np
import heapq
N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
A = np.array(A)
answer = []
for i in range(N):
  A_temp = np.delete(A, i)
  answer.append(heapq.pop(A_temp))
for i in range(N):
  print(answer[i])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import heapq
n=int(input())
d=[]
for i in range(n):
  heapq.heappush(d,int(input()))
for j in range(n):
  if d[j]==d[n-1]:
    print(x[n-2])
  else:
    print(x[n-1])

Submission status: Runtime Error

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

pop_que =[]

for i in range(N):
    pop_que =A_list.pop(0)
    pop_que.append(max(A_list,key=lambda x:x[1]))
    A_list.append(pop_que)

for i in range(N):
    print(f"{A_list[i][2][1]}")

Submission status: Runtime Error

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

pop_que =[]
ans_list= []

print(f"A_list:{A_list}")

for i in range(N):
    pop_que =A_list.pop(0)
    pop_que.append(max(A_list,key=lambda x:x[1]))
    A_list.append(pop_que)

#print(f"A_list[0]:{A_list[0]}")
#print(f"A_list[0][0]:{A_list[0][0]}")
#print(f"A_list[0][2][0]:{A_list[0][2][0]}")

for i in range(N):
    print(f"{A_list[i][2][1]}")

Submission status: Runtime Error

Solution code:
t = True

while(t):
  arr=[]
  try:
    n = input()
    arr.append(n)
  except EOF:
    t = False
    break
  
  for i in range(len(arr)-1):
    print(max(arr[:i]+arr[i+1:]))

Submission status: Runtime Error

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

for r in range(N): A[r] = int(input())
A_max = max(A)
A_sec = sorted(set(A))[-2]

for r in range(N):
  if A[r] == A_max: print(A_sec)
  elif A[r] == A_sec: print(A_max)
  else: print(A_max)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(input()) for n in range(N)]
#print(max(A[1:]))
#for i in range(1,N-1):
m=max(A)
for i in range(N):
	if A[i]<m:
    	print(m)
	else:
    	print(max(A[:i]+A[i+1:]))
#print(max(A[:N-1]))

Submission status: Runtime Error

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

A = [0]*N

for r in range(N):
  A[r] = int(input())
Elias_A = copy.copy(A)
A.sort()
Sorted_A = copy.copy(A)
  
for r in range(N):
  if N >= 3:
    if A[r] == Sorted_A[N-1]: print(A[r])
    elif A[r] == Sorted_A[N-2]: print(A[r])
    elif A[r] == sorted_A[N-3]: print(A[r])
    else:
      A.remove(Elias_A[r])
      print(A[N-2])
      A = copy.copy(Sorted_A)
  else:
    A.remove(Elias_A[r])
    print(A[N-2])
    A = copy.copy(Sorted_A)

Submission status: Runtime Error

Solution code:
N = int(input())
al = [int(input()) for _ in range(0, N)]
for a in al:
  el = filter(lambda x: x != a, al)
  if len(list(el)):
    print(max(el))
  else:
    print(a)

Submission status: Runtime Error

Solution code:
n = int(input())
for i = 0, n-1:
  a(i) = int(input())

print(max(a(1:n-1)))

for i = 1, n-1:
  print(max(a(1:i-2),a(i:n-1)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = [input() for _ in range(N)]
for j in range(N):
    if max(A) == A[i]:
        A.remove(A[i])
        print(max(A))
        A.insert(i,A[i])
    else:
        print(max(A))

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
tmp = 0
for _ in range(N):
    A.append(int(input()))
    for j in range(N):
        tmp = A.pop(j)
        print(max(A))
        A.insert(j,tmp)

Submission status: Runtime Error

Solution code:
def main():

    n,*a = map(int,open('abc134_c.txt').read().split())
    b = sorted(a)
    max = b[-1]
    maxs= b[-2]

    for i in range(n):
        if a[i] == max:
            print(maxs)
        else:
            print(max)
    return()

if __name__=='__main__':
    main()

Submission status: Runtime Error

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

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
a2 = list(set(a))
a2.remove(m1)
m2 = max(a2)

for i in range(n):
  if a[i] == m1:
    print(m2)
  elif a[i] == m2:
    print(max(a[:i]+a[i+1:]))
  else:
    print(m1)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
A_sort = sorted(A)
for i in range(N) :
    if a[i] == a[-1] :
        print(a[-2])
    else :
        print(a[-1])

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = [input() for _ in range(n)]
a_sort = sorted(a)
for i in range(n):
    if i == np.argmax(a):
        print(a_sort[-2])
    else:
        print(a_sort[-1])

Submission status: Runtime Error

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

if N == 2:
    print("\n".join(map(str, A[::-1])))
else:
    for i in range(N):
        if i == N - 1:
            print(max(A[:-1]))
        else:
            print(max(*A[:i], *A[i+1:]))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
a_copy = A
a_max = max(a_copy)
b_max = list(set(a_copy))
b_max.remove(a_max)
b_max = max(b_max)

for i in A:
    if i == a_max:
        print(b_max)
    else:
        print(a_max)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [map(int, input()split()) for _ in range(N)]
for i in range(N) :
    k = A[i]
    del A[i]
    print(max(A))
    A.insert(i, k)

Submission status: Runtime Error

Solution code:
"""長さNの整数A1,A2,...,ANが与えられる。1以上N以下の各整数iに対し、数列中のAiを除くN-1個の要素のうち、最大の値を求める

    N (int): 数列の個数
        Nは整数
        2≦N≦200000
    Ai...N list(int): 数列中の各整数
        整数
        1≦Ai≦200000

考え方として、最大の数値のインデックスが指定された場合は2番目に大きな値を、
それ以外は最大の数値を出力するようにすることで、数列全体を調査するコストを最小に減らすことができる。

Raises:
    ValueError: 数列の個数に制約外の値が指定された場合
"""

from typing import List, Any, Iterable


SEQUENCE_LEN_MIN = 2
SEQUENCE_LEN_MAX = 200000
NUMERIC_MIN = 1
NUMERIC_MAX = 200000


class NumericInfo:
    """数列中の値とその値のインデックスを管理する"""
    def __init__(self):
        # 初期状態は言語仕様・制約上入力されない値を指定する
        self.index = - 1
        self.value = NUMERIC_MIN - 1

    def update(self, idx: int, val: int):
        self.index = idx
        self.value = val

    def copy(self, info: Any):
        self.update(info.index, info.value)


class SequenceProcessor:
    def __init__(self, sequence: List[int]):
        self.sequence_length = len(sequence)
        self.first_largest_num_info = NumericInfo()
        self.second_largest_num_info = NumericInfo()
        self._process(sequence)

    def _process(self, sequence: List[int]):
        """引数で渡される数列をもとに、後の処理で使うインスタンス変数を初期化する
            sequence_length (int): 配列の個数
            first_largest_num_info (NumericInfo): 最大値のインデックスと値
            second_largest_num_info (NumericInfo): 2番目に大きな値のインデックスと値

        Args:
            sequence (List[int]): 数列
        """
        for i, num in enumerate(sequence):
            if self.first_largest_num_info.value < num:
                self.second_largest_num_info.copy(self.first_largest_num_info)
                self.first_largest_num_info.update(i, num)
            elif self.second_largest_num_info.value < num:
                self.second_largest_num_info.update(i, num)

    def _max_value(self, idx: int) -> int:
        """指定されたインデックスの値を除く、数列中の最大値を求める

        Args:
            idx (int): 指定されたインデックス
        """
        if idx == self.first_largest_num_info.index:
            return self.second_largest_num_info.value
        else:
            return self.first_largest_num_info.value

    def all_max_value(self) -> Iterable[int]:
        """数列全てのインデックスに対して、インデックスの値を除く、数列中の最大値を求める
        """
        for i in range(self.sequence_length):
            yield self._max_value(i)


def _validate_sequence_length(s: str):
    """入力値（数列の個数）が制約通りか検証する

    Args:
        s (str): 数列の個数が制約通りか検証する文字列
            制約1. 整数であること
            制約2. 2以上200000以下であること
    Raises:
        ValueError: 制約外の値が渡された場合
   """
    if not s.isdigit():
        raise ValueError("数列の個数の入力値が整数ではありません")
    r = int(s)
    if not SEQUENCE_LEN_MIN <= r <= SEQUENCE_LEN_MAX:
        raise ValueError(
            f"数列の個数は{SEQUENCE_LEN_MIN}から"
            f"{SEQUENCE_LEN_MAX}の間で指定してください")


def get_sequence_length_from_stdin() -> int:
    """数列の個数を標準入力から取得する

    Returns:
        int: 数列の個数
    """
    s = input()
    s = s.strip()
    _validate_sequence_length(s)
    return int(s)


def _validate_numeric(s):
    """入力値（数値）が制約通りか検証する

    Args:
        s (str): 数値が制約通りか検証する文字列
            制約1. 整数であること
            制約2. 1以上200000以下であること
    Raises:
        ValueError: 制約外の値が渡された場合
   """
    if not s.isdigit():
        raise ValueError("数値の入力値が整数ではありません")
    r = int(s)
    if not NUMERIC_MIN <= r <= NUMERIC_MAX:
        raise ValueError(
            f"数値は{NUMERIC_MIN}から{NUMERIC_MAX}の間で指定してください")


def get_sequence_from_stdin(length: int) -> List[int]:
    """標準入力から数列を作成する

    Args:
        length (int): 作成する数列の個数

    Returns:
        List[int]: 数列
   """
    result = []
    for i in range(1, length+1):
        while True:
            n = input()
            try:
                _validate_numeric(n)
                result.append(int(n))
                break
            except ValueError:
                print("入力値に誤りがあります。再入力してください。")
                continue
    return result


def main():
    seq_len = get_sequence_length_from_stdin()
    sequence = get_sequence_from_stdin(seq_len)
    seq_processor = SequenceProcessor(sequence)
    for num in seq_processor.all_max_value():
        print(num)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

for j in range(n):
  big1 = max(l[:n])
  big2 = max(l[n + 1:])
  print(max(big1, big2))

Submission status: Runtime Error

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

for i in range(N):
    for j in range(N):
        A_list[j] = A[j]
    
    A_list[i] = 0
    print(max(A_list))

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
max_a = max(a)
set_a = set(a)
s_set_a = sorted(set(a))[-2]
for i in range(n):
    if max_a == a[i]:
        if len(set_a) == 1:
            print(max_a)
        else:
            print(s_set_a)
    else:
        print(max_a)

Submission status: Runtime Error

Solution code:
import math
import copy
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())
#修正ver
X = [0] * N
for i in range(N):
    B = copy.copy(A)
    del B[i]
    max = max(B)
    X[i] = max
for i in range(N):
    print(X[i])

Submission status: Runtime Error

Solution code:
import math
import heapq
import copy
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())
X = [0] * N
for i in range(N):
    B = copy.copy(A)
    del B[i]
    max = max(B)
    X[i] = max
    print(X[i])

Submission status: Runtime Error

Solution code:
n = int(input())
l=[int(input()) for x in range(n)]
ll=l
for i in range(n):
    l.pop(i)
    print(max(l))
    l.insert(i,ll[i])

Submission status: Runtime Error

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

maxL = max(L)
num = ["n"] * N

if L.count(maxL) >= 2:
	for i in range(N):
		print(maxL)
		
else:
	L = L.remove(maxL)
	secL = max(L)
	
	for i in range(N):
		if i in num:
			print(secL)
		else:
			print(maxL)

Submission status: Runtime Error

Solution code:
n = int(input())
nums = [int(input()) for i in range(n)]
n_max = max(nums)
ex_nums = [i for i in nums].remove(n_max)
n_semi_max = max(ex_nums)
for i in nums:
    if i == n_max:
        print(n_semi_max)
    else:
        print(n_max)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
max_num = -1
for i range(n):
    ipt = int(input())
    if ipt > max_num:
        max_num = max(ipt, max_num)
        idx = i
    a.append(ipt)
a = sorted(a)
if a[-1] == a[-2]:
    for i in range(n):
        print(max_num)
else:
    for i in range(n):
        if i == idx:
            print(a[-2])
        else:
            print(max_num)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
max_num = -1
mode_max = False
for i in range(n):
    ipt = int(input())
    if ipt == max_num:
        mode_max = True
    else:
        max_num = max(ipt, max_num)
        a.append(ipt)
if mode_max:
    for i in range(n):
        print(max_num)
else:
    a_copy = a[:]
    idx = a.index(max_num)
    a_copy.remove(max_num)
    sub_max = max(a_copy)
    for i in range(n):
        if i == idx:
            print(sub_max)
        else:
            print(max_nums)

Submission status: Runtime Error

Solution code:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if len(a)!=1:
  maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Submission status: Runtime Error

Solution code:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Submission status: Runtime Error

Solution code:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
maxa2=sorted(set(nums))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Submission status: Runtime Error

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

for i in range(n):
  listA=list.remove[i]
  print(max(listA))

Submission status: Runtime Error

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

max_num = max(A)

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

Submission status: Runtime Error

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

max_num = max(A)

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

Submission status: Runtime Error

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

max_num = max(A)

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

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
MAX1=max(A)
copyA=A.copy()
copyA.remove(MAX)
MAX2=max(copyA)
for i in A:
  if (i==MAX1):
    print(MAX2)
  else:
    print(MAX1)

Submission status: Runtime Error

Solution code:
from heapq import heappush, heappop

N = int(input())
A = [int(input()) for i in range(N)]
hq = []
for i in range(N):
    heappush(hq, -A[i])
max1 = -heappop(hq)
while True:
    max2 = -heappop(hq)
    if max2 != max1:
        break
ans = [0] * N
for i in range(N):
    if A[i] == max1:
        ans[i] = max2
    else:
        ans[i] = max1
print(*ans, sep="\n")

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input()))
m, i = 0, -1
for j in range(len(A)):
  if A[j] > m:
    m, i = A[j], j
B = A[:]
B.remove(m)
M = max(B)
for k in range(len(A)):
  if k != i:
    A[k] = m
  else:
    A[k] = M
for l in range(len(A)):
  print(A[l])

Submission status: Runtime Error

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



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

b = a[:]
b.reamove(max(a))
mx = max(a)
smx = max(b)

for i in range(test):
	if a[i]==max(a):
		print(smx)
	else:
		print(mx)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
B = sorted(A,reverse=True)
if B[0] = B[1]:
    for i in range(N):
        print(B[0])
else:
    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_list = []
max_num = 0
sub_max = 0
all_max = False
if n == 2:
    a_list.append(int(input))
    print(a_list[1])
    print(a_list[0])
else:
    for i in range(n):
        a = int(input())
        a_list.append(a)
        if sub_max < a:
            if max_num < a:
                sub_max = max_num
                max_num = a
                idx = i
            else:
                sub_max = a
        elif max_num == a:
            max_num = a
            all_max = True
    if all_max:
        for i in range(n):
            print(max_num)
    else:
        for i in range(n):
            if i == idx:
                print(sub_max)
            else:
                print(max_num)

Submission status: Runtime Error

Solution code:
n = int(input())
for i in range(n):
  a = [int(j) for j in input().split()]
  a[i] = 0
  print(max(a))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
m1,m2,_ = sorted(A)[::-1]

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

Submission status: Runtime Error

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

lis = sorted(li)
for i in range(N):
  if lis[-1] == li[i]:
    print(lis[-2])
  else: print(lis[-1])

Submission status: Runtime Error

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

lis = sorted(li)
for i in range(N):
  if lis[-1] == li[i]:
    print(lis[-2])
  else: print(lis[-1])

Submission status: Runtime Error

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

lis = li.sorted()
for i in range(N):
  if lis[-1] == li[i]:
    print(lis[-2])
  else: print(lis[-1])

Submission status: Runtime Error

Solution code:
N = int(input())

idx_1st=1
val_1st=1
idx_2nd=0
val_2nd=0

for i in range(N):
  Ai = int(input())
  if Ai>=val_1st:
    idx_2nd=idx_1st
    val_2nd=val_1st
    
    idx_1st=i
    val_1st=Ai
    
  elif Ai<val_1st:
    if Ai>val_2nd:
      idx_2nd=i
      val_2nd=Ai
    else:
      raise ValueError
  else:
    raise ValueError

for i in range(N):
  if i!=idx_1st:
    print(val_1st)
  elif i==idx_1st:
    print(val_2nd)
  else:
    raise ValueError

Submission status: Runtime Error

Solution code:
n, *a = map(int, open(0).read().split())
a2 = sorted(a)[:-2]
for i in range(n):
    if a[i]==a2[1]:
        print(a[0])
    else:
        print(a[1])

Submission status: Runtime Error

Solution code:
n, *a = map(int, read(0).open().split())
a2 = sorted(a)[:-2]
for i in range(n):
    if a[i]==a2[1]:
        print(a[0])
    else:
        print(a[1])

Submission status: Runtime Error

Solution code:
n = int(input())
s=[''.join(int(input())) for i in range(n)]
s_sort=sorted(s,reverse=True)
for i in range(n):
    if s[i] == s_sort[0]:
        print(s_sort[1])
    else:
        print(s_sort[0])

Submission status: Runtime Error

Solution code:
a=int(input())
b=list(map(int, input().split()))
cou,ju=0,0
ans=[]
while cou<a:
  i=1
  su=0
  while i*(cou+1)<a:
    su+=b[i*(cou+1)]
    i+=1
  if su%2!=b[cou]:
    ans+=[cou+1]
  cou+=1
if ans==[]:
  print("0")
else:
  s=""
  for i in ans:
    s+=str(i)+" "
  print(s)

Submission status: Runtime Error

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

mi = li.index(max(li))
m = max(li)

for a, b in enumerate(li):
  if a != mi:
    print(m)
  else:
    print(max(l[a+1:]+l[:a]))

Submission status: Runtime Error

Solution code:
#また長さが1の時を考慮していない
#出来るだけループの外で計算する
n=int(input())
a=[int(input()) for i in range(n)]
m1=max(a)
m2=sorted(a,reverse=True)[1]
for i in range(n):
    if m==a[i]:
        print(m2)
    else:
        print(m1)

Submission status: Runtime Error

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [int(input().rstrip('\n')) for _ in range(n)]
    b = sorted(a.copy(), reverse=True)
    for i in a:
        if i == b[0]:
            print(b[1])
        else:
            print(b[0])


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
l,r=map(int,input().split())
ll=l%2019
rr=r%2019

ans=float('inf')
for i in range(ll,rr):
    for j in range(i+1,rr+1):
        ans=min(ans,i*j%2019)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
li = list(int(stdin.readline().rstrip()) for _ in range(n))
one = max(li)
two = sorted(li)[-2]
for i in range(n):
    if max(li) == li[i]:
        print(two)
    else:
        print(max(one))

Submission status: Runtime Error

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
li = list(int(stdin.readline().rstrip()) for _ in range(n))
one = max(li)
two = sorted(li)[-2]
for i in range(n):
    if max(li) == li[i]:
        print(two)
    else:
        print(max(one)

Submission status: Runtime Error

Solution code:

N = int(input())

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

B = A.copy()

B = sorted(list(set(B)))

max = B[-1]
n_max = B[-2]


for a in A:
    if a == max:
        print(n_max)
    else:
        print(max)

Submission status: Runtime Error

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

k = [i for i, x in enumerate(a) if x == m]

if len(k)>=2:
	for i in range(n):
		print(m)
else:
	b = a
	b.pop(m)
	m2 = max(b)
	for i in range(n):
		if i != m:
			print(m)
		else:
			print(m2)

Submission status: Runtime Error

Solution code:
import copy

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

chinpo = max(A)
B = copy.copy(A)
B.remove(max(A))
chinchin = max(B)

for i in range(N):
    if i == A.index("max(A)"):
        print(chinpo)
    else:
        print(chinchin)

Submission status: Runtime Error

Solution code:

import copy

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

chinpo = max(A)
B = copy.copy(A)
while max(A) in B:
    B.remove(max(A))
chinchin = max(B)

for i in range(N):
    if chinpo > A[i]:
        print(chinpo)
    else:
        print(chinchin)

Submission status: Runtime Error

Solution code:
A = list()
B = [0] * 200000

for i in range(N):
  i = int(input())
  A.append(i)
  
C = sorted(A,reverse=True)

for k in range(N):
  if max(A) != A[k]:
    print(C[0])
  else:
    B[k] = A[k]
    A[k] = 0
    print(max(A))
    A[k] = B[k]

Submission status: Runtime Error

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

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

for k in range(N):
  if max(A) != A[k]:
    print(max(A))
  else:
    B[k] = A[k]
    A[k] = 0
    print(max(A))
    A[k] = B[k]

Submission status: Runtime Error

Solution code:
n,*a=map(int,open(0).read().split())
b=0
while n>b:
    list.remove(a[b])
    print(max(a))
    list.append(a[b])
    b+=1

Submission status: Runtime Error

Solution code:
import sys
a = list(map(int,sys.stdin.readline().split()))
n = a.pop(0)

for i in range(n):
	b = set(a[:i]+a[i+1:])
	print(max(b))
	del b

Submission status: Runtime Error

Solution code:
N = int(input())
a = [int(input()) for i in range(N)]
for i in range(N):
  b = a
  del b[i]
  sorted(b)
  print(b[0])

Submission status: Runtime Error

Solution code:

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

L = [0] * (max(A)+1)
R = [0] * (max(A)+1)

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

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

#print(L)
#print(R)

for i in range(N):
    ans = max(L[i], R[i+1])
    print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
b=sorted(a,reverse=True)
m=set(b)
M=m[0]
indexes=[j for j,x in enumerate(a) if x==M]
for k in range(n):
  if a[k]==M and len(indexes)==1:
    print(m[1])
  else:
    print(M)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
b=a
b.sort(reverse=True)
m=set(b)
M=m[0]
indexes=[j for j,x in enumerate(a) if x==M]
for k in range(n):
  if a[k]==M and len(indexes)==1:
    print(m[1])
  else:
    print(M)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
m=set(sorted(a,reverse=True))
M=m[0]
indexes=[j for j,x in enumerate(a) if x==M]
for k in range(n):
  if a[k]==M and len(indexes)==1:
    print(m[1])
  else:
    print(M)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
M=max(a)
indexes=[j for j,x in enumerate(a) if x==M]
for k in range(n):
  if a[k]==M and len(indexes)==1:
    print(max(max(a[:k]),max(a[k+1:])))
  else:
    print(M)

Submission status: Runtime Error

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

B = list(A)

for j in range(N):
    B.pop(j)
    print(max(B))
    B = list(A)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
m1, m2 = sorted(A, reverse=True)[:2]

for i in range(N):
    if i == p:
        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):
  print(max(max(a[:j]),max(a[j+1:])))

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
tmp = sorted(a)
mx = max(a)
cnt = a.count(mx)

for t in a:
    if t == mx and -cnt-1 < len(a):
        print(tmp[-cnt-1])
    else:
        print(mx)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
tmp = sorted(a)
mx = max(a)
cnt = a.count(mx)

for t in a:
    if t == mx:
        print(tmp[-cnt-1])
    else:
        print(mx)

Submission status: Runtime Error

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

for j in a:
    if j >= max(a):
        print(sorted(a)[-2])
    else:
        print(max(a))

Submission status: Runtime Error

Solution code:
N = int(input())

nums = [int(input()) for x in range(N)]

a = sorted(nums)[-1]#max(nums)
b = sorted(nums)[-2]#max(nums.remove(max_num))



if a == b:
    for _ in range(nums):
        print(a)
else:
    for x in [b if x == a else a for x in nums]:
        print(x)

Submission status: Runtime Error

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

max_val = max(A)
subset = list(set(A))
subset.remove(max_val)
max_val_2 = max(subset)
count = A.count(max_val)

for i, num in enumerate(A):
  if num < max_val:
    print(max_val)
  else:
    if count > 1:
      print(max_val)
    else:
      print(max_val_2)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;++i)
#define MOD (int) 1e9+7
#define INF (int) 2e9

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n){
        cin >> a[i];
    }
    int maxl[n], maxr[n];
    maxl[0] = 0;
    maxr[n-1] = 0;
    
    for (int i = 1; i < n; i++){
        maxl[i] = max(maxl[i-1], a[i-1]);
    }
    for (int i = n-2; i >= 0; i--)
    {
        maxr[i] = max(maxr[i+1], a[i+1]);
    }

    rep(i, n){
        cout << max(maxl[i], maxr[i]) << endl;
    }

    // printf("%d\n", N);
    return 0;
}

Submission status: Runtime Error

Solution code:
import glob
import numpy as np
import collections


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\134\\C'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'


class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class C(Common):

    def resolve(self):

        seq_len = int(self.input_data())
        seq = np.array([0 for i in range(seq_len)])
        for i in range(seq_len):
            seq[i] = int(self.input_data())

        max_num = np.max(seq)
        times = collections.Counter(seq)[max_num]

        if times >= 2:
            for i in range(seq_len):
                print(str(max_num))
        else:
            for i in range(seq_len):
                if seq[i] != max_num:
                    print(str(max_num))
                else:
                    print(np.max(seq[0:i]) if np.max(seq[0:i]) > np.max(seq[i+1:seq_len]) else np.max(seq[i+1:seq_len]))


solver = C(REL_PATH)
solver.exec_resolve()