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: Time Limit Exceeded

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

def anser(arr, i):
    b = a.copy() 
    b.pop(i)
    b = sorted(b)
    print(b[n-2])
    return

for i in range(n):
    anser(a , i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
import sys
input = sys.stdin.readline
for i in range(N):
  A.append(int(input().rstrip()))
from collections import Counter
counter = Counter(A)
B = sorted(set(A), key = A.index)
B = sorted(B, reverse = True)
max_A = B[0]
try:
  second_max = B[1]
except:
  second_max = B[0]
j = False
if counter[max_A] >= 2:
  j = True
for i in range(N):
  if A[i] == max_A and j == False:
    print(second_max)
  else:
    print(max_A)

Submission status: Time Limit Exceeded

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



B = copy.copy(A)

for i in range(N):
    A.pop(i)

    print(max(A))
    A.insert(i, B[i])

Submission status: Time Limit Exceeded

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

def anser(arr, i):
    b = list(arr) # 値渡しと同じ挙動にしたいので、リストのコピーを作る　b=aでは参照渡しになってしまう
    b.pop(i)
    b = sorted(b)
    print(b[n-2])
    return

for i in range(n):
    anser(a , i)

Submission status: Time Limit Exceeded

Solution code:
import copy
N,*D=map(int,open(0).read().split())
for i in range(N):
  A=copy.deepcopy(D)
  del A[i]
  print(max(A))

Submission status: Time Limit Exceeded

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    numbers=[]
    n = int(input())
    [numbers.append(int(input().rstrip())) for _ in range(n)]
    s_numbers=sorted(numbers)

    for i in numbers:
        if i == max(numbers):
            print(s_numbers[-2])
        else:
            print(s_numbers[-1])
    

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

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

for i in range(n):
    if i == 0:
        l = 0
    else:
        l = max(a_l[:i])

    if i == n-1:
        r = 0
    else:
        r = max(a_l[i+1:])
    print(max([l,r]))

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
import math
import itertools
import numpy as np
N = int(input())
A = [int(input()) for c in range(N)]

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    M = max(data)
    if data[i] == M:
        data[i] = 0
        m_d = max(data)
        print(m_d)
        data[i] = M
    else:
        print(M)

Submission status: Time Limit Exceeded

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

import copy

alist_copy = copy.copy(alist)
for i, v in enumerate(alist):
    alist_copy.pop(i)
    print(max(alist_copy))
    alist_copy = copy.copy(alist)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l =[]
for i in range(n):
        a = int(input())
        l.append(a)
        b = max(l)
for i in range(n):
        if l[i] == b:
                del l[i]
                print(max(l))
                l.insert(i,b)

        else:
                print(b)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
maxa = max(a)
if a.count(maxa) > 1:
    for i in range(n):
        print(max(a))
else:
    for j in range(n):
        if a[j] == maxa:
            sorta = sorted(a)
            print(sorta[-2])
        else:
            print(maxa)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
for j in range(N):
    B = A[:j] + A[j+1:]
    print(max(B))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for _ in range(N)]
B=sorted(A)[:N-1]
m=max(A)
for i in range(N):
    if  A[i]==m:
        print(max(B))
    else:
        print(m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = [int(input()) for i in range(a)]
c = sorted(b)[-2]
if b.count(max(b)) >= 2:
  for i in range(a):
    print(max(b))
else:
  for i in b:
    if i == max(b):
      print(c)
    else:
      print(max(b))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    tmp = al[:i] + al[i+1:]
    print(max(tmp))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
m,m2=-1,-1
for i in range(n):
  b=int(input())
  a.append(b)
  m2=max(m2,min(m,b))
  m=max(m,b)

if m==m2:
  for i in range(n):
    print(m)
else:
  for i in range(n):
    if a.index(m)==i:
      print(m2)
    else:
      print(m)

Submission status: Time Limit Exceeded

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

if m==m2:
  for i in range(n):
    print(m)
else:
  for i in range(n):
    if a.index(m)==i:
      print(m2)
    else:
      print(m)

Submission status: Time Limit Exceeded

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

for n in range(N):
  print(max(A[:n]+A[n+1:]))

Submission status: Time Limit Exceeded

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

for i in range(n):
  lis=l[:i]+l[i+1:]
  print(max(lis))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, (input() for i in range(N))))

for i in range(N) :
  x = A[i]
  A.remove(x)
  print(max(A))
  A.insert(i,x)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, (input() for i in range(N))))
for i in range(N):

  print(max(A[:i]+A[i+1:]))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    for i in range(n):
        x = 0
        a[i], x = x, a[i]
        print(max(a))
        a[i], x = x, a[i]

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    for i in range(n):
        a_copy = list(a)
        a_copy.pop(i)
        print(max(a_copy))

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    for i in range(n):
        ans = -1
        for j in range(n):
            if i == j: continue
            ans = max(ans, a[j])
        print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = tuple(int(input()) for i in range(n))
x = a.count(max(a))
if 2 <= x:
    for i in range(n):
        print(max(a))
else:
    for i in range(n):
        if a[i] != max(a):
            print(max(a))
        else:
            print(max(a[:i] + a[i+1:]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
x = a.count(max(a))
if 2 <= x:
    for i in range(n):
        print(max(a))
else:
    for i in range(n):
        if a[i] == max(a):
            print(max(a[:i] + a[i+1:]))
        else:
            print(max(a))

Submission status: Time Limit Exceeded

Solution code:
import copy

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

def delete_list(n,l):
    new_l = l.copy()
    new_l.remove(new_l[n])
    return new_l

for i in range(n):
    print(max(delete_list(i,l)))

Submission status: Time Limit Exceeded

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

copy = num_list.copy()
copy.sort()
maximum = copy[-1]

for i in range(n):
    if num_list[i] == maximum:
        tmp = num_list[:i]+num_list[i+1:]
        tmp.sort()
        print(tmp[-1])
    else:
        print(maximum)

Submission status: Time Limit Exceeded

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

ans_list = []
for i in range(n):
    tmp = num_list.copy()
    tmp = tmp[:i] + tmp[i+1:]
    tmp.sort()
    maximum = tmp[-1]
    ans_list.append(maximum)

for j in ans_list:
    print(j)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
a = deque()
for i in range(n):
    tmp = int(input())
    a.append(tmp)
#print(a)
for i in range(n):
    tmp = a.popleft()
    print(max(a))
    a.append(tmp)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
#print(a)
for i in range(n):
    tmp = a[:i]+a[i+1:]
    #print(tmp)
    print(max(tmp))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
a = deque()
for _ in range(n):
    a.append(int(input()))

for i in range(n):
    tmp = a.popleft()
    print(max(a))
    a.append(tmp)

Submission status: Time Limit Exceeded

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

for i in range(N):
  except_ls = A[:i] + A[i+1:]
  print(max(except_ls))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

for i in range(N):
    new_A = A.copy()
    del new_A[i]
    print(sorted(new_A)[-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

anext=a[:]
for i in range(n):
  anext.remove(anext[i])
  b=max(anext)
  print(b)
  anext.insert(i,a[i])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(int(input()) for _ in range(n))
for i in range(n):
    aa = a.copy()
    del aa[i]
    print(max(aa))

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

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

for i in range(n):
  if i != n-1 :
    a = an[:i] + an[i+1:]
  else :
    a = an[:i]
  print(max(a))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
for i in range(n):
    if i == 0:
        ans = a[1:]
    if i == n:
        ans = a.pop(n)
    ans = a[:i] + a[i+1:]
    print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = [int(input()) for _ in range(n)]
for i in range(n):
    cp_list = a_list.copy()
    cp_list[i] = 0
    print(max(cp_list))

Submission status: Time Limit Exceeded

Solution code:
#C - Exception Handling
N = int(input())
A = list(int(input()) for _ in range(N))
A_sorted = list(set(sorted(A, reverse = False)))

ans = []
for i in A:
    A_copy = A.copy()
    A_copy.remove(i)
    ans.append(max(A_copy))

for i in ans:
    print(i)

Submission status: Time Limit Exceeded

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

for i in range(N):
  A = int(input())
  L[i] = A
  
for i in range(N):
  print(max(L[:i]+L[i+1:]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i, a in enumerate(A):
    print(max(A[:i] + A[i+1:]))

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
A_ = [int(input()) for _ in range(N)]

for i in range(N):
    A = copy.copy(A_)
    A.pop(i)
    print(max(A))

Submission status: Time Limit Exceeded

Solution code:
def solve():
    import sys
    n, *s = map(int, sys.stdin.read().split())
    for i in range(n):
        t = s[:i] + s[i + 1:]
        print(max(t))


solve()

Submission status: Time Limit Exceeded

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

m = max(a)

for i in range(n):
    if m > a[i]:
        print(m)
    else:
        b = a[i]
        a.remove(b)
        print(max(a))
        a.insert(i,b)

Submission status: Time Limit Exceeded

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

for i in range(n):
    b = a[i]
    a.remove(b)
    print(max(a))
    a.insert(i,b)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[]
for i in range(n):
    x=int(input())
    l.append(x)
for i in range(0,len(l)):
    e=l.pop(i)
    d=max(l)
    print(d)
    l.insert(i,e)

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
c = a.count(max(a))
a_2 = copy.copy(a)

if c > 1:
    for i in range(n):
        print(max(a))
else:
    t = max(a)
    a_2.remove(t)
    t_2 = max(a_2)
    for i in a:
        if i == t:
            print(t_2)
        else:
            print(t)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(N):
  if a.index(max(a))==count:
    b = sorted(a)[-2]
    print(b)
  else:
    print(max(a))
  count +=1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

maximum = max(A)
for i in range(N):
    if A[i] != maximum:
        print(maximum)
    else:
        num = A[i]
        A[i] = 0
        print(max(A))
        A[i] = num

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n=deque(int(input()) for _ in range(int(input())))
for _ in range(len(n)): m=n.popleft();print(max(n));n.append(m)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = []
for i in range(N):
    A = int(input())
    a.append(A)
b = []
for i in range(N):
    for j in range(N):
        if i != j:
            b.append(a[j])
        b = sorted(b)
    print(b[-1])
    b = []

Submission status: Time Limit Exceeded

Solution code:
# abc134_c.py
# https://atcoder.jp/contests/abc134/tasks/abc134_c

# C - Exception Handling /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 長さ Nの数列 A1,A2,...,AN が与えられます。 1 以上 N 以下の各整数 iに対し、次の問いに答えてください。
#     数列中の Aiを除く N−1
#     個の要素のうちの最大の値を求めよ。

# 制約
#     2≤N≤200000
#     1≤Ai≤200000
#     入力中のすべての値は整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# A1
# :
# AN

# 出力
# N行出力せよ。i 行目 (1≤i≤N) に、数列中の Ai を除く N−1個の要素のうちの最大の値を出力すること。

# 入力例 1
# 3
# 1
# 4
# 3

# 出力例 1
# 4
# 3
# 4

#     数列中の A1を除く 2 個の要素、A2=4 と A3=3 のうちの最大の値は 4です。
#     数列中の A2を除く 2 個の要素、A1=1 と A3=3 のうちの最大の値は 3です。
#     数列中の A3を除く 2 個の要素、A1=1 と A2=4 のうちの最大の値は 4です。

# 入力例 2
# 2
# 5
# 5

# 出力例 2
# 5
# 5


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # X, A = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    values = list()
    for i in range(N):
        values.append(int(lines[i+1]))
    # valueses = list()
    # for i in range(M):
    #     valueses.append(list(map(int, lines[i+1].split())))

    results = list()
    mi = min(values)
    for n in range(N):
        tmp = values[:n]
        tmp.append(mi)
        maa = max(tmp)
        tmp = values[n+1:]
        tmp.append(mi)
        mab = max(tmp)
        results.append(max(maa, mab))

    return results


# 引数を取得
def get_input_lines():
    line = input()
    N = int(line)
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3', '1', '4', '3']
        lines_export = [4, 3, 4]
    if pattern == 2:
        lines_input = ['2', '5', '5']
        lines_export = [5, 5]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

alcopy = copy.deepcopy(al)
alcopy.sort()
for a in al:
    if a != max(al):
        print(max(al))
    else:
        print(alcopy[-2])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
c = []
mL = 0
mR = 0
# m = 0
m = max(A)
S = copy.copy(A)
for s in S:
    if s == m:
        S.remove(s)
    # print(S[i])
s = max(S)    
# print(s)
for i, a in enumerate(A):
    # print(a)
    if a == m:
        print(s)
    else:
        print(m)
    # if i == 0:
    #     mR = max(A[i + 1 :])
    #     print(mR)
    # elif i == len(A) - 1:
    #     mL = max(A[0: i])
    #     print(mL)
    # else:
    #     mL = max(A[0: i])
    #     mR = max(A[i + 1 :])
    #     m = max(mL, mR)
    #     print(m)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
c = []
mL = 0
mR = 0
m = 0
for i,a in enumerate(A):
    if i == 0:
        mR = max(A[i + 1 :])
        print(mR)
    elif i == len(A) - 1:
        mL = max(A[0: i])
        print(mL)
    else:
        mL = max(A[0: i])
        mR = max(A[i + 1 :])
        m = max(mL, mR)
        print(m)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
A,B=sorted(a,reverse=True)[0:2]
for i in range(n):
    if i==a.index(max(a)):
        print(B)
    else:
        print(A)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
for i in range(N):
    A[i] *= -1
    print(max(A))
    A[i] *= -1

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(int(input()) for i in range(n))
for i in range(n):
    b = list(a)
    b.pop(i)
    print(max(b))

Submission status: Time Limit Exceeded

Solution code:
#<134>
import sys
input = sys.stdin.readline
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
#print(A)
for n in range(N):
    x = A[n]
    A[n] = 0
    print(max(A))
    A[n] = x
    #print(A)

Submission status: Time Limit Exceeded

Solution code:

#<134>
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
#print(A)
for n in range(N):
    x = A[n]
    A[n] = 0
    print(max(A))
    A[n] = x
    #print(A)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

B = copy.copy(A)
B.sort()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n = int(input())
    A = [int(input()) for i in range(n)]
    B = sorted(A)
    for a in A:
        if a == max(B):
            print(B[-2])
        else:
            print(max(B))
resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n = int(input())
    A = [int(input()) for i in range(n)]
    for a in A:
        A_a = A.copy()
        A_a.remove(a)
        print(max(A_a))
resolve()

Submission status: Time Limit Exceeded

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

for i in range(N):
    temp = A[:i] + A[i + 1:]
    print(max(temp))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for _ in range(n):
  a_ = int(input())
  a.append(a_)
  
for i in range(n):
  res = a[i]
  a[i] = 0
  print(max(a))
  a[i] = res

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for i in range(N):
  a = int(input())
  A.append(a)
  
A2 = sorted(A)
mx1 = A2[-1]
mx2 = A2[-2]

for i in range(N):
  if i == A.index(mx1):
    print(mx2)
  else:
    print(mx1)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for i in range(N):
  a = int(input())
  A.append(a)
  
A2 = sorted(A)
mx1 = max(A)
mx2 = A2[-2]

for i in range(N):
  if i == A.index(mx1):
    print(mx2)
  else:
    print(mx1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy

N=int(input())
A=[int(input()) for i in range(N)]
for i in range(N):
  a=deepcopy(A)
  del a[i]
  print(max(a))

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
a = [int(input()) for _ in range(n)]
for i in range(n):
    a_copy = copy.deepcopy(a)
    a_copy.pop(i)
    print(max(a_copy))

Submission status: Time Limit Exceeded

Solution code:
loop = int(input())
nums =[int(input()) for i in range(loop)]
for i in range(0,loop):
  subNums = [v for v in nums]
  del subNums[i]
  print(max(subNums))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    l = a.pop(i)
    print(max(a))
    a.insert(i, l)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
a = deque( int(input()) for i in range(n))
for i in range(n):
    s = a.popleft()
    m = max(a)
    print(m)
    a.append(s)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
a = deque()
for i in range(n):
    j = int(input())
    a.append(j)
for i in range(n):
    s = a.popleft()
    m = max(a)
    print(m)
    a.append(s)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
M=max(A)
sort_A=sorted(A, reverse=True)

for j in range(N):
    if A[j]==M:
        if A.count(M)==1:
            print(sort_A[1])
        else:
            print(M)
    else:
        print(M)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

for j in range(N):
  if j == A.index(max(A)) and A.count(max(A)) == 1:
    B=[i for i in A if i != max(A)]
    print(max(B))
  else:
    print(max(A))

Submission status: Time Limit Exceeded

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

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

for j in range(N):
  B=A[j]
  del A[j]
  print(max(A))
  A.insert(j,B)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import heapq

num = int(input())
a = [int(input()) for i in range(num)]
b = heapq.nlargest(2, a)
c = [b[0] for i in range(num)]
if b[0] == b[1]:
  for j in c:
    print(j)
else:
  for f in range(num):
    if f == a.index(b[0]):
      print(b[1])
    else:
      print(b[0])

Submission status: Time Limit Exceeded

Solution code:
import heapq

num = int(input())
a = [int(input()) for i in range(num)]
for f in a:
  if max(a) == f:
    print(heapq.nlargest(2, a)[1])
  else:
    print(max(a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list()
for x in range(n):
    a.append(int(input()))

for x in range(n):
    tmp = a.pop(x)
    print(max(a))
    a.insert(x, tmp)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list()
for x in range(n):
    a.append(int(input()))

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lis = [int(input()) for _ in range(N)]
l_copy = lis.copy()

for i in lis:
    lis = l_copy.copy()
    lis.remove(i)
    print(max(lis))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A_lis = [int(input()) for _ in range(N)]

A_lis = np.array(A_lis)
for i in range(N):
    ind = np.ones(N, dtype=bool)
    ind[i] = False
    print(max(A_lis[ind]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A_lis = list()
for i in range(N):
    A_lis.append(int(input()))

A_lis = np.array(A_lis)
for i in range(N):
    ind = np.ones(N, dtype=bool)
    ind[i] = False
    print(max(A_lis[ind]))