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:
import numpy as np

N = int(input())
A_array = np.array([int(input()) for _ in range(N)])

sorted_A_array = sorted(A_array)
max_1st = sorted_A_array[-1]
max_2nd = sorted_A_array[-2]
max_count =sum(A_array == max_1st)

for i in range(N):
    if max_count == 1:
        if A_array[i] == max_1st:
            print(max_2nd)
        else:
            print(max_1st)
    else:
        print(max_1st)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A_array = np.array([int(input()) for _ in range(N)])

print(A_array[1:].max())
for i in range(1, N-1):
    answer = max(A_array[:i].max(), A_array[i+1:].max())
    print(answer)
print(A_array[:N].max())

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N = int(input())
    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)
    for i in range(N):
        B = A[:i]+A[i+1:]
        print(max(B))
resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
readline = sys.stdin.readline
a = [int(input()) for _ in range(n)]

from collections import deque
a = deque(a)

ans = []

for _ in range(n):
    tmp = a.popleft()
    ans.append(max(a))
    a.append(tmp)

print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
readline = sys.stdin.readline
a = [int(input()) for _ in range(n)]

ans = []

for _ in range(n):
    tmp = a.pop(0)
    ans.append(max(a))
    a.append(tmp)

print(*ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = [int(input()) for i in range(n)]
    for i in range(n):
        d = sorted(a, reverse=True)
        if d[0] == a[i]:
            print(d[1])
        else:
            print(d[0])
            
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(input()) for i in range(n)]
X = list(set(A))
X.sort()
X.reverse()
if len(X) == 1 or A.count(max(A)) >= 2:
  for i in range(n):
    print(max(A))
else:
  for i in range(n):
    if A[i] == X[0]:
      print(X[1])
    else:
      print(X[0])

Submission status: Time Limit Exceeded

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

for i in range(n):
  X = A
  X = list(X)
  X.pop(i)
  print(max(X))

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[10]:


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

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


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N = int(input())
    A = [int(input()) for n in range(N)]
    B = A.copy()
    B.sort()
    for i in range(N):
        if max(A) > A[i]:
            print(max(A))
        elif max(A) == A[i]:
            if A.count(max(A)) >= 2:
                print(max(A))
            else:
                print(B[-2])
    return

resolve()

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:
#c
n = int(input())
a = [int(input()) for _ in range(n)]
import copy
ans = []
a_max = max(a)
for i in range(len(a)):
    if a[i]==a_max:
        tmp = copy.deepcopy(a)
        tmp.pop(i)
        print(max(tmp))
    else:
        print(a_max)

Submission status: Time Limit Exceeded

Solution code:
#c
n = int(input())
a = [int(input()) for _ in range(n)]
import copy
ans = []
for i in range(len(a)):
    tmp = copy.deepcopy(a)
    tmp.pop(i)
    print(max(tmp))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
l=[]
for i in range(n):
    z=int(input())
    l.append(z)
for i in range(n):
    print(np.max([x for idx,x in enumerate(l) if idx!=i]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(N):
  _a = a[:i] + a[i+1:]
  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):
    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 _ in range(n)]

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

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

Submission status: Time Limit Exceeded

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

ans = []
tmp = 0
cnt = 0

for i in range(n):
    tmp = []
    for m in range(n):
        if i != m:
            tmp.append(l[m])
    ans.append(max(tmp))


for j in range(n):
    print(ans[j])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[int(input()) for i in range(n)]
for j in range(n):
    kari=l[j]
    l[j]=0
    print(max(l))
    l[j]=kari

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
l=[int(input()) for i in range(n)]
for j in range(n):
    l2=copy.copy(l)
    l2[j]=0
    print(max(l2))

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())

lis = []
for _ in range(n):
    lis.append(int(input()))
    
m = max(lis)

for i in range(n):
    if lis[i] == m:
        tlis = copy.deepcopy(lis)
        tlis.remove(lis[i])
        print(max(tlis))
    else:
        print(m)

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())

lis = []
for _ in range(n):
    lis.append(int(input()))
    
for i in range(n):
    tlis = copy.deepcopy(lis)
    tlis.remove(tlis[i])
    print(max(tlis))

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def solve():
    n=int(input())
    a=[int(input()) for _ in range(n)]
    num1=max(a)
    count=0
    while count!=n:
        if a[count]==num1:
            if count==0:
                print(max(a[1:]))
            elif count==n-1:
                print(max(a[:n-1]))
            else:
                print(max(max(a[:count]),max(a[count+1:])))
        else:
            print(num1)
        count+=1
solve()

Submission status: Time Limit Exceeded

Solution code:
def solve():
    n=int(input())
    a=[int(input()) for _ in range(n)]
    num1=max(a)
    for i in range(n):
        if a[i]==num1:
            if i==0:
                print(max(a[1:]))
            elif i==n-1:
                print(max(a[:n-1]))
            else:
                print(max(max(a[:i]),max(a[i+1:])))
        else:
            print(num1)

solve()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
num1=max(a)
for i in range(n):
    if a[i]==num1:
        if i==0:
            print(max(a[1:]))
        elif i==n-1:
            print(max(a[:n-1]))
        else:
            print(max(max(a[:i]),max(a[i+1:])))
    else:
        print(num1)

Submission status: Time Limit Exceeded

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

for i in range(n):
    # copy.copyを使用することで新しいオブジェクトを生成し、元のリストが影響を受けない
    b = copy.copy(a)
    b.pop(i)
    print(max(b))

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)
    B[i] = 0
    print(max(B))

Submission status: Time Limit Exceeded

Solution code:
n   = int(input())
li1 = [int(input()) for i in range(n)]
li2 = li1.copy()
mx  = max(li1)

for i in range(n):
    if li1[i]==mx:
        li2.remove(li1[i])
        print(max(li2))
        li2.append(li1[i])
    else:
        print(mx)

Submission status: Time Limit Exceeded

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

for i in range(N):
    A_copy = A[:]
    removed_A = A_copy.pop(i)
    print(max(A_copy))

Submission status: Time Limit Exceeded

Solution code:
n   = int(input())
li1 = [int(input()) for i in range(n)]
li2 = li1.copy()

for i in range(n):
    li2.remove(li1[i])
    print(max(li2))
    li2.append(li1[i])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = []

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy
# input
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
  
# main / output
for i in range(n):
  tmp = copy.deepcopy(a)
  del tmp[i]
  print(max(tmp))

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
from itertools import permutations as perm


N = int(input())
#H1,M1,H2,M2,K= map(int,input().split())
#A = list(map(int,input().split()))
#B = list(map(int,input().split()))
#S= str(input())
l=[]
for i in range(N):
    B = int(input())
    l.append(B)

for i in l:
    x=l.copy()
    x.remove(i)
    m=max(x)
    print(m)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

#num = [0]*(N+1)
#for i in range(N):
#num[i+1] = num[i] + A[i]

for j in range(N):
  result = A[:j]+A[j+1:]
  print(max(result))

Submission status: Time Limit Exceeded

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

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 = []

[A.append(int(input())) for x in range(N)]

max_num = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
#A = [int(i) for i in input().split()]
A = [int(input()) for _ in range(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=[0]*n
for i in range(n):
    a[i]=int(input())
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 = []
for i in range(N):
    a = int(input())
    A.append(a)

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

print(ma)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    for _ in range(n):
        tmp = a.pop(0)
        print(max(a))
        a.append(tmp)
   
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(n):
    L = A.pop(0)
    print(max(A))
    A.append(L)

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)
    elif M==A[i]:
        A[i]=0
        print(max(A))
        A[i]=M

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = [int(input()) for _ in range(n)]
for i in range(n):
    list2 = copy.copy(a)
    list2.pop(i)
    print(max(list2))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3


def main():
    N = int(input())
    As = [int(input()) for _ in range(N)]
    for i in range(N):
        tmp = As[:]
        tmp.pop(i)
        print(max(tmp))


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

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

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.pop(0)
	print(max(a))
	a.append(b)

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = [int(input()) for _ in range(n)]
b = copy.copy(a)
b.sort(reverse=True)
s = b[1]
m = max(a)

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = [int(input()) for _ in range(n)]
b = copy.copy(a)
b.sort(reverse=True)
m = max(a)

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    if a[i] != max(a):
        print(max(a))
    else:
        b = copy.copy(a)
        b.pop(i)
        print(max(b))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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):
    memory = a[0]
    a.remove(a[0])
    print(max(a))
    a.append(memory)

Submission status: Time Limit Exceeded

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

for i in range(n):
    memory = a[0]
    a.remove(a[0])
    print(max(a))
    a.append(memory)

Submission status: Time Limit Exceeded

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

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

for i in range(0,n):
  c = a
  temp = c[i]
  c[i] = -1
  print(max(c))
  c[i] = temp
  
#  1 4 3

Submission status: Time Limit Exceeded

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
# print(a)
ans = 0
# print(a[:0]+a[1:])
for i in range(n):
    ans = max(a[:i]+a[(i+1):])
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
#import numpy as np
import math
from fractions import Fraction
import itertools

input=sys.stdin.readline
n=int(input())
a=[int(input()) for _ in range(n)]
print(max(a[1:]))
for i in range(1,n-1):
    print(max(max(a[:i]),max(a[i+1:])))
    
print(max(a[:n-1]))

Submission status: Time Limit Exceeded

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

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

  M = max(A)
for i in range(N):
  if M == A[i]:
    Atmp = A[0:i]
    Atmp.extend(A[i+1:N])
    ans = max(Atmp)
    print(ans)
  else:
    print(M)

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):
  Atmp = A[0:i]
  Atmp.extend(A[i+1:N])
  ans = max(Atmp)
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ll = [[] for _ in range(n+1)]
for i in range(n):
    ll[0].append(int(input()))

count = 1
for i in range(n):
    ll[count] = ll[0].copy()
    ll[count][count-1] = 0
    max = 0
    for j in ll[count]:
        if j>max:
            max = j
        else:
            pass
    print(max)
    count+=1

Submission status: Time Limit Exceeded

Solution code:
# For taking integer inputs.
def inp():
    return(int(input()))


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

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

Submission status: Time Limit Exceeded

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

for j in range(N):
    p = A.pop(j)
    print(max(A))
    A.insert(j, p)

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
a=[0]*n
for i in range(0,n):
  a[i]=int(input())
temp=copy.copy(a)
for i in range(0,n):
  temp[i]=0
  print(max(temp))
  temp=copy.copy(a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

for i in range(N):
    print(max(Alist[:i]+Alist[i+1:]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(input()) for _ in range(N)]
for i in range(len(a)):
  num = a[:]
  num.pop(i)
  print(max(num))

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):
    if i == 0:
        li_s=0
    else:
        li_s = max(a[:i])
    if i == n-1:
        li_g = 0
    else:
        li_g = max(a[i+1:])
    print(max(li_s,li_g))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [0] * n
li = [0] * (n-1)
for i in range(n):
    a[i] = int(input())
for i in range(n):
    li_s = a[:i]
    li_g = a[i+1:]
    li_max = max(li_s,li_g)
    print(max(li_max))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

i = 0

while i != n:
  t = num.pop(0)
  print(max(num))
  num.append(t)
  i += 1

Submission status: Time Limit Exceeded

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

if AList.count(max(AList)) > 1:
    for i in range(N):
        print(max(AList))
else:
    SList=sorted(AList)
    SecMax=SList[-2]
    MaxIndex=AList.index(max(AList))
    
    for i in range(N):
        if i==MaxIndex:
            print(SecMax)
        else:
            print(max(AList))

Submission status: Time Limit Exceeded

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

MList=[]
i=0
while i<N:
    B=str(AList[i])
    AList[i]=0
    MList.append(max(AList))
    AList[i]=int(B)
    
    i+=1

for i in MList:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0] * N
B = [[]]* N
for i in range(N):
  A[i] = int(input())
for j in range(N):
  B[j] = [A[i] for i in range(N) if i != j]
for i in range(N):
  print(max(B[i]))

Submission status: Time Limit Exceeded

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

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

# check
for i in range(N):
    nor_result = [n for j, n in enumerate(A) if j != i]
    if not nor_result:
        continue
    print(max(nor_result))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
#print(a)
lm = [0]
rm = [0]

for i in range(n-1):
    lm.append(max(a[i], lm[i]))

for i in range(n-1, 0, -1):
    rm.insert(0, (max(a[i], rm[n-i-1])))

#print(lm)
#print(rm)

for i in range(n):
    print(max(lm[i], rm[i]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = []
for i in range(n):
    li.append(int(input()))
for i in range(n):
    k = li[i]
    li[i] = 0
    print(max(li))
    li[i] = k

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for _ in range(N)]
ll=sorted(A,reverse=True)
  
for n in range(N):
  if A[n]==max(A):
    print(ll[1])
  else:
    print(max(A))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
l=list()
for n in range(N):
  A=int(input())
  l.append(A)
  ll=sorted(l,reverse=True)
  
for n in range(N):
  if l[n]==max(l):
    print(ll[1])
  else:
    print(max(l))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
l=list()
for n in range(N):
  A=int(input())
  l.append(A)
  
for n in range(N):
  if l[n]==max(l):
    ll=sorted(l,reverse=True)
    print(ll[1])
  else:
    print(max(l))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lst=[int(input()) for i in range(n)]
for j in range(n):
  if j==0:
    print(max(lst[1:]))
  elif j==n-1:
    print(max(lst[:n]))
  else:
    a=max(lst[:j])
    b=max(lst[j+1:])
    print(max(a,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):
    tem=a[i]
    del a[i]
    print(max(a))
    a.insert(i,tem)

Submission status: Time Limit Exceeded

Solution code:
import math
import copy
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nuko = 10

a = []
n = iin()
for i in range(n):
    a.append(iin())
for i in range(n):
    b = copy.copy(a)
    b.pop(i)
    print(max(b))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
an=[]
an=[int(input()) for i in range(n)]
for i in range(n):
    an_a=an[0:i]+an[i+1:n]
    print(max(an_a))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
an=[]
an=[int(input()) for i in range(n)]
for i in range(n):
    an_a=an[0:n]
    an_a.pop(i)
    print(max(an_a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    a = [int(input()) for _ in range(int(input()))]
    st = sorted(a)
    count = len(st)
    for i in a:
        index = st.index(i)
        if index == (count - 1):
            print(st[-2])
        else:
            print(st[-1])


resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    a = [int(input()) for _ in range(int(input()))]
    for i, v in enumerate(a):
        _a = a.copy()
        del _a[i]
        print(max(_a))


resolve()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
tmp=0    
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)]

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

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):
    a_n = copy.copy(a)
    a_n.pop(i)
    print(max(a_n))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
A0=max(A)
for i in range(N):
  if A[i]!=A0:
    print(A0)
  else:
    A.remove(A0)
    A1=max(A)
    print(max(A))
    A.append(A1)

Submission status: Time Limit Exceeded

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

for k in range(N):
  A0=A[0]
  A.remove(A0)

  print(max(A))
  A.append(A0)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
B=[]
for k in range(N):
  A0=A[0]
  A.remove(A0)

  print(max(A))
  A.append(A0)

Submission status: Time Limit Exceeded

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

m=max(a)
for i in range(n):
    if a[i]==m:
        a_new=a[:i]+a[i+1:]
        print(max(a_new))
    else:
        print(m)

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 _ in range(n)]
mx = []
for i in range(n):
    x = a.pop(i)
    mx.append(max(a))
    a.insert(i, x)
for i in range(n):
    print(mx[i])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

b = max(A)

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

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())
A_list= []

for _ in range(N):
    A_list.append(int(input()))

for i, a in enumerate(A_list):
    temp_A_list = copy.copy(A_list)
    temp_A_list.pop(i)
    print(max(temp_A_list))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

seq=[]

for i in range(N):

    a= int(input())
    
    seq.append(a)

left=[0]
for i in range(N-1):
    left_i=max(left[i],seq[i])

    left.append(left_i)

right=[0]

for j in range(N-1):
    right_j = max(right[j],list(reversed(seq))[j])

    right.append(right_j)

right = list(reversed(right))

for k in range(N):
    print(max(left[k],right[k]))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

import numpy as np
seq=np.array([])

for i in range(N):

    a= int(input())
    
    seq=np.append(seq,a)

index=np.argsort(seq)[::-1]
for j in range(N):
    if index[0]==j:
        print(int(seq[index[1]]))
    else:
        print(int(seq[index[0]]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = list(A)
B.sort()
m1 = B[N-1]
m2 = B[N-2]
for i in range(N):
  if A.count(m1) >= 2:
    print(m1)
  else:
    if A[i] == m1:
      print(m2)
    else:
      print(m1)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
m = max(A)
for i in range(N):
  if A.count(m) >= 2:
    print(m)
  elif m == A[i]:
    B = A.pop(i)
    print(max(A))
    A.insert(i,B)
  else:
    print(m)