Problem:


Score : 300 points

Problem Statement

You are given a sequence of length N: A_1, A_2, ..., A_N.
For each integer i between 1 and N (inclusive), answer the following question:

Find the maximum value among the N-1 elements other than A_i in the sequence.

Constraints

2 \leq N \leq 200000

1 \leq A_i \leq 200000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print N lines. The i-th line (1 \leq i \leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.

Sample Input 1

3
1
4
3

Sample Output 1

4
3
4

The maximum value among the two elements other than A_1, that is, A_2 = 4 and A_3 = 3, is 4.

The maximum value among the two elements other than A_2, that is, A_1 = 1 and A_3 = 3, is 3.

The maximum value among the two elements other than A_3, that is, A_1 = 1 and A_2 = 4, is 4.

Sample Input 2

2
5
5

Sample Output 2

5
5



Sample input:
3
1
4
3


Sample output:
4
3
4

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import copy
a = int(input());
b = [int(input()) for i in range(a)];
c = 0;
for i in range(a):
    if max(b) > b[i]:
        print(max(b));
    elif max(b) == b[i]:
        d = copy.copy(b);
        del d[i]
        e = max(d);
        print(e);

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = [int(input()) for _ in range(N)]
result = []
for x in range(N):
  as_tmp = list(As)
  del as_tmp[x]
  result.append(max(as_tmp))
print('\n'.join(map(str, result)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())

a = []

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
arr = np.array([int(input()) for _ in range(n)])

a_max = arr.max()

idx = np.where(arr == a_max)[0]

not_arr = arr[arr != a_max]

if len(not_arr) != 0:
    b_max = not_arr.max()

if len(idx) > 1:
    for i in range(n):
        print(a_max)
else:
    for i in range(n):
        if i in idx:
            print(b_max)
        else:
            print(a_max)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import copy

n = int(input())
ls = [int(input()) for _ in range(n)]
p = 200000
ans = 0
if p>n:
    p=n

def cul(n, x):
    l = len(x)
    b = [x[i] for i in range(l)]
    b.pop(n)
    return max(b)
    
for i in range(p):
    s = cul(i,ls[:p])
    print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import numpy as np

def main():
    N = int(input().strip())
    arr = np.zeros(N, np.int32)
    for i in range(N):
        arr[i] = int(input().strip())
    for i in range(N):
        if i == 0:
            tmp = arr[i]
            arr[i] = 0
            print(arr.max())

        else:
            arr[i-1] = tmp
            tmp = arr[i]
            arr[i] = 0
            print(arr.max())

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = [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:])
    max_a = a1 if a1 > a2 else a2
    print(max_a)
    
print(max(a[:-1]))

Submission status: Time Limit Exceeded

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

max_ = max(list)
for i in range(n):
    a = list[i]
    if a == max_:
        del list[i]
        ans = max(list)
        print(ans)
        list.insert(i,a)
    else:
        print(max_)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
num_line = [stdin.readline().rstrip() for _ in range(N)]
for i in range(N):
    save_num = num_line[i]
    num_line.pop(i)
    print(max(num_line))
    num_line.insert(i, save_num)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
for i in l:
    la = l[:]
    la.remove(i)
    print(max(la)[0])

Submission status: Time Limit Exceeded

Solution code:
import copy
import sys
def input():
    return sys.stdin.readline()[:-1]
  

n=int(input())
num_list=[int(input()) for i in range(n)]
 
buf = []
 
for i in range(n):
  buf = copy.copy(num_list)
  buf.pop(i)
  print(max(buf))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    for i in range(N):
        if i != A.index(max(A)):
            print(max(A))
            continue
        Ap = []
        Ap = copy.copy(A)
        del Ap[i]
        print(max(Ap))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
m1 = max(a)
if len(set(a)) == 1:
	for i in range(n):
		print(m1)
else:
	m2 = sorted(set(a))[-2]
	for i in range(n):
		if a[i] < m1:
			print(m1)
		elif a[i] == m1:
			if a.count(m1) > 1:
				print(m1)
			else:
				print(m2)
		else:
			print(m2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
x=[]
for i in range(n):
  x.append(int(input()))
cnt = [0] * 50
for i in range(n):
  for j in range(n):
    if i is not j and cnt[i] < x[j]:
      cnt[i]=x[j]
for i in range(n):
  print(cnt[i])

Submission status: Time Limit Exceeded

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

maxa=max(a)

for i in range(n):
    if a[i]==maxa:
        list = a[:]
        list.pop(i)
        print(max(list))
    else:
        print(maxa)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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):
  tmp = l[0:i] + l[i+1:]
  #print(max(l[0:i],l[i+1:]))
  print(max(tmp))

Submission status: Time Limit Exceeded

Solution code:

N = int(input())

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

for i in range(N):
    tmp_list = []
    for j in range(N):
        if i != j:
            tmp_list.append(an[j])
    print(max(tmp_list))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list = []
max = 0
second = 0
max_index = []

for i in range(n):
    num = int(input())
    if num > max:
        max = num
    list.append(num)

for i,x in enumerate(list):
    if x == max:
        max_index.append(i)
    elif x > second:
        second = x

for i in range(n):
    if (i in max_index) & (len(max_index) == 1):
        print(second)
    else:
        print(max)

Submission status: Time Limit Exceeded

Solution code:
data = []
i = int(input())

data = [int(input()) for _n in range(i)]
maxInt = max(data)
for n in range(i):
	if maxInt != data[n]:
		print(maxInt)
	else:
		print(max(data[0:n]+data[n+1:]))

Submission status: Time Limit Exceeded

Solution code:
hako = []
zan = []
num = int(input())
for n in range(num):
  hako.append(int(input()))
for h in range(len(hako)):
  zan.append(hako[h])
  hako.remove(hako[h])
  print(max(hako))
  hako.insert(h, zan[h])

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):
    Ai=A.pop(0)
    print(-min(A))
    A.append(Ai)

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

Submission status: Time Limit Exceeded

Solution code:
N, *d = map(int, open(0).read().split())
m=d.index(max(d))
for i in range(N-1):
    if(i==m):
        temp=d[i]
        d[i]=0
        y=max(d)
        print(y)
        d[i]=temp
    
    print(max(d))

Submission status: Time Limit Exceeded

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

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

m = max(array)
c = array.count(m)

for e in array:
    sa = array[:]
    if e != m:
        print(m)
    else:
        if 1 < c:
            print(m)
        else:
            sa.remove(m)
            print(max(sa))

Submission status: Time Limit Exceeded

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

L=[]
for i,a in enumerate(A):
	if i==0:
		L.append(a)
	else:
		L.append( max(L[-1], a) )

R=[]
for i,a in enumerate(A[::-1]):
	if i==0:
		R.append(a)
	else:
		R.append( max(R[-1], a) )

R=R[::-1]


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

Submission status: Time Limit Exceeded

Solution code:
A = int(input())

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

for i in range(A):
    C = B.pop(0)
    maxp = max(B)
    print(maxp)
    B.append(C)

Submission status: Time Limit Exceeded

Solution code:
def solve(n: int, a: list):
  for i in range(n):
    aa = a.copy()
    aa[i] = -1
    print(max(aa))
  

if __name__ == '__main__':
  n = int(input())
  a = [int(input()) for _ in range(n)]
  solve(n, a)

Submission status: Time Limit Exceeded

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

N = int(input())
A = [int(input()) for _ in range(N)]
amax = max(A)
amaxcnt = A.count(amax)

for i in range(N):
    a0 = A.pop(0)
    if a0 == amax and amaxcnt == 1:
        print(max(A))
    else:
        print(amax)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

a = []
for i in range(N):
    a.append(int(input()))
  
for j in range(0,N):
    b = a[:]
    b.pop(j)
    print(max(b))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input() for i in range(N)]
for i in range(0,N):
    a = s[i]
    del s[i]
    print(max(s))
    s.insert(i, a)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
lst = []
for i in range(N):
    lst.append(int(input()))

for i in range(N):
    n=0
    n,lst[i] = lst[i],n
    print(max(lst))
    lst[i] = n

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import itertools
import queue
from fractions import gcd
import time


def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N= int(sys.stdin.readline())
    A = list(map(int,sys.stdin.readlines()))
    k=A.pop(0)
    m = max(A)
    A.insert(0,k)
    print(m)
    if k>m:
        m=k
    for i in range(1,len(A)):
        if m == A[i]:
            k=A.pop(i)
            m = max(A)
            A.insert(i,k)
            print(m)
            m=k
        else:
            print(m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

for i in range(N):
    A_i_copy = A_i[:]
    A_i_copy.pop(i)
    print(max(A_i_copy))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

A_length = len(A)
# print(A_length)

left = [A.pop(0)]
right = A

# print(left)
# print(right)

left_max = max(left)
right_max = max(right)
print(right_max)


for i in range(A_length-2):
    temp = right.pop(0)
    if temp == right_max:
        right_max = max(right)
    print(max(left_max, right_max))
    if temp > left_max:
        left_max = temp
    left.append(temp)

temp = right.pop(0)
if temp > left_max:
    lef_max = temp
left.append(temp)
print(left_max)

Submission status: Time Limit Exceeded

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

maxA=max(A)

for i in range(N):
  if A[i]<maxA:
    print(maxA)
  else:
    B=A[:]
    del B[i]
    print(max(B))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from sys import stdin
n = int(stdin.readline().rstrip())
a = [int(stdin.readline().rstrip()) for x in range(n)]
for i in range(len(a)):
    b = []
    b.append(a[:i])
    b.append(a[i+1:])
    b = [flatten for inner in b for flatten in inner]
    print(max(b))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list = []
max = 0

for i in range(n):
    num = int(input())
    if num > max:
        max = num
    list.append(num)

max_index = [i for i,x in enumerate(list) if x == max]
#print(max_index)

list2 = [i for i in list if i != max]
#print(list2)
if list2 != []:
    second = sorted(list2)[-1]
else:
    second = 0
#print(second)

for i in range(n):
    if (i in max_index) & (len(max_index) == 1):
        print(second)
    else:
        print(max)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = [0 for i in range(0, N)]
for i in range(0, N):
    D[i] = int(input())

l = []
for i in range(N):
    d = D.copy()
    d.pop(i)
    l.append(max(d))
    
for i in range(len(l)):
    print(l[i])

Submission status: Time Limit Exceeded

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

           
for i in range(0,len(a)):
  ax = a.copy()
  del a[i]
  print(max(a))
  a = ax.copy()
  

  #  if 1+i<=len(a):
#    print('i:' ,i)
#    print(max(a[i],a[i+1]))

        
#print(max(a[0],a[-1]   )   )

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def solve(n: int, a: list):
  for i in range(n):
    aa = [a[j] for j in range(n) if i != j]
    print(max(aa))
  

if __name__ == '__main__':
  n = int(input())
  a = [int(input()) for _ in range(n)]
  solve(n, a)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
lst = []
for i in range(N):
    lst.append(int(input()))

n=0
for i in range(N):
    n,lst[i] = lst[i],n
    print(max(lst))
    n,lst[i] = lst[i],n

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

#list
for i in range(N):
    n = int(input())
    A.append(n)

#max
print(sorted(A[1:])[-1])

if N>2:
    for i in range(1, N-1):
        A_=sorted(A[:i])
        A__=sorted(A[i+1:])
        print(max(A_[-1], A__[-1]))

print(sorted(A[:-1])[-1])

Submission status: Time Limit Exceeded

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

maxmax=max(a)

for i in range(n):
    if a[i]!=maxmax:
        print(maxmax)
    elif a[i]==maxmax:
        temp=a[i]
        a[i]=0
        print(max(a))
        a[i]=temp

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

A = np.array([])

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

ans = np.amax(A)
j = np.argmax(A)
ans2 = np.amax(np.delete(A,j))

for i in range(N):
	if i == j:
		print(int(ans2))
	else:
		print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for i in range(n):
  list = s[:]
  list.pop(i)
  print(max(list))

Submission status: Time Limit Exceeded

Solution code:
data = []

data = [int(input()) for _n in range(int(input()))]

for n in range(len(data)):
	print(max(data[0:n]+data[n+1:]))

Submission status: Time Limit Exceeded

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

l = []
for i in range(N):
    d = D.copy()
    d.pop(i)
    l.append(max(d))
    
for i in range(len(l)):
    print(l[i])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
list = []

for n in range(N):
  list.append(int(input()))

for i in range(N):
  select = [list[j] for j in range(N) if j != i]
  print(np.max(select))

Submission status: Time Limit Exceeded

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

for j in range(n):
    if list[j] == max(list):
        print(sorted(list)[-2])
    else:
        print(max(list))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

if N%2!=0:
	for i in range(N):
		Ni = List[0]
		List.remove(List[0])
		l_max = max(List[0:int(N/2)])
		r_max = max(List[int(N/2):N])
		if l_max>=r_max:
			print(l_max)
		else:
			print(r_max)
		List.append(Ni)
            
         
else:
	for i in range(N):
		Ni = List[0]
		List.remove(List[0])
		l_max = max(List[0:int(N//2)])
		r_max = max(List[int((N//2)-1):N])
		if l_max>=r_max:
			print(l_max)
		else:
			print(r_max)
		List.append(Ni)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import numpy as np

def main():
    N = int(input().strip())
    arr = np.zeros(N, np.int32)
    for i in range(N):
        arr[i] = int(input().strip())
    for i in range(N):
        arr2 = np.copy(arr)
        arr2[i] = 0
        print(arr2.max())

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = input()
n = int(n)

li = [int(input()) for i in range(n)]
m = max(li)
for j in range(n):
  if m < li[j]:
    print(m)
  else:
    buf=li.pop(j)
    print(max(li))
    li.insert(j,buf)

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
all_list = [int(input()) for _ in range(n)]
max_value = max(all_list)
for i in range(n):
    if all_list[i] == max_value:
        tmp = copy.copy(all_list)
        tmp.pop(i)
        print(max(tmp))
    else:
        print(max_value)

Submission status: Time Limit Exceeded

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

for i in range(N):
    tmp = A[i]
    A[i] = 0
    Ao = sorted(A)
    ans = Ao[N-1]
    A[i] = tmp
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

for i in range(N):
        tmp = copy.copy(sequences)
        tmp.pop(i)
        tmp_set = set(tmp)
        print(max(tmp_set))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [int(input()) for i in range(N)]
for k in s:
    m = s.pop(0)
    print(max(s))
    s.append(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for x in range(n)]
for i in range(len(a)):
    b = []
    b.append(a[:i])
    b.append(a[i+1:])
    b = [flatten for inner in b for flatten in inner]
    print(max(b))

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())

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

    for i in range(len(A)):
        ans = calcMax(A, i)
        print(ans)



def calcMax(A, i):
    ans = max(A)
    if not ans == A[i]:
        return ans

    else:
        tmp = A[i]
        A[i] = 0
        ans = calcMax(A, i)
        A[i] = tmp
        return ans

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(0,len(lst)):
  sort_lst = []
  for j in range(0,len(lst)):
    if not i == j:
      sort_lst.append(lst[j])
  sort_lst = sorted(sort_lst, reverse=True)
  print(sort_lst[0])

Submission status: Time Limit Exceeded

Solution code:
import copy

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

T=sorted(copy.deepcopy(L))
h=max(L)
h2=T[len(T)-2]

for i in range(N):
  if L[i]!=h:
    print(h)
  elif L[i]!=h2:
    print(h2)
  else:
    tmp=copy.deepcopy(L)
    del tmp[i]
    print(max(tmp))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
m = max(a)
for j in range(n):
	if a[j] < m:
		print(m)
	elif a[j] == m:
		if a.count(m) > 1:
			print(m)
		else:
			b = a[:]
			b[j] = 0
			print(max(b))
	else:
		b = a[:]
		b[j] = 0
		print(max(b))

Submission status: Time Limit Exceeded

Solution code:

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

# S = sorted(A)
# MAXS = max(S[1:3])
# two = S[-2]
# print("MAX {} two {}".format(MAXS,two))
# count = S.count(max(S))
#
# for i in range(N):
#     if A[i] == MAXS:
#         if count > 1:
#             print(MAXS)
#         else:
#             print(two)
#     else:
#         print(MAXS)
#
for i in range(N):

    if i == 0:
        print(max(A[1:]))

    elif i == N-1:
        print(max(A[:i]))

    else:
        low = max(A[0:i])
        high = max(A[i+1:])

        if high > low:
            print(high)
        else:
            print(low)

Submission status: Time Limit Exceeded

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

for i in range(n):    
    print(max(A)) 
print(sorted(A)[-2])
for i in range(N-n-1):
    print(max(A))

Submission status: Time Limit Exceeded

Solution code:
import heapq

list = []
n = int(input())
for i in range(n):
    list.append(int(input()))
maxsize = max(list)

for j in range(n):
    a = list[j]
    if a == maxsize:
        list2 = heapq.nlargest(2, list)
        print(list2[1])
    else:
        print(maxsize)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

if N%2!=0:
	for i in range(N):
		Ni = List[0]
		List.remove(List[0])
		l_max = max(List[0:int(N/2)])
		r_max = max(List[int(N/2):N])
		if l_max>=r_max:
			print(l_max)
		else:
			print(r_max)
		List.append(Ni)
            
         
else:
	for i in range(N):
		Ni = List[0]
		List.remove(List[0])
		l_max = max(List[0:int(N//2)])
		r_max = max(List[int((N//2)-1):N])
		if l_max>=r_max:
			print(l_max)
		else:
			print(r_max)
		List.append(Ni)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

a_max = max(a)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

A = np.array([])

for i in range(N):
	a = int(input())
	A = np.hstack( (A,a) )

ans = np.amax(A)
j = np.argmax(A)
ans2 = np.amax(np.delete(A,j))
for i in range(N):
	if i == j:
		print(int(ans2))
	else:
		print(int(ans))

Submission status: Time Limit Exceeded

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

first_max = max(a)

former_arr = [0] + a[0:a.index(first_max)]
latter_arr = [0] + a[a.index(first_max) + 1:]
second_max = (max(max(former_arr), max(latter_arr)))

for i in range(0, N):  
  if (a.index(first_max) == i):
    print(second_max)
  else:
    print(first_max)

Submission status: Time Limit Exceeded

Solution code:
N, *d = map(int, open(0).read().split())
m=max(d)
for i in range(N):
    if(d[i]==m):
        temp=d[i]
        d[i]=0
        y=max(d)
        print(y)
        d[i]=temp     
    else:
        print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
p = list()
for i in range(n):
  a = input()
  p.append(a)
for j in range(n):
  x = p.pop(0)
  p = [int(k) for k in p]
  print(max(p))
  p.append(x)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

for i in range(N):
        tmp = copy.copy(sequences)
        tmp.pop(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())

D=max(A)
for j in range(N):
	if A[j] != D:
		print(D)
	else:
		B = A[:]
		B.pop(j)
		print(max(B))

Submission status: Time Limit Exceeded

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

if len(set(A)) == 1:
  for _ in range(N):
    print(max(A))
else:
  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:
import copy
import heapq

N=int(input())
A=[]
for i in range(N):
    A.append(-int(input()))
for i in range(N):
    B=copy.copy(A)
    B.pop(i)
    heapq.heapify(B)
    print(B[0] * (-1))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    if i > 1 and i < N - 2:
        if max(A) != A[i]:
            print(MAX)
        else:
            print(max(A[:i]),max(A[i+1:]))
            continue
    if i == 0:
        print(max(A[1:]))
        continue
    if i == 1 and N == 2:
        print(A[0])
        continue
    if i == 1 and N > 2:
        print(max(A[0], max(A[2:])))
        continue
    if i == N -2:
        print(max(max(A[:N-2]), A[N-1]))
        continue
    if i == N - 1:
        print(max(A[:N-1]))

Submission status: Time Limit Exceeded

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

for i in range(n):
    ans = 0
    for j in range(n):
        if j != i and a[j] > ans:
            ans = a[j]
    print(ans)

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_temp=a[i]
    a[i]=0
    
    maxmax=max(a)
    print(maxmax)
    a[i]=max_temp

Submission status: Time Limit Exceeded

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
d = []
for i in range(n):
    k = readi()
    d.append(k)
p = []
g = -1
for i in range(n - 1):
    t = d[i]
    k = max(d[i+1:n])
    print(max(k, g))
    g = max(t, g)
print(max(d[0],g))

Submission status: Time Limit Exceeded

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

for x in range(N):
    #print(x)
    t = A[:x] + A[x+1:]
    print(max(t))

Submission status: Time Limit Exceeded

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

max_num = max(string_list)

for j in string_list:
    if j != max_num:
        print(max_num)
    else:
        templist = copy.deepcopy(string_list)
        templist.remove(j)
        print(max(templist))