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 = [0] * N
for i in range(N):
  A[i] = int(input())
  
for i in range(N):
  A_temp = A[i]
  A[i] = 0
  print(max(A))
  A[i] = A_temp

Submission status: Time Limit Exceeded

Solution code:
import copy

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

B = copy.copy(A) # B=AとするだけではAを変更した時にBも変更してしまう
for i in range(N):
    A[i] = 0
    print(max(A))
    A[i] = B[i]

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    nums = [int(input()) for _ in range(N)]

    for i in range(len(nums)):
        tmp = nums[i]
        nums[i] = 0
    
        print(max(nums))
        
        nums[i] = tmp


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    nums = [int(input()) for _ in range(N)]

    for i in range(len(nums)):
        t = deepcopy(nums)
        t.pop(i)

        print(max(t))


if __name__ == '__main__':
    main()

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):
  temp = a.pop(i)
  max_num = max(a)
  print(max_num)
  a.insert(i, temp)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

s_la = sorted(la, reverse=True)

for a in la:
	max_la = copy.copy(s_la)
	max_la.remove(a)
	print(max_la[0])

Submission status: Time Limit Exceeded

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

for a, b in enumerate(li):
  li2 = li[a+1:] + li[:a]
  print(max(li2))

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):
  print(max(A[:i]+A[i+1:]))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(210000)
input = sys.stdin.readline

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(210000)

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

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

Submission status: Time Limit Exceeded

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

# maxの値と場所, maxを除いた場合のnext_maxを求めておく

# max
if B[0] == B[1] : 
    for i in range(len(A)) : 
        print(B[0])

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

Submission status: Time Limit Exceeded

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

# maxの値と場所, maxを除いた場合のnext_maxを求めておく

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

Submission status: Time Limit Exceeded

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

# maxの値と場所, maxを除いた場合のnext_maxを求めておく

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

Submission status: Time Limit Exceeded

Solution code:
import copy

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

for i in range(n):
    b = copy.deepcopy(a)
    b.pop(i)
    print(max(b))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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 = [int(input()) for i in range(N)]
Ad = [0] *N

for i in range(N):
    Ad[i] = A[i]
    dA = [x-y for (x,y) in zip(A,Ad)]
    print(max(dA))
    Ad[i] =0

Submission status: Time Limit Exceeded

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

for j in range(n):
    tmp = a[j]
    if max(a) == tmp:
        a[j] = 0
        print(max(a))
        a[j] = tmp
    else:
        print(max(a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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(one)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(int(stdin.readline().rstrip()) for _ in range(n))

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(int(stdin.readline().rstrip()) for _ in range(n))

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
l=[]
for i in range(N):
  l.append(int(input()))
i=l.index(max(l))
if i==0:
  l1=l[1:]
  print(max(l1))
  for a in range(N-1):
    print(max(l))
elif i==N:
  l1=l[:N]
  for a in range(N-1):
    print(max(l))
  print(max(l1))
else:
  l1=l[:i]+l[i+1:]
  for a in range(i):
    print(max(l))
  print(max(l1))
  for a in range(N-i-1):
    print(max(l))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
l=[]
for i in range(N):
  l.append(int(input()))
for i in range(N):
  if i==0:
    l1=l[1:]
  elif i==N:
    l1=l[:N]
  else:
    l1=l[:i]+l[i+1:]
  print(max(l1))

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:
    temp = a[1:]
  elif i==n-1:
    temp = a[:i]
  else:
    temp = a[:i]+a[i+1:]
  print(max(temp))

Submission status: Time Limit Exceeded

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

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

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

print(max(a[:n]))

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())

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

for n in range(N):
    temp = copy.deepcopy(A)
    del temp[n]
    print(max(temp))

Submission status: Time Limit Exceeded

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(chinchin)
    else:
        print(chinpo)

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):
    temp = A.pop(i)
    print(max(A))
    A.insert(i, temp)

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = []
for i in range(n):
    number = int(input())
    li.append(number)
temp = []
for i in range(n):
    for j in range(len(li)):
        if i != j:
            temp.append(li[j])
        else:
            temp.append(0)
d = 0
for i in range(n):
    max_num = 0
    for j in range(n):
        if max_num<=temp[d]:
            max_num = temp[d]
        d+=1
    print(max_num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
b = [max(set(a[:x]+a[x+1:])) for x in range(len(a))]
s = str()
for i in b:
	s += str(i)+'\n'
	
print(s)

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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):
    temp = A[i]
    del A[i]
    print(max(A))
    A.insert(i, temp)

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):
    temp = A.pop(i)
    print(max(A))
    A.insert(i, temp)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a_list = [ int(input()) for _ in range(n)]
for i, a in enumerate(a_list):
  tmp_list = copy.copy(a_list)
  tmp_list.pop(i)
  max_val = max(tmp_list)
  print(max_val)

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())
a = [int(input()) for i in range(N)]
for i in range(N):
  b = copy.deepcopy(a)
  del b[i]
  print(sorted(b, reverse=True)[0])

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = list(map(int,[input() for i in range(n)]))
a_copy = copy.copy(a)

for i in range(n):
  a=copy.copy(a_copy)
  a.remove(a[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):
    temp = a[0:i] + a[i + 1:]
    print(max(temp))

Submission status: Time Limit Exceeded

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

for i in range(N):
    B = A.pop(i)
    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)]
a_first = sorted(a)[-1]
a_second = sorted(a)[-2]
for i in range(n):
    print(a_second if i == a.index(a_first) else a_first)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
a_first = sorted(a)[-1]
a_second = sorted(a)[-2]
for i in range(n):
    if i != a.index(a_first):
        print(a_first)
    else:
        print(a_second)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
a_first = sorted(a)[-1]
a_second = sorted(a)[-2]
for i in range(n):
    if i == a.index(a_first):
        print(a_second)
    else:
        print(a_first)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
a_first = sorted(a)[-1]
a_second = sorted(a)[-2]
if a_first == a_second:
    for i in range(n):
        print(a_first)
else:
    for i in range(n):
        if i == a.index(a_first):
            print(a_second)
        else:
            print(a_first)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = [int(input()) for i in range(n)]
for i in range(n):
    b = copy.copy(a)
    del b[i]
    b.sort()
    print(b[-1])

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = [int(input()) for i in range(n)]
for i in range(n):
    b = copy.deepcopy(a)
    del b[i]
    b.sort()
    print(b[-1])

Submission status: Time Limit Exceeded

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

for j in range(len(A)):
    Ai = copy.copy(A)
    del Ai[j]
    print(max(Ai))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
num_dict = {}

num_list = [int(input()) for i in range(N)]
max_num = max(num_list)

for cnt in range(N):
  if num_list[cnt] == max_num:
    print(max(num_list[0:cnt] + num_list[cnt+1:]))
  else:
    print(max_num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

for cnt in range(N):
  print(max(num_list[:cnt] + num_list[cnt+1:]))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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+1:]+a[:i]))

Submission status: Time Limit Exceeded

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

pre_max = 0
af_max = max(A[1:])
print(af_max)
for ii in range(1, N - 1):
    af_max = max(A[ii + 1:])
    pre_max = max(A[ii - 1], pre_max)
    print(max(pre_max, af_max))

print (max(pre_max, A[N - 2]))

Submission status: Time Limit Exceeded

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

Solution code:
N = int(input())
A_lis = [int(input()) for i in range(N)]
a_max = max(A_lis)
for a in A_lis:
  if a == a_max:
    print(sorted(A_lis)[N-2])
  else:
    print(a_max)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

copys = nums.copy()

for ind in range(N):
    copys.pop(ind)
    print(max(copys))
    copys = nums.copy()

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
def input():
	return sys.stdin.readline().rstrip()
def main():
	N = int(input())
	A = [int(input()) for _ in range(N)]
	for i in range(N):
		B = copy.deepcopy(A)
		B.pop(i)
		print(max(B))
if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

def input():
	return sys.stdin.readline().rstrip()
def main():
	N = int(input())
	A = [int(input()) for _ in range(N)]
	for i in range(N):
		B = A[:]
		B.pop(i)
		print(max(B))
if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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

A=max(sequence)
max_index_list=[]
while A in sequence:
    b=sequence.index(A)
    max_index_list.append(b)
    sequence[b]=0
C=len(max_index_list)

Sequence=tuple(sequence)
for i in range(0,N):
    sequence2=list(Sequence)
    sequence2.pop(i)
    if i in max_index_list and C==1:
        print(max(sequence2))
    else:
        print(A)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
max_val = max(A)
for i, num in enumerate(A):
  if num < max_val:
    print(max_val)
  else:
    print(max(A[:i] + A[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[:i] + A[i+1:]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = []
for _ in range(n):
  l.append(int(input()))
m = max(l)
for i in range(0,n):
    if l[i] != m:
      print(m)
    else:
      l.pop(i)
      p = max(l)
      print(p)
      l.insert(i,m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = []
for _ in range(n):
  lst.append(int(input()))
for i in range(n):
  left = lst[:i]
  right = lst[i+1:]
  temp = left+right
  print(max(temp))

Submission status: Time Limit Exceeded

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

for i in range(n):
  temp = a.pop(i)
  tempList = sorted(a)
  print(tempList[n-2])
  a.insert(i,temp)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums = [None] * n

for i in range(n):
    nums[i] = int(input())
sorted_nums = sorted(nums)

for i in range(n):
    if sorted_nums.index(nums[i]) == n - 1:
        max_val = sorted_nums[n - 2]
    else:
        max_val = sorted_nums[n - 1]
    print(max_val)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    # [4, 3, 3, 1, 3, 2]
    A = [int(input()) for _ in range(N)]
    current_max = max(A[1:N])
    # print('---')
    print(current_max)
    previous_max = current_max
    for i in range(1, N):
        A_tmp = A[0:i] + A[i+1:N]
        if previous_max in A_tmp:
            current_max = max([A[i-1], previous_max])
        else:
            current_max = max(A[0:i] + A[i+1:N])
        print(current_max)
        previous_max = current_max


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    # [4, 3, 3, 1, 3, 2]
    A = [int(input()) for _ in range(N)]
    current_max = max(A[1:N])
    # print('---')
    print(current_max)
    previous_max = current_max
    for i in range(1, N):
        if A[i] != previous_max:
            current_max = max([A[i-1], previous_max])
        else:
            current_max = max(A[0:i] + A[i+1:N])
        print(current_max)
        previous_max = current_max


if __name__ == '__main__':
    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_tmp = A[0: i] + A[i+1: N]
        print(max(A_tmp))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#######################################
import numpy as np
import math
import copy
import re
import sys
#sys.exit(0)

inf = float("inf")
prime = 1

def check_print(check_flag, text, end="\n"):
  if check_flag:
    print(text, end=end)

def c2i(x):
    if str.isdecimal(x):
        return int(x)
    else:
        return x

def cout(*args):
  arglist = []
  for arg in args:
    if hasattr(arg, "__iter__"):
      arglist.extend(arg)
    else:
      arglist.append(arg)
      
  arglist = list(map(str, arglist))
  print(" ".join(arglist))
  
def count2(num):
  count=0
  while num%2==0:
    num/=2
    count+=1
  return count

def ketasum(num):
  nums = [int(s) for s in str(num)]
  return sum(nums)

#math
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return a

def lcm(a, b): #最小公倍数
  return a * b // gcd (a, b)

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)

def lcm3(lis): #最小公倍数(3over)
  ans = lis[0]
  for li in lis:
    ans = lcm(ans,li)

def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def is_prime(n):
  for i in range(2, n + 1):
    if i * i > n:
      break
    if n % i == 0:
      return False
  return n != 1

#input stock
"""
n = int(input())

#list
a = map(int, input().split())
a,b = map(int, input().split())

#縦1dim-list
a = [int(input()) for i in range(n)]

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

#2dim-list
a = [list(map(int, input().split())) for i in range(n)]

s = input()
ss =  [int(si) for si in s]
"""

#processing stock
"""
a = sorted(a)
a = sorted(a, reverse=True)

"""

#regex
"""
pattern = ""
result = re.search(pattern, s)

result = re.fullmatch(pattern, s)

result = re.finditer(pattern, s)
for res in result:
    print res.group()   # 1回目: ca      2回目: ca   
    print res.start()   # 1回目: 0       2回目: 6      
    print res.end()     # 1回目: 2       2回目: 8      
    print res.span()    # 1回目: (0, 2)  2回目: (6, 8)
"""


#math
"""
#切り捨て
math.floor()
# 切り上げ
math.ceil()
"""

#######################################
n = int(input())
a = [int(input()) for i in range(n)]
#a = np.array(a)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
from collections import deque
n = int(input())
l = deque([int(input()) for _ in range(n)][::-1])

for i in range(n):
    num = l.pop()
    print(max(l))
    l.appendleft(num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(input()) for _ in range(n)]
m = l.copy()
m = m[::-1]

for i in range(len(l)):
    num = m.pop()
    print(max(m))
    m.insert(0, num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
ahead = 0
back = max(a[1:])
result = [back]
for i in range(1,n-1):
    ahead = max(ahead,a[i-1])
    if back == a[i]:
        back = max(a[(i+1):])
    result.append(max(ahead,back))
ahead = max(ahead,a[n-2])
result.append(ahead)
for j in range(n):
    print(result[j])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

input = sys.stdin.readline

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

    A = np.array(A)
    i = 0

    for a in A:
        print(max(np.delete(A, i)))
        i = i + 1

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
nums = []
for i in range(n):
  nums.append(int(input()))
#print(nums)  

for i in range(n):
  new_list = copy.copy(nums)
  del new_list[i]
  print(max(new_list))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8
def main():
    a = int(input())
    lists = []
    lists= [int(input()) for _ in range(a)]

    temp = lists.copy()

    for i in range(a):
        lists = temp.copy()
        lists.pop(i)
        ans = max(lists)
        print(ans)

if __name__ == '__main__' :
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8
def main():
    a = int(input())
    list = []
    for i in range(a):
        list.append(int(input()))
    temp = list.copy()

    for i in range(a):
        list = temp.copy()
        list.pop(i)
        ans = max(list)
        print(ans)

if __name__ == '__main__' :
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
def input():
    return sys.stdin.readline()
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
def input():
    return sys.stdin.readline()
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

input = sys.stdin.readline

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

    A = np.array(A)

    for i in range(N):
        print(max(np.delete(A, [i], axis=0)))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

    A = np.array(A)

    for i in range(N):
        print(max(np.delete(A, [i], axis=0)))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A = np.array(A)

for i in range(N):
    print(max(np.delete(A, [i], axis=0)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())

input_list = []
tmplist = []

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

for i in input_list:
  tmplist = copy.copy(input_list)
  tmplist.remove(i)
  print(max(tmplist))

Submission status: Time Limit Exceeded

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




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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(int(input()) for i in range(N))
for i in range(N):
    p= A[i]

    M = max(A)
    del A[i]
    MM = max(A)
    if M == MM:
        print(M)
    else:
        print(MM)
    A.insert(i,p)

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):
    temp = List[:]
    temp.pop(i)
    print(max(temp))

Submission status: Time Limit Exceeded

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

tmp_array = []
for i in range(n):
    tmp_array = []
    for m in array_int:
        tmp_array.append(m)
    tmp_array.pop(i)
    max_int   = max(tmp_array)
    print(max_int)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
a_sorted = []
tmp = 0
tmpp = 0

for i in range(n):
    a.append(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 = []
a_sorted = []
tmp = 0

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

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

    a_sorted = sorted(a, reverse=True)

    a[i] = tmp
    
    print(a_sorted[0])