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:
from copy import copy
from collections import deque

N = int(input())

A = [None]*N

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

Asorted = deque(sorted(A))
    
for i in range(N):
    Ai = A[i]
    Asortedcopy = copy(Asorted)
    Amax = Asortedcopy.pop()
    if Amax == Ai:
        Amax = Asortedcopy.pop()
    print(Amax)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
A_ap = A.append
for i in range(N):
    A_ap(int(input()))
    
max_A = max(A)
for i in range(N):
    if A[i] != max_A:
        print(max_A)
    else:
        print(sorted(A)[-2])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]

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

Submission status: Time Limit Exceeded

Solution code:
import copy

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

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

for i in range(n):
    buf = copy.deepcopy(a)
    buf.pop(i)
    print("{}".format(max(buf)))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

k=a.index(max(a))

for i in range(n):
    if i==k:
        print(sorted(a)[-2])
    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):
  if i == 0:
    print(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for i in range(n):
    if(i != 0):
        p1 = max(li[0:i])
    else:
        p1 = 0
    if(i != n-1):
        p2 = max(li[i+1:n])
    else:
        p2 = 0
    
    #print("{}, {}, {}".format(p1,p2,max(p1,p2)))
    print(max(p1,p2))

Submission status: Time Limit Exceeded

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

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

for i in range(n):
    c = sorted(a,reverse = True)
    if c[0] == a[i]:
        b = c[1]
    else:
        b = c[0]
    print(b)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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


for i in range(N):
    indices = np.ones(N, dtype=bool)
    indices[i] = False
    print(np.amax(nums[indices]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

forward = [0 for n in range(N)]
forward[0] = A[0]
backward = [0 for n in range(N)]
backward[N-1] = A[N-1]
for n in range(1,N):
    forward[n] = max(forward[n-1], A[n])
for n in range(N-1)[::-1]:
    backward[n] = max(backward[n+1], A[n])

# print(forward)
# print(backward)

for n in range(N):
    # print("====")
    # print(forward[:n])
    # print(backward[n+1:])
    print(max(forward[:n]+backward[n+1:]))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

maxa = max(A)

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

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

Submission status: Time Limit Exceeded

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

    mx = max(A)
    for i in range(N):
        s = A[i]
        if mx != s:
            print(mx)
        else:
            print(sorted(A)[-2])
            
resolve()

Submission status: Time Limit Exceeded

Solution code:
import copy

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

for i in range(n):
    a_list.append(int(input()))
    
#print(a_list)    
for i in range(n):
    a_copy = copy.copy(a_list)
    a_copy.pop(i)
    #print(a_copy)
    print(max(a_copy))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

ANS = []
for i in range(N):
  Alist = A[:i]+A[i+1:]
  ANS.append(max(Alist))

for i in ANS:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
#n,k = list(map(int,input().split(" ")))
"""n = int(input())
print(3*(n*n))
"""
"""
import math as m
N,D = list(map(int,input().split(" ")))
print(m.ceil(N / (2*D+1)))
"""

N = int(input())
l = []
nums = []
for i in range(N):
    Ai = int(input())
    nums.append(Ai)
    l.append(Ai)
for i in range(N):
    n = l[i]
    nl = sorted(l)
    m = nl[-1]
    if m == n:
        m = nl[-2]
    print(m)

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_list = [int(input()) for _ in range(n)]
for i in range(len(a_list)):
    print(max(a_list[:i]+a_list[i+1:]))

Submission status: Time Limit Exceeded

Solution code:
from copy import copy

N = int(input())

A = [None]*N

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

Asorted = sorted(A)
    
for i in range(N):
    Ai = A[i]
    Asortedcopy = copy(Asorted)
    Amax = Asortedcopy.pop()
    if Amax == Ai:
        Amax = Asortedcopy.pop()
    print(Amax)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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


def main():
	#N, D = [int(x) for x in input().split()]
	N = int(input())
	
	lst = []
	for i in range(N):
		lst.append(int(input()))

	a = np.array(lst)
	
	for i in range(N):
		mask = [True] * N
		mask[i] = False
		mask = np.array(mask)
		_a = a[mask]
		print(np.max(_a))

if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy
s=[]
i=0
n=int(input())
while i!=n:
    s.append(int(input()))
    i+=1
#print(s)
a=copy.copy(s)
#print(a)
i=0
while i!=n:
    del a[i]
    print(max(a))
    i+=1
    a=copy.copy(s)

Submission status: Time Limit Exceeded

Solution code:
#coding : utf-8

import os
import sys

def except_i(a, i):
	return a[0:i] + a[i+1:len(a)]

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 = []
for i in range(N):
    A.append(int(input()))
    
MAX1 = max(A)
MAX2 = -1
for i in range(N):
    if i != A.index(MAX1):
        MAX2 = max(MAX2,A[i])
        
if MAX1 == MAX2:
    for i in range(N):
        print(MAX1)
else:
    for i in range(N):
        if i == A.index(MAX1):
            print(MAX2)
        else:
            print(MAX1)

Submission status: Time Limit Exceeded

Solution code:
n=input()
n=int(n)
l=[]
for i in range(n):
    x=input()
    x=int(x)
    l.append(x)
ans=max(l)
for i in range(n):
    
    if l[i]==ans:
        del l[i]
        print(max(l))
        l.append(0)
        continue
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
for _ in range(n):
    ans=a
    x=ans.pop(0)
    print(max(ans))
    ans.append(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for i in range(n):
  print(max(a_list[:i]+a_list[i+1:]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
#n,k = list(map(int,input().split(" ")))
"""n = int(input())
print(3*(n*n))
"""
"""
import math as m
N,D = list(map(int,input().split(" ")))
print(m.ceil(N / (2*D+1)))
"""

N = int(input())
l = []
nums = []
for i in range(N):
    Ai = int(input())
    nums.append(Ai)
    l.append(Ai)
for i in range(N):
    n = l[i]
    nl = sorted(l)
    m = nl[-1]
    if m == n:
        m = nl[-2]
    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):
    max = 0
    for j in range(N):
        if j!=i and max < a[j]:
            max = a[j]
    print(max)

Submission status: Time Limit Exceeded

Solution code:
# C
N = int(input())
A=[]
for i in range(N):
    A.append(int(input()))
for i in range(len(A)):
    temp = A[i]
    A[i] = 0
    print(max(A))
    A[i] = temp

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
ls = []
for i in range(n):
    a = int(input())
    ls.append(a) 
    
for i in range(len(ls)):
    ls2 = copy.copy(ls)
    del ls2[i]
    ls2 = sorted(ls2)
    print(ls2[-1])

Submission status: Time Limit Exceeded

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

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

    for i in range(N):
        L = A_[0:i]
        L.extend(A_[i + 1:])
        print(max(L))
        
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

c_list = []
for i, a in enumerate(a_list[:]):
    b = a_list.pop(i)
    c_list.append(max(a_list))
    a_list.insert(i, b)

for c in c_list:
    print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

max_itr = [i for i, v in enumerate(A) if v == max(A)]
max_number = max(A)
for i in range(N):
  if i not in max_itr:
    print(max_number)
  else:
    print(sorted(A)[-2])

Submission status: Time Limit Exceeded

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


def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    for _ in range(N):
        print(max(A[0:_]+A[_+1:N]))
                

    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#coding : utf-8

import os
import sys

def except_i(a, i):
	return a[0:i] + a[i+1:len(a)]

N = int(input())

A = []

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


for i in range(N):
	print(max(except_i(A, i)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
for i in range(N):
    B = A.copy()
    del B[i]
    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):
    new = list(a)
    del new[i]
    print(max(new))

Submission status: Time Limit Exceeded

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

MAX = max(a)

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

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())

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

for i in range(N):
    B = copy.deepcopy(A)
    B.pop(i)
    print(max(B))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

nums = [0]*N
for i in range(0, N):
    nums[i] = int(input())

for i in range (0, N):
    test = nums[:i] + nums[i+1:]
    print(max(test))

Submission status: Time Limit Exceeded

Solution code:
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    al = [int(input()) for i in range(n)]

    for i in range(n):
        print(max(al[:i] + al[i+1:]))

Submission status: Time Limit Exceeded

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

for i in range(n):
  print(max(nums[0: i] + nums[i + 1:]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
for i in range(N):
    B = A[0:i]+A[i+1:len(A)]
    print(max(B))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
count_list=[]
i=0
while(i<N):
    a=int(input())
    count_list.append(a)
    i+=1

i=0
while(i<N):
    b=[]
    for j in count_list:
        b.append(j)
    b[i]=0
    print(max(b))
    i+=1

Submission status: Time Limit Exceeded

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


def main():
    n = int(input())

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

    a_max = max(a)

    for i in range(n):
        if a[i] != a_max:
            print(a_max)
            continue

        tmp = a.copy()
        tmp.remove(a[i])
        print(max(tmp))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for _ in range(N)]
for i in range(N):
    if sorted(A)[-1]==A[i]:
        print(sorted(A)[-2])
    else:
        print(sorted(A)[-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):
  ta = A[:]
  ta.pop(i)
  print(max(ta))

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int( input() )

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

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

Submission status: Time Limit Exceeded

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

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    n, = read_h()
    a = read_v(n)

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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)]
if n==2:
  print(A[1])
  print(A[0])
  exit()

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

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
aa=[]
for _ in range(n):
    aa.append(int(input()))
for i in range(n):
    print(max(aa[:i] + aa[i+1:]))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
N = int(input())
A = [int(input()) for _ in range(N)]
for i in range(N):
    B = A[:]
    B.pop(i)
    print(max(B))

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A = [int(input()) for _ in range(N)]

maxA = max(A)
lenA = len(A)

for i, a in enumerate(A):
    if a == maxA:
        if i == 0:
            print(max(A[1:]))
        elif i == lenA-1:
            print(max(A[:-1]))
        else:
            print(max(max(A[:i]), max(A[i+1:])))
    else:
        print(maxA)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a = []
n = int(input())
for i in range(n):
  a.append(int(input()))
for j in range(n):
  b = [a[i] for i in range(n) if i != j]
  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):
  print(max(a[:i]+a[i+1:]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
for num,a in enumerate(A):
    del A[num]
    print(max(A))
    A.insert(num,a)

Submission status: Time Limit Exceeded

Solution code:
#n=list(map(int,input().split()))
n=int(input())

import copy

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = [int(input()) for i in range(n)]
a_max = max(a)
for i in range(n):
    if a_max == a[i]:
        a_ = copy.deepcopy(a)
        del a_[i]
        print(max(a_))
    else:
        print(a_max)

Submission status: Time Limit Exceeded

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

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

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

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:
# -*- coding: utf-8 -*-

import math

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc134/tasks/abc134_c

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

for i in range(n):
    b = max(a)
    if b == a[i]:
        c = sorted(a,reverse = True)
        b = c[1]
    print(b)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
for i in range(N):
  a=int(input())
  A.append(a)
  
print(max(A[1:]))
for i in range(1,N-1):
  b=A[:i]
  c=A[i+1:]
  aa=b+c
  print(max(aa))
  
print(max(A[:N-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):
    m = max(A[:i] + A[(i+1):])
    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[:i]+a[i+1:]
    print(max(b))

Submission status: Time Limit Exceeded

Solution code:
#n,k = list(map(int,input().split(" ")))
"""n = int(input())
print(3*(n*n))
"""
"""
import math as m
N,D = list(map(int,input().split(" ")))
print(m.ceil(N / (2*D+1)))
"""
N = int(input())
l = []
nums = []
for i in range(N):
    Ai = int(input())
    nums.append(Ai)
    l.append(Ai)
for i in range(N):
    new = l.copy()
    new.remove(nums[i])
    print(max(new))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = [int(input()) for x in range(n)]
for b in range(len(a_list)):
  new_list = list(a_list)
  new_list.pop(b)
  print(max(set(new_list)))

Submission status: Time Limit Exceeded

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

a_sort = sorted(a, reverse=True)
max1 = a_sort[0]
max2 = a_sort[1]
for x in a:
        if a.count(max1) > 1:
                print(max1)
        else: 
                if x != max1:
                        print(max1)
                else:
                        print(max2)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy
  
N = int(input())  
A = np.zeros(N)

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

B = copy.deepcopy(A)

for i in range(N):
    B = np.delete(A, i)
    print(int(np.max(B)))
    B = copy.deepcopy(A)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	A = [int(input()) for _ in range(N)]
	print(max(A[1:]))
	for i in range(1, N-1):
		print(max(max(A[:i]), max(A[i+1:])))
	print(max(A[:N]))

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

Submission status: Time Limit Exceeded

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


if __name__ == '__main__':
    main()

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

for n in range(N):
    print(max(A[:n] + A[n+1:]))

Submission status: Time Limit Exceeded

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

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

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(max(A[0:i],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):
    if i == 0:
        print(max(A[1:]))
    elif i == N - 1:
        print(max(A[:N-1]))
    else:
        print(max(A[:i]+A[i+1:]))

Submission status: Time Limit Exceeded

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


def main():
    n = int(input())

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

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy

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

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

Submission status: Time Limit Exceeded

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


if(a.count(max(a)) >= 2):
    la = list(set(a))
    la = sorted(la, reverse=True)
    l1 = la[0]
    for i in range(n):
        print(l1)
else:
    for i in range(n):
        la = list(set(a))
        la = sorted(la, reverse=True)
        l1 = la[0]
        l2 = la[1]
        if(a[i] == l1):
            print(l2)
        else:
            print(l1)

Submission status: Time Limit Exceeded

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = [int(input()) for x in range(n)]
for b in range(len(a_list)):
  new_list = list(a_list)
  new_list.pop(b)
  print(max(new_list))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
A=[int(input()) for _ in range(N)]
Anp=np.array(A)
for i in range(N):
    vec=np.ones(N,dtype=bool)
    vec[i]=False
    print(max(Anp[vec]))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = input()
    aa = []
    for _ in xrange(n):
        aa.append(input())
    bb = sorted(aa)
    b0, b1 = bb[-1], bb[-2]
    for a in aa:
        if a < b0:
            print b0
        else:
            print b1


if __name__ == '__main__':
    main()