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(int(input()) for _ in range(N))

A_sort = sorted(A)

for i in range(N):
    v = A[i]
    if v < max(A):
        print(max(A))
    else:
        print(A_sort[-2])

Submission status: Time Limit Exceeded

Solution code:
def solve():

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

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

solve()

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(max(a))

Submission status: Time Limit Exceeded

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

# ほとんどは全体のmax?
m = max(a)
p = a.index(m)

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

# i-1までのmaxはキャッシュする
m1 = 0
for i in range(n):
  p = a[i - 1]
  if i != 0:
    if m1 < p:
      m1 = p
  
  if i != n - 1:
    c = a[i + 1:]
    cm = max(c)
    if m1 < cm:
      print(cm)
    else:
      print(m1)
  else:
    print(m1)
  
  """
  # 遅すぎる
  b = a.copy()
  del b[i]
  print(max(b))
  # 遅すぎる2
  b = a[0:i]
  c = a[i+1:]
  b += c
  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):
  b = a[0:i]
  c = a[i+1:]
  if len(b) > 0:
    b = max(b)
  else:
    b = 0
  if len(c) > 0:
    c = max(c)
  else:
    c = 0

  if b > c:
    print(b)
  else:
    print(c)
  """
  # 遅すぎる
  b = a.copy()
  del b[i]
  print(max(b))
  # 遅すぎる2
  b = a[0:i]
  c = a[i+1:]
  b += c
  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):
  b = a[0:i]
  c = a[i+1:]
  b += c
  print(max(b))
  """
  # 遅すぎる
  b = a.copy()
  del b[i]
  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):
  b = a.copy()
  del b[i]
  print(max(b))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

list_max = max(A)

import copy

for i in range(N):
    if A[i] != list_max:
        print(list_max)
    else:
        _tmp = copy.copy(A)
        _tmp.pop(i)
        print(max(_tmp))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
x=[]
for i in range(N):
    x+=list(map(int,input().split()))    
for j in range(N):
    if j==N-1:
        print(max(x[0:N-1]))
    elif j==0:
        print(max(x[1:N]))
    else:
        print(max(max(x[0:j]),max(x[j+1:N])))

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = [int(input()) for i in range(n)]
A = copy.deepcopy(a)
#print(A)
for i in range(n):
    A.pop(i)
    print(max(A))
    A.insert(i,a[i])

Submission status: Time Limit Exceeded

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

A = [0]*N

for r in range(N):
  A[r] = int(input())
Elias_A = copy.copy(A)
A.sort()
Sorted_A = copy.copy(A)
  
for r in range(N):
  A.remove(Elias_A[r])
  print(A[N-2])
  A = copy.copy(Sorted_A)

Submission status: Time Limit Exceeded

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

A = [0]*N

for r in range(N):
  A[r] = int(input())
Elias_A = copy.copy(A)
A.sort()
Sorted_A = copy.copy(A)

  
for r in range(N):
  A.remove(Elias_A[r])
  print(A[N-2])
  A = copy.copy(Sorted_A)

Submission status: Time Limit Exceeded

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

A = [0]*N

for r in range(N):
  A[r] = int(input())
  
B = copy.copy(A)
  
for r in range(N):
  A.pop(r)
  print(max(A))
  A = copy.copy(B)

Submission status: Time Limit Exceeded

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

for i in range(len(A)):
    exclude_A = A[:i] + A[i+1:]
    max_A = max(exclude_A)
    print(max_A)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
for i in range(n):
   a.append(int(input()))
temp=max(a)
for i in range(n):
    if a[i]<temp:
        print(temp)
    else:
        temp2=a.pop(i)
        print(max(a))
        a.insert(i,temp2)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n=int(input())
a=[]
for i in range(n):
   a.append(int(input()))
q=deque(a)
for i in range(n):
    temp=q.popleft()
    print(max(q))
    q.append(temp)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# C - Exception Handling
N = int(input())
A = [int(input()) for i in range(N)]

#print(A)
max1 = max(A)

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

Submission status: Time Limit Exceeded

Solution code:
# C - Exception Handling
N = int(input())
A = [int(input()) for i in range(N)]

#print(A)

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())
li_a = list()
d_a = dict()

for _ in range(n):
    wk = int(input())
    li_a.append(wk)

    get = d_a.get(wk, 0)
    d_a[wk] = get + 1

for i in range(n):
    d_a_copy = d_a.copy()
    if d_a_copy.get(li_a[i], 0) == 1:
        d_a_copy.pop(li_a[i])
    print(max(d_a_copy.keys()))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li_a = list()
d_a = dict()

for _ in range(n):
    wk = int(input())
    li_a.append(wk)

    get = d_a.get(wk, 0)
    d_a[wk] = get + 1

for i in range(n):
    print(max(k for k, v in d_a.items() if not (k == li_a[i] and v == 1)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li_a = list()
for _ in range(n):
    li_a.append(int(input()))

for i in range(n):
    li_w = li_a[::]
    li_w.pop(i)
    print(max(li_w))

Submission status: Time Limit Exceeded

Solution code:
import heapq  # heapqライブラリのimoprt
N = int(input())
A = []

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

A_init = A[:]
for i in range(N):
  A[i] = 0
  heapq.heapify(A)  # リストを優先度付きキューへ
  ans = -heapq.heappop(A) # 最小値の取り出し
  print(ans)
  A = A_init[:]

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

import copy

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())
A = []
for _ in range(N):
    A.append(int(input()))
list = A
list = sorted(list)
max = list[-1]
second_max = list[-2]
for i in range(N):
    if A[i] == max and A.count(max) == 1:
        print(second_max)
    else:
        print(max)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for _ 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:
import heapq
import copy
N = int(input())
A = []
for _ in range(N):
    A.append((-1) * int(input()))

for i in range(N):
    list = copy.deepcopy(A)
    del list[i]
    heapq.heapify(list)
    print((-1) * heapq.heappop(list))

Submission status: Time Limit Exceeded

Solution code:
import heapq
N = int(input())
A = []
for _ in range(N):
    A.append((-1) * int(input()))

for i in range(N):
    list = A[:i] + A[i + 1:]
    heapq.heapify(list)
    print((-1) * heapq.heappop(list))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
a = deque([int(input()) for _ in range(n)])
for i in range(n):
    ak = a[i]
    del a[i]
    print(max(a))
    a.appendleft(ak)

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]:
        a[i] = 0
        ans = max(a)
        a[i] = m
    else:
        ans = m
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
for i in range(n):
    v = a[i]
    a[i] = 0
    ans = max(a)
    print(ans)
    a[i] = v

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

if L.count(maxL) >= 2:
	for i in range(N):
		print(maxL)
		
else:
	for i in range(N):
		if L[i] == maxL:
			num[i] = i
			L[i] = 0
	
	if max(L) != 0:
		secL = max(L)
	else:
		secL = max(subL)
	
	for i in range(N):
		if i in num:
			print(secL)
		else:
			print(maxL)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
ary = [int(stdin.readline().rstrip()) for _ in range(n)]
for i in range(n):
    print(max(max(ary[:i], ary[i+1:])))

Submission status: Time Limit Exceeded

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

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

for i in range(n):
    if i==0:
        newlist=lists[1:]
        print(max(newlist))
    if i>=1:
        newlist=lists[:i]+lists[i+1:]
        print(max(newlist))

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
ori_a = []
for i in range(n):
    a = int(input())
    ori_a += [a]
for j in range(n):
    co_a = copy.copy(ori_a)
    co_a.pop(j)
    print(max(co_a))

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import copy

n = int(input())
a = []

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

for i in range(n):
	b = copy.deepcopy(a)
	heapq.heapify(b)
	maximum = heapq.heappop(b)
	if maximum == a[i]:
		print(heapq.heappop(b) * (-1))
	else:
		print(maximum * (-1))

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import copy

n = int(input())
a = []

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

for i in range(n):
	b = copy.deepcopy(a)
	b.remove(a[i])
	heapq.heapify(b)
	maximum = heapq.heappop(b) * (-1)
	if maximum == a[i]:
		print(heapq.heappop(b) + (-1))
	else:
		print(maximum)

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import copy

n = int(input())
a = []

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

for i in range(n):
	b = copy.deepcopy(a)
	b.remove(a[i])
	heapq.heapify(b)
	print(heapq.heappop(b) * (-1))

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import copy

n = int(input())
a = []

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

for i in range(n):
	b = copy.deepcopy(a)
	b.remove(a[i])
	b = [-1*tmp for tmp in b]
	heapq.heapify(b)
	print(heapq.heappop(b) * (-1))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
B = []
for i in range(N):
    temp = A[i]
    A[i] = -999
    print(max(A))
    A[i] = temp

Submission status: Time Limit Exceeded

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

for i in range(n):
	b=a.copy()
	b.remove(a[i])
	c[i]=sorted(b)[-1]
for i in range(n):
	print(c[i])

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
d = deque([int(input()) for i in range(n)])

for _ in range(n):
    x = d.popleft()
    print(max(d))
    d.append(x)

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):
    aa = max(a[0:i])
    ab = max(a[i+1:])
    print(max(aa,ab))
print(max(a[:n]))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for i in range(len(list_A)):
    list_check = list_A[:i] + list_A[i+1:]
    print(max(list_check))

Submission status: Time Limit Exceeded

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

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

for i in range(N):
    lstAns = copy.copy(lst)
    a = lstAns.pop(i)
    print(max(lstAns))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nList = [int(input()) for _ in range(N)]
ansList = nList[:]
for i in range(N):
    del ansList[i]
    print(max(ansList))
    ansList = nList[:]

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
input = sys.stdin.readline
 
def main():
    n=int(input())
    a=[0 for _ in range(n)]
    for i in range(n):
        a[i]=int(input())
    M=max(a)
    ans=0
    for i in range(n):
        if(a[i]!=M):
            ans=M
        else:
            ans=0
            for j in range(n-1):
                if(j>=i):
                    j+=1
                if(a[j]>ans):
                    ans=a[j]
            
        print(ans)        
main()

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())
M=max(a)
ans=0
for i in range(n):
    if(a[i]!=M):
        ans=M
    else:
        ans=0
        for j in range(n-1):
            if(j>=i):
                j+=1
            ans=max(ans,a[j])
        
    print(ans)

Submission status: Time Limit Exceeded

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

maxIndex = [i for i, x in enumerate(a) if x == max(a)]
if len(maxIndex)>=2:
    for i in range(n):
        print(max(a))
else:
    z = maxIndex[0]
    s = max(a[0:z],a[z+1:n+1])
    maxa=max(a)
    for k in range(z):
            print(maxa)
    print(s[0])
    for k2 in range (n-z-1):
        print(maxa)

Submission status: Time Limit Exceeded

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

maxIndex = [i for i, x in enumerate(a) if x == max(a)]
if len(maxIndex)>=2:
    for i in range(n):
        print(max(a))
else:
    z = int(maxIndex[0])
    s = max(a[0:z],a[z+1:n+1])
    for k in range(z):
            print(max(a))
    print(s[0])
    for k2 in range (n-z-1):
        print(max(a))

Submission status: Time Limit Exceeded

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

maxIndex = [i for i, x in enumerate(a) if x == max(a)]
if len(maxIndex)>=2:
    for i in range(n):
        print(max(a))
else:
    z = int(maxIndex[0])
    s = max(a[0:z],a[z+1:n+1])
    for k in range(n):
        if k==z:
            print(s[0])
        else:
            print(max(a))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
first = sorted(A)[-1]
second = sorted(A)[-2]
if first == second:
    for i in range(N):
        print(first)
else:
    for i in range(N):
        if i == A.index(first):
            print(second)
        else:
            print(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 i!=0 and i!= N-1:
        ans = max(max(A[:i]),max(A[i+1:]))
    elif i == 0:
        ans = max(A[i+1:])
    else:
        ans = max(A[:i])
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [input() for i in range(n)]
'''
for i in range(n):
    tmp = a[i]
    a.pop(i)
    print(max(a))
    a.insert(i, tmp)
'''
for i in range(n-1):
    if i==0:
        print(max(a[1:]))
    else:
        max1 = max(a[:i])
        max2 = max(a[i+1:])
        print(max(max1, max2))
print(max(a[:n]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [input() for i in range(n)]
for i in range(n):
    tmp = a[i]
    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):
  temp=copy.deepcopy(a)
  temp.pop(i)
  print(max(temp))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def func():
    input_num = int(input(''))
    a_i = [int(input('')) for i in range(input_num) ]
    frag, count = True, [0]*input_num
    count = [1 for i in range(input_num) if a_i[0] == a_i[i]]
    if sum(count) >= 2:
         frag = False
    if frag == True:
        value = [[a_i[i] if a_i[i] != a_i[j] else 0 for i in range(input_num )] for j in range(input_num)]
    else:
        value = [[a_i[i]for i in range(input_num )] for j in range(input_num)]
    for i in range(input_num):
        print(max(value[i]))
if __name__ == '__main__':
    func()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ind = []
m = 0
k = 0
for i in range(n):
    a = int(input())
    if m == a:
        ind.append(i)
        k = a
    elif m < a:
        k, m = m, a
        ind = [i]
    elif k < a:
        k = a
print("\n".join(map(str, [k if i in ind else m for i in range(n)])))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for _ in range(N)]
print(max(A[1:]))
for i in range(1,N-1):
  a=A[:i]
  a.extend(A[i+1:])
  print(max(a))
if N>1:
  print(max(A[:N-1]))

Submission status: Time Limit Exceeded

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

maximum = max(A)
for i in range(N):
    if A[i] == maximum:
        new = A[:]
        new.pop(i)
        print(max(new))
    else:
        print(maximum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
for i in range(N):
    new = A[:]
    new.pop(i)
    print(max(new))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
minv=200000
for i 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:
# -*- coding:utf8 -*-

n = int(input())
l = [int(input()) for _ in range(n)]
m = max(l)
for i in range(n):
    if l[i] != m:
        print(m)
    else:
        print(max(l[:i] + l[i+1:]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf8 -*-

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:
import math

def main(): 

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

    for i in range(n):
        t = list(a)
        t.pop(i)

        print(max(t))




if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

def main(): 

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

    max_value = max(a)
    max_list = [i for i, x in enumerate(a) if x == max_value]
    
    a.pop(max_list[0])
    second_max = max(a)

    for i in range(n):
        if i not in max_list:
            print(max_value)
        else:
            print(second_max)




if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

def main(): 

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

    max_value = max(a)

    for i in range(n):
        if a[i] != max_value:
            print(max_value)
        else:
            t = list(a)
            t.pop(i)

            print(max(t))




if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def test():
    n = int(input())
    a = [int(input()) for i in range(n)]
    s = 0
    for i in range(n):
        s = a[i]
        a[i] = 0
        print(max(a))
        a[i] = s


if __name__ == "__main__":
    test()

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
A = [int(input()) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
c = collections.Counter(A)
Max = max(A)
Max_list = [i for i, v in enumerate(A) if v == max(A)]
for i in range(N):
    if A[i] == Max:
            if len(Max_list) > 1:
                print(A[i])
            else:
                print(set_A[1])
    else:
        print(Max)

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_copy = copy.deepcopy(A)
    A_copy.pop(i)
    print(max(A_copy))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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



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

b = sorted(a)
mx = b[-1]
smx = b[-2]

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

Submission status: Time Limit Exceeded

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



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

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

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

Submission status: Time Limit Exceeded

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



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

b = a[:]
b.sort()

for i in range(test):
	if a[i]==max(a):
		print(b[-2])
	else:
		print(max(a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
s = max(a)
if a.count(s) >= 2:
  for i in range(n):  
    print(s)
else:
  for i in range(n):
    l = a.copy()
    l[i] = 0
    print(max(l))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
s = max(a)
for i in range(n):
  if a[i] == s:
    l = a.copy()
    l[i] = 0
    print(max(l))
  else:
    print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = []
for _ in range(N):
    a.append(int(input()))
tmp = 0
idx = 0
while idx < N:
    tmp, a[idx] = a[idx], tmp
    print(max(a))
    tmp, a[idx] = a[idx], tmp
    idx += 1

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = [int(input()) for _ in range(N)]
    for index in range(N):
        print(max(A[:index] + A[index + 1:]))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
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:
import sys
input = sys.stdin.readline
n=int(input())
a=[]
for _ in range(n):
    a.append(int(input()))

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

Submission status: Time Limit Exceeded

Solution code:
def maxprint(A,i):
    a = list(A)
    a.pop(i)
    print(max(a))

N = int(input())
A = tuple(int(input()) for _ in range(N))


for i in range(N):
    maxprint(A,i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
for i in range(N):
    tmp = A.copy()
    tmp.pop(i)
    tmp.sort()
    print(tmp[-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(1, n):
    if a[i] in a[:i] or a[i] in a[i+1:]:
        ans.append(ans[i-1])
    else:
        max_l = max(a[:i])
        max_r = max(a[i+1:])
        ans.append(max(max_l, max_r))

print(*ans, sep='\n')

Submission status: Time Limit Exceeded

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

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