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 = []
for i in range(N):
  A.append(int(input()))
m = max(A)
for i in range(N):
  if m == A[i]:
    B = A.pop(i)
    print(max(A))
    A.insert(i,B)
  else:
    print(m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

ans[0] = max(A[1:])
ans[N-1] = max(A[:-1])

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array([int(input()) for i in range(N)])
ans = np.zeros(N, dtype=int)

ans[0] = A[1:].max()
ans[N-1] = A[:-1].max()

for i in range(1, N-1):
    left = A[:i].max()
    right = A[i+1:].max()
    ans[i] = max(left, right)

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

Submission status: Time Limit Exceeded

Solution code:
# C - Exception Handling

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,*A =map(int,open(0).read().split())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Max = max(A)
for i in range(n):
  if A[i] != Max:
    print(Max)
  else:
    print(max(set(A[:i] + A[i+1:])))

Submission status: Time Limit Exceeded

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

Max = max(A)
for i in range(n):
  if A[i] != Max:
    print(Max)
  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):
    tmp = a[i]
    a[i] = 0
    print(max(a))
    a[i] = tmp

Submission status: Time Limit Exceeded

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

for i in range(n):
    temp = 0
    if(max(a) == a[i]):
        temp = a[i]
        a[i] = 0
        print(max(a))
        a[i] = temp
    else: 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):
    dum = a_list[i]
    a_list[i] = 0
    print(max(a_list))
    a_list[i] = dum

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
aa = [0,0]
for i in range(n):
    if a[i] > aa[-1]:
        aa[-1] = a[i]
    else:
        if a[i] >= aa[-2]:
            aa[-2] = a[i]

if aa[-1] == aa[-2]:
    for i in range(n):
        print(aa[-1])
else:
    for i in range(n):
        if i == a.index(aa[-1]):
            print(aa[-2])
        else:
            print(aa[-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import math
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    MAX = max(A)
    Ms = [-1]*N
    for i in range(N):
        if A[i] == MAX:
            A[i] = 0
            Ms[i] = max(A)
            A[i] = MAX
        else:
            Ms[i] = MAX
    for i in range(N):
        print(Ms[i])

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:


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

for i in range(n):
  cal_a = sorted_a.copy()
  cal_a.remove(a[i])
  print(cal_a[-1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
b = sorted(a,reverse=True)
m = b[0]
if b[0] == b[1] and b[0] == m:
    for i in range(n):
        print(m)
else:
    for i in range(n):
        if a[i] == m:
            print(max(b[1:]))
        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())
b = sorted(a,reverse=True)
if b[0] == b[1] and b[0] == max(a):
    for i in range(n):
        print(max(a))
else:
    for i in range(n):
        if a[i] == max(a):
            print(max(b[1:]))
        else:
            print(max(a))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = []
for i in range(N):
    A = int(input())
    l.append(A)
ans = [0]*N
m = max(l)
for i in range(N):
    n = l[i]
    if  n == m:
        l[i] = 0
        ans[i] = max(l)
        ans = ans[:i+1]
        ans.extend([n]*(N-i-1))
        break
    ans[i] = max(l)
[print(i) for i in ans]

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=[int(input()) for i in range(n)]
    if len(set(l))==1:
        for i in range(n):
            print(max(l))
    else:
        biggest = max(l)
        lsort=sorted(l)
        niban=lsort[-2]
        for j in range(n):
            if l[j]!=biggest:
                print(biggest)
            else:
                print(niban)
resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.buffer.readline
n=int(input())
L=list(int(input()) for i in range(n))
for i in range(n):
    N=sorted(L)
    print(N[-1] if L[i]!=N[-1] else N[-2])

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
L=list(int(input()) for i in range(n))
for i in range(n):
    N=sorted(L)
    print(N[-1] if L[i]!=N[-1] else N[-2])

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
L=list(int(input()) for i in range(n))
for i in range(n):
    N=L[:i]+L[i+1:]
    print(max(N))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [input() for i in range(N)]
for j in range(N):
    L1 = L.copy()
    del L1[j]
    print(max(L1))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
#print('l1',l)

for i in range(n):
    print(max(l[1:]))
    l.append(l[0])
    l.pop(0)
    #print('l2',l)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for i in range(n):
    big = 0
    for j in range(n):
        if j == i: continue
        big = max(big, a[j])
    print(big)

Submission status: Time Limit Exceeded

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

for i in range(n):
  acp = a.copy()
  acp[i] = 0
  acp.sort()
  print(acp[-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
def main():
    N = int(input())
    A = [int(input()) for a in range(N) ]
    for i in range(N):
        tmp = copy.copy(A[i])
        A[i] = 0
        print(max(A))
        A[i] = copy.copy(tmp)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

n=int(sys.stdin.readline())
a=np.array([sys.stdin.readline() for _ in range(n)],dtype='int64')


for i in range(n):
    if i==0:
        print(max(a[i+1:]))
    elif i==n-1:
        print(max(a[:i]))
    else:
        print(max(max(a[:i]),max(a[i+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):
    excp = a.pop(j)
    print(max(a))
    a.insert(j, excp)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
maxi = max(a)
for i in range(n):
  if a[i] == maxi:
    b = []
    b += a
    b.sort()
    print(b[-2])
  else:
    print(maxi)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = [INT() for _ in range(N)]

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

Submission status: Time Limit Exceeded

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

ans_li = [max(a_inputs[0:max(i,0)]+a_inputs[min(i+1,n):n]) for i in range(n)]

for ans in ans_li:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


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

max_a = max(A)
max_idx = [i for i, x in enumerate(A) if x == max_a]


for i in range(N):
    if i in max_idx:
        tmp = A[i]
        A[i] = NIL
        print(max(A))
        A[i] = tmp
        continue

    print(max_a)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


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

max_a = max(A)

for i in range(N):
    if A[i] == max_a:
        tmp = A[i]
        A[i] = NIL
        print(max(A))
        A[i] = tmp
        continue

    print(max_a)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


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

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




# def main():

# if __name__ == '__main__':
#     main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()

N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""
N = int(input())
A = [int(input()) for _ in range(N)]

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




# def main():

# if __name__ == '__main__':
#     main()

Submission status: Time Limit Exceeded

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

cnt = Counter(a)
for i in range(n):
  temp = cnt.copy()
  temp[a[i]] -= 1
  if temp[a[i]] == 0:
    del temp[a[i]]

  print(max(temp.keys()))

Submission status: Time Limit Exceeded

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

    if max(a) > a[i]:
        print(max(a))
    else:
        if a.count(a[i]) > 1:
            print(a[i])
        else:
            print(b[-2])

Submission status: Time Limit Exceeded

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

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(max(a))
    else:
        if a.count(a[i]) > 1:
            print(a[i])
        else:
            print(sorted(a)[-2])

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.pop(i)
    print(max(a))
    a = [num]+a

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=[]
for i in range(N):
    a.append(int(input()))
for j in range(N):
    k=a.pop(j)
    mx=a[0]
    for l in range(1,N-1):
        mx=max(mx,a[l])
    print(mx)
    a.insert(j,k)

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):
    k=a.pop(j)
    print(max(a))
    a.insert(0,k)

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[i]
  a.pop(i)
  print(max(a))
  a.insert(i,x)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
while True:
  try:
    a.append(int(input()))
  except:
    break

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

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for i in range(n)]
for j in range(n):
    B = A.copy()
    B.remove(B[j])
    print(max(B))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
result = []
for i in range(N):
    C = A[i]
    A[i] = 0
    result.append(max(A))
    A[i] = C

for a in result:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
B = []
result = []
for i in range(N):
    B = A
    C = B[i]
    B[i] = 0
    result.append(max(B))
    B[i] = C

for a in result:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
#a = list(map(int, input().split()))
#b = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(int(input()))

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

Submission status: Time Limit Exceeded

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


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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def myAnswer(N:int,A:list) -> None:
   MAX = max(A)
   tmp = A[:]
   for i in range(N):
      if(A[i] == MAX):
         tmp.remove(A[i])
         print(max(tmp))
         tmp = A[:]
      else:
         print(MAX)

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A =[]
   for _ in range(N):
      A.append(int(input()))
   myAnswer(N,A)

if __name__ == '__main__':
   main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = []

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

for i in range(N):
    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:])))

Submission status: Time Limit Exceeded

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

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


MAX = max(A)

if A.count(MAX) == N:
  for _ in range(N):
    print(MAX)

  
else:

  two = sorted(set(A))[-2]
  for i in range(N):
    if A[i] == MAX and A.count(MAX) == 1:
      print(two)
    else:
      print(MAX)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
# maxA = max(A)
for x in range(len(A)):
    a_tmp = A[x]
    A[x] = 0
    print(max(A))
    A[x] = a_tmp

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
for x in range(len(A)):
    a_copy = A[:]
    a_copy[x] = 0
    print(max(a_copy))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
a_ = sorted(a)
a_max = a_[-1]
a_second = a_[-2]
 
if a.count(max(a)) >= 2:
    for _ in range(n):
        print(a_max)
else:
    for _ in range(n):
        if a[_] == max(a):
            print(a_second)
        else:
            print(a_max)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
a_ = sorted(a)
a_max = a_[-1]
a_second = a_[-2]

if a.count(max(a)) >= 2:
    for _ in range(n):
        print(a_max)
else:
    for _ in range(n):
        if a[_] == max(a):
            print(a_second)
        else:
            print(a_max)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
a_max = max(a)
a_second = sorted(a)[-2]

if a.count(max(a)) >= 2:
    for _ in range(n):
        print(a_max)
else:
    for _ in range(n):
        if a[_] == max(a):
            print(a_second)
        else:
            print(a_max)

Submission status: Time Limit Exceeded

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

if a.count(max(a)) >= 2:
    for _ in range(n):
        print(max(a))
else:
    for _ in range(n):
        if a[_] == max(a):
            print(sorted(a)[-2])
        else:
            print(max(a))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
num = []
for i in range(n):
  num.append(int(input()))
  
for i in range(n):
  subnum = num[0:i] + num[i+1:n]
  subnum = sorted(subnum)
  print(subnum[n-2])

Submission status: Time Limit Exceeded

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

for x in range(len(a)):
    if x==a.index(max(a)):
            print(sorted(a)[-2])
    else:
            print(max(a))

Submission status: Time Limit Exceeded

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

for x in range(n):
    if x!=a.index(max(a)):
            print(max(a))
    else:
            print(sorted(a)[-2])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls=[int(input()) for i in range(n)]
ans=[]
for i in range(n):
  ls2 = ls.copy()
  del ls2[i]
  ans.append(max(ls2))
a='\n'.join(map(str,ans))
print(a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls=[int(input()) for i in range(n)]
ans=[]
for i in range(n):
  ls2 = ls.copy()
  del ls2[i]
  ans.append(max(ls2))
for i in range(n):
  print(ans[i])

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

Submission status: Time Limit Exceeded

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

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

        
if __name__ == '__main__':
    q3()

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 a[i] == max(a):
        mx_index = i
        break
a.sort()
for i in range(n):
    print(a[n-2] if i == mx_index else a[n-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
l=[]
for i in range(N):
    a=int(input())
    l.append(a)
len_l=len(l)
now=[]
for i in range(len_l):
    now=l[0:i]+l[i+1:len_l]
    print(max(now))

Submission status: Time Limit Exceeded

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

b = sorted(a,reverse=True)

if b[0] == b[1]:
    for i in range(n):
        print(b[0])
else:
    s = max(a)
    for i in range(n):
        if i == a.index(s):
            print(b[1])
        else:
            print(s)

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

Submission status: Time Limit Exceeded

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

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

b = sorted(a, reverse=True)
for x in a:
   if x == max(a):
      print(b[1])
   else:
      print(b[0])

Submission status: Time Limit Exceeded

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

for i in range(n):
    if a[i] == c:
        x = b.pop(i) #i番目の要素を削除
        print(max(b)) #その中での最大値を出力
        b.insert(i, x) #削除した要素を戻す
    else:
        print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
b = a
#print(a)
for i in range(n):
  x = b.pop(i) #i番目の要素を削除
  print(max(b)) #その中での最大値を出力
  b.insert(i, x) #削除した要素を戻す

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[:]
    del tmp[i]
    print(max(tmp))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
a_max = max(A)
count = A.count(a_max)
for i in range(N):
    if A[i] < a_max and count >= 2:
        print(a_max[0])
    else:
        B = copy.deepcopy(A)
        B.remove(A[i])
        print(max(B)[0])

Submission status: Time Limit Exceeded

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

s = [i for i, v in enumerate(a) if v == max(a)]
if len(s) >= 2:
     for i in range(n):
          print(max(a))
else:
     for i in range(n):
          if i == s[0]:
               print(sorted(a)[-2])
          else:
               print(max(a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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