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 = list()
for i in range(n):
    a.append(int(input()))
for i in range(n):
    b = a[:]
    b.pop(i)
    print(max(b))

Submission status: Time Limit Exceeded

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

MAX_1 = max(A)
MAX_2 = sorted(A)[-2]

for i in range(N):
    if i == A.index(MAX_1):
        print(MAX_2)
    else:
        print(MAX_1)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

S = [0] * (N+1)
for i in range(N):
    A.append(int(input()))
    S[i+1] = S[i] + A[i]

for i in range(N):
    MAX = -float('inf')
    for j in range(N):
        if j == i:
            continue
        else:
            MAX = max(MAX, S[j+1] - S[j])
    print(MAX)

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

Submission status: Time Limit Exceeded

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

R = []
for i in range(n):
  R.append(L[0:i]+L[i+1:])

  
for i in range(n):
  print(max(R[i]))

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):
  R = L[0:i]+L[i+1:]
  print(max(R))

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = [int(input()) for _ in range(n)]
ex_a = []
for i in range(n):
  ex_a = copy.deepcopy(a)
  ex_a[i] = -1
  print(max(ex_a))

Submission status: Time Limit Exceeded

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


for j in range(len(lst)):
    if max(lst) != lst[j]:
        print(max(lst))
    else:
        print(sorted(lst)[-2])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
maxa = max(A)
for i in range(N):
    if maxa == A[i]:
        tmp = A[i]
        A[i] = 0
        print(max(A))
        A[i] = tmp
    else:
        print(maxa)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input()) #1行目のNを取得する
list = [input() for i in range(n)] #複数行の数値の入力を取得
lint = [int(s) for s in list]

ans = max(lint)
index = [i for i, x in enumerate(lint) if x == max(lint)]

if len(index) >= 2:
    for i in range(n):
        print(ans)
elif len(index) == 1:
    for i in range(0, index[0], 1):
        print(ans)
    a = lint.pop(index[0])
    print(max(lint))
    lint.append(a)
    for i in range(index[0] + 1, n, 1):
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input()) #1行目のNを取得する
list = [input() for i in range(n)] #複数行の数値の入力を取得
lint = [int(s) for s in list]

ans = max(lint)
index = [i for i, x in enumerate(lint) if x == max(lint)]

if len(index) >= 2:
    for i in range(n):
        print(ans)
elif len(index) == 1:
    for i in range(0, index[0], 1):
        print(ans)
    a = lint.pop(index[0])
    print(max(lint))
    for i in range(index[0] + 1, n, 1):
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input()) #1行目のNを取得する
list = [input() for i in range(n)] #複数行の数値の入力を取得
lint = [int(s) for s in list]

for i in range(n):
    s = lint.pop(0)
    lints = sorted(lint, reverse=True)
    ans = lints[0]
    print(ans)
    lint.append(s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input()) #1行目のNを取得する
list = [input() for i in range(n)] #複数行の数値の入力を取得
lint = [int(s) for s in list]

for i in range(n):
    a = lint.pop(0)
    ans = max(lint)
    print(ans)
    lint.append(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 = A[:]
	del B[i]
	B.sort(reverse = True)
	print(B[0])

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:
from sys import stdin
input = stdin.readline

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy
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(np.max(A))
    A[i] = tmp

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import math
def print_ans(N, ar):
    """Test Case
    >>> print_ans(3, [1, 4, 3])
    4
    3
    4
    >>> print_ans(2, [5, 5])
    5
    5
    """
    for i in range(N):
        ans_max = 1
        for k in range(N):
            if i != k:
                ans_max = max(ans_max, ar[k])
        print(ans_max)

if __name__ == '__main__':
    N = int(input().rstrip())
    ar = [int(input().rstrip()) for i in range(N)]
    print_ans(N, ar)

Submission status: Time Limit Exceeded

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

for i,x in enumerate(A):
  A_=copy.copy(A)
  del A_[i]
  print(max(A_))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
    
    
    
import copy
U=copy.deepcopy(A)
del U[U.index(max(U))]
X=max(U)
Q=max(A)
for i in range(N):
    if i==A.index(Q):
        print(X)
    else:
        print(Q)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
    
    
import copy
U=copy.deepcopy(A)
del U[U.index(max(U))]
for i in range(N):
    if i==A.index(max(A)):
        print(max(U))
    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):
    print(max(A[0:i]+A[i+1:]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
b = []

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

b.sort()
m = 0
l = n+1

for i in range(n):
    m = 0
    l = n+1
    while a[i] != b[(m+l)//2]:
        if a[i] < b[(m+l)//2]:
            l //= 2
        else:
            m = i
    tmp = b[(m+l)//2]
    b[(m+l)//2] = 0
    print(max(b))
    b[(m+l)//2] = tmp

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
b = []

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

for i in range(n):
    b.sort()
    b.remove(a[i])
    print(b[-1])
    b.append(a[i])
    b.sort()

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]
tmp = sorted(A)
for i in range(n):
    if A[i] == max(A):
        print(tmp[-2])
    else:
        print(max(A))

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]

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

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]

for i in range(n):
    if A[i] == max(A):
        tmp = A.pop(i)
        print(max(A))
        A.insert(i, tmp)
    else:
        print(max(A))

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]
A = deque(A)
for i in range(n):
    tmp = A.popleft()
    print(max(A))
    A.append(tmp)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

for i in range(n):
    #print(A)
    tmp = A.pop(i)
    print(max(A))
    A.insert(i, tmp)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
b=[]
for i in range(n):
  k=int(input())
  a.append(k)
  b.append(k)
for j in range(n):
  a.remove(b[j])
  a.sort()
  print(a[n-2])
  a.append(b[j])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
maxnum = max(a)
for i in range(n):
    if a[i] == maxnum:
        tmp = a[i]
        a[i] = 0
        print(max(a))
        a[i] = tmp
    else:
        print(max(a))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
t = 0
for i in range(N):
    A.append(int(input()))
while t != N:
    B = [0] * N
    for i in range(N):
        if t != i:
            B[i] = A[i]
    print(max(B))
    t += 1

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

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    t = c_list[i]
    a_copy = a[:]
    a_copy.remove(t)
    print( a_copy[N - 2] )

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    compare_list = A_list[0:i] + A_list[i+1:]
    print(max(compare_list))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
an = [int(input()) for _ in range(n)]
    
for i in range(n):
        an_i= an[i]
        an[i] = 0
        print(max(an))
        an[i] = an_i

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
an = []
for _ in range(n):
    an.append(int(input()))
    
    
for i in range(n):
        an_copy = an.copy()
        del an_copy[i]
        print(max(an_copy))

Submission status: Time Limit Exceeded

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

A_max = max(A)
for i in range(n):
    if A[i] == A_max:
        print(max(A[0:i] + A[i+1:n]))
    else:
        print(A_max)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
d = deque()
for _ in range(n):
  d.append(int(input()))
for _ in range(n):
  b = d.popleft()
  print(max(d))
  d.append(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.pop(i)
  print(max(a))
  a.insert(i,  b)

Submission status: Time Limit Exceeded

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

for i in range(n):
    ls = l.copy()
    ls.pop(i)
    print(max(ls))

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(0, n):
    if a[i] == max(a):
        print(sorted(a)[-2])
    else:
        print(max(a))

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(0, n):
    tmp = a[i]
    a.remove(a[i])
    print(max(a))
    a.insert(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):
  b=a[i]
  a[i]=0
  print(max(a))
  a[i]=b

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

Submission status: Time Limit Exceeded

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

index = A.index(max(A))
for i in range(N):
  if i==index:
    b=A.pop(i)
    print(max(A))
    A.insert(i,b)
  else:
      print(max(A))

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

Submission status: Time Limit Exceeded

Solution code:
import heapq
import copy

N=int(input())
A=[-int(input()) for i in range(N)]
#print(N,A)

for j in range(N):
    copy_A=copy.copy(A)
    item=copy_A.pop(j)  #負
    #print(item)
    heapq.heapify(copy_A)
    #print(copy_A)
    MAX=-copy_A[0]  #正
    print(MAX)

Submission status: Time Limit Exceeded

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

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

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    temp = 0
    minimum = min(A)
    for i in range(N):
        temp = A[i]
        A[i] = minimum
        print(max(A))
        A[i] = temp


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d=[]
for i in range(n):
  d.append(int(input()))
x=sorted(d)
for j in range(n):
  if d[j]==max(d):
    print(x[n-2])
  else:
    print(max(d))

Submission status: Time Limit Exceeded

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

pop_que =[]

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

#for i in range(N):
#    print(A_list[i][2][1])

Submission status: Time Limit Exceeded

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

pop_que =[]

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

for i in range(N):
    print(A_list[i][2][1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for i 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 = [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 = []
for _ in range(n):
  a.append(int(input()))
  
for i in range(n):
  b = a.copy()
  b.remove(b[i])
  print(max(b))

Submission status: Time Limit Exceeded

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


for i in range(len(S)):
        maax=-100
        for j in range(len(S)):
                if i==j:
                        continue
                if S[j] > maax:
                        maax = S[j]
        print(maax)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import heapq
import copy
N = input()
A = [-int(input()) for _ in range(int(N))]
A_heap = copy.deepcopy(A)
for idx, a in enumerate(A):
    heapq.heapify(A_heap)
    pop_A = heapq.heappop(A_heap)
    pop_A_list = []
    pop_A_list.append(pop_A)
    if pop_A == a:
        pop_A2 = heapq.heappop(A_heap)
        print(-(pop_A2))
        heapq.heappush(A_heap, pop_A)
        heapq.heappush(A_heap, pop_A2)
        continue

    print(-(pop_A))
    heapq.heappush(A_heap, pop_A)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import copy
N = input()
A = [-int(input()) for _ in range(int(N))]
A_heap = copy.deepcopy(A)
for idx, a in enumerate(A):
    heapq.heapify(A_heap)
    pop_A = heapq.heappop(A_heap)
    pop_A_list = []
    pop_A_list.append(pop_A)
    if pop_A == a:
        pop_A = heapq.heappop(A_heap)
        pop_A_list.append(pop_A)

    print(-(pop_A))
    for i in pop_A_list:
        heapq.heappush(A_heap, i)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import copy
N = input()
A = [-int(input()) for _ in range(int(N))]
for idx, a in enumerate(A):
    A_heap = copy.deepcopy(A)
    A_heap.pop(idx)
    heapq.heapify(A_heap)
    pop_A = heapq.heappop(A_heap)
    print(-(pop_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):
  print(max(a[:i]+a[i+1:]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


for i in range(N):
    AA=A[:i]+A[i+1:]
    AA.sort(reverse=False)
    print(AA[-1])

Submission status: Time Limit Exceeded

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

for i in range(N):
    AB=A[:i]+B[i+1:]
    AB.sort(reverse=False)
    print(AB[-1])

Submission status: Time Limit Exceeded

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

for i in range(N):
    X=B.index(A[i])
    Y=B.pop(X)
    print(B[-1])
    B.insert(X,Y)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ary = []
for i in range(N):
    ary.append(int(input()))
maximum = max(ary)
tmp = 0
for i in range(N):
    if ary[i] == maximum:
        tmp = ary[i]
        ary[i] = 0
        print(max(ary))
        ary[i] = tmp
    else:
        print(maximum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ary = []
for i in range(N):
    ary.append(int(input()))
tmp = []
for i in range(N):
    for j in range(0,i):
        tmp.append(ary[j])
    for k in range(i+1,N):
        tmp.append((ary[k]))
    print(max(tmp))
    tmp = []

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for i in range(0,N):
  A.append(int(input()))
#print(A)
print(max(A[1:]))
for j in range(1,N-1):
  print(max(A[:j]+A[j+1:]))
print(max(A[:N-1]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for i in range(0,N):
  A.append(int(input()))
#print(A)
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())
A = [int(input()) for _ in range(N)]
for n in range(N):
    tmp = A.copy()
    tmp.pop(n)
    print(max(tmp))

Submission status: Time Limit Exceeded

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

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]

for n in range(N):
    if A[n] != max(A):
        print(max(A))
    else:
        print(second_A)

Submission status: Time Limit Exceeded

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

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]
max_list = [i for i, x in enumerate(A) if x == max(A)]

if len(max_list) >= 2:
    for n in range(N):
        print(max_A)

else:
    for n in range(N):
        if A[n] != max(A):
            print(max(A))
        else:
            print(second_A)

Submission status: Time Limit Exceeded

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

for n in range(N):
    max_before = max(A[:n], default=0)
    max_after = max(A[n+1:], default=0)
    ans = max(max_before, max_after)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    a = arr[:i] + arr[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):
	t = A[i]
	A[i] = 0
	print(max(A))
	A[i] = t

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
maxa=max(A)
for i in range(N):
  if A[i]==maxa:
    tmp=max(A[:i]+A[i+1:])
    print(tmp)
  else:
    print(maxa)

Submission status: Time Limit Exceeded

Solution code:
import copy, heapq

n = int(input())
a = [int(input())*(-1) for i in range(n)]
b = {}
for j in range(n):
  b = copy.deepcopy(a)
  b[j] = 0
  heapq.heapify(b)
  print(heapq.heappop(b)*(-1))

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
a = [int(input()) for i in range(n)]
b = {}
for j in range(n):
  b = copy.deepcopy(a)
  b[j] = 0
  print(max(b))

Submission status: Time Limit Exceeded

Solution code:
n,*a=map(int,open(0))
for i in range(n):
    x=a[i]
    a[i]=0
    print(max(a))
    a[i]=x

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
b = []
for i in range(n):
    b = sorted(a.copy(), reverse=True)
    if a[i] == b[0]:
        print(b[1])
    else:
        print(b[0])

Submission status: Time Limit Exceeded

Solution code:
def max_cont(n,a_l):
    for i in range(n):
        b = a_l.copy()
        b[i] = 0
        print(max(b))

n = int(input())
a = [int(input()) for _ in range(n)]
b = []
max_cont(n,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[i] = 0
    print(max(b))

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:
from collections import deque
n = int(input())
A = deque([int(input()) for _ in range(n)])
ans = []

for _ 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)]
ans = []

for i in range(len(A)):
    tmp = A.pop(i)
    print(max(A))
    A.insert(i, tmp)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
maximum = []
for i in range(N):
    a = 0
    a = int(input())
    A.append(a)
    if i == 0:
        maximum = [0, a]
    elif maximum[1] < a:
        maximum = [i, a]
A = tuple(A)
B = list(A)

for j in range(N):
    if j == maximum[0]:
        del B[j]
        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()))
A = tuple(A)

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

Submission status: Time Limit Exceeded

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

max_A = max(A)
for i in range(N):
    if A[i] != max_A:
        print(max_A)
    else:
        print(sorted(A, reverse=True)[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):
    B = list(A)
    B.pop(i)
    print(max(B))

Submission status: Time Limit Exceeded

Solution code:
n= int(input())
a=[]
k=0
for _ in range(n):
  a.append(int(input()))
h=max(a)
for i in range(n):
  if a[i]==h:
    a.pop(i)
    print(max(a))
    a.insert(i,h)
  else:
    print(h)

Submission status: Time Limit Exceeded

Solution code:
n= int(input())
a=[]
k=0
for _ in range(n):
  a.append(int(input()))
for i in range(n):
  k=0
  k+=a[i]
  a.pop(i)
  print(max(a))
  a.insert(i,k)

Submission status: Time Limit Exceeded

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

sorted_A = sorted(A, reverse=True)  
for a in A:
  tmp_A = list(sorted_A)
  tmp_A.remove(a)
  print(tmp_A[0])

Submission status: Time Limit Exceeded

Solution code:
import copy

N = input()
A = [0]*N
tmp = [0]*N

for i in range(0,N):
  tmp[i]=int(raw_input())
for i in range(0,N):
  A[i] = copy.deepcopy(tmp)

for i in range(0,N):
  A[i].pop(i)
  print max(A[i])

Submission status: Time Limit Exceeded

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

for i in range(0,N):
  tmp[i]=int(raw_input())
for i in range(0,N):
  A = tmp
  x = A.pop(i)
  print max(A)
  A.insert(i,x)

Submission status: Time Limit Exceeded

Solution code:
n = input()
a = [input() for _ in xrange(n)]
ans = max(a)
for i in xrange(n):
  if a[i] != ans:
    print ans
  else:
    print max(a[:i] + a[i + 1:])

Submission status: Time Limit Exceeded

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

for i in range(n):
    if i == 0:
        print(max(d[1:]))
    elif i == n - 1:
        print(max(d[:-1]))
    else:
        print(max(d[i+1:] + d[:i]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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