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:
data = []
res = []
i = int(input())

for _n in range(i):
	data.append(int(input()))

for n in range(i):
	res.append(max(data[0:n]+data[n+1:]))

for item in res:
	print(item)

Submission status: Time Limit Exceeded

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

for _ in range(n):
  b=a[0:_]+a[_+1:n]
  print(max(b))

Submission status: Time Limit Exceeded

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

a_max = max(a)
max_idx = [i for i, x in enumerate(a) if x == a_max]

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

Submission status: Time Limit Exceeded

Solution code:
Nlist = list(range(int(input())))
lst = []
for i in Nlist:
    lst.append(int(input()))


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

for i in range(n):
    if a[i] == max_num and a.count(max_num) == 1:
        a.pop(i)
        print(max(a))
        a = list(b)
    else:
        print(max_num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input()) 
t = [int(input()) for i in range(n)]
m = max(t)
for i in range(n):
	x = t.copy()
	if t[i] != m:
		print(m)
	else:
		x.pop(i)
		print(max(x))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[0 for i in range(N)]
for i in range(N):
  A[i]=int(input())
L=A.copy()
L.sort()
max1=L[N-1]
max2=L[N-2]
for i in range(N):
  if i == A.index(max1):
    print(max2)
  else:
    print(max1)

Submission status: Time Limit Exceeded

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

if n > 1:
	print(max(temp[1:n]))

	for i in range(1,n-1):
		print(max(max(temp[0:i]), max(temp[i+1:n])))

	print(max(temp[0:n-1]))

else:
	print(temp[0])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(input()) for i in range(n)]
m = str(max(A))
ANS = []

for i in range(n):
    if i == A.index(max(A)):
        ans = A[:]
        ans.pop(i)
        ANS.append(str(max(ans)))
    else:
        ANS.append(m)

print('\n'.join(ANS))

Submission status: Time Limit Exceeded

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

for i in range(n):
    if i == 0:
        s = 0
    else:
        s = i
    e = i + 1
    l = a[:s] + a[e:]
    print(sorted(l)[-1])

Submission status: Time Limit Exceeded

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

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)
for i in range(n):
    if (i in max_index) & (len(max_index) == 1):
        list2 = list.copy()
        del(list2[i])
        print(sorted(list2)[-1])
    else:
        print(max)

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)]
	maxNum = max(A)
	maxIndex = [i for i, x in enumerate(A) if x == max(A)]
	if len(maxIndex) > 1:
		for _ in range(N):
			print(maxNum)
	elif maxIndex[0] == 0:
		print(max(A[1:]))
		for i in range(1, N):
			print(maxNum)
	elif maxIndex[0] == N-1:
		for i in range(N-1):
			print(maxNum)
		print(max(A[:N-1]))
	else:
		for i in range(maxIndex[0]):
			print(maxNum)
		prev = max(max(A[:maxIndex[0]]), max(A[maxIndex[0]+1:]))
		print(prev)
		for i in range(maxIndex[0]+1, N):
			print(maxNum)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy

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

h=max(L)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
alist = []
for i in range(n):
  
  a = int(input())
  alist.append(a)
for j in range(n):
  blist = []
  blist.extend(alist)
  blist.pop(j)
    
  print(max(blist))
  blist.clear()

Submission status: Time Limit Exceeded

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

flag = {}
for i in range(n):
    if a[i] in flag:
        flag[a[i]] += 1
    else:
        flag[a[i]] = 1

for j in range(n):
    if flag[a[j]] > 1:
        flag[a[j]] -= 1
    else:
        flag.pop(a[j])
    
    print(max(flag))
    if a[j] in flag:
        flag[a[j]] += 1
    else:
        flag[a[j]] = 1

Submission status: Time Limit Exceeded

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

for i in range(len(a)):
    if a[i] != max_a or a.count(a[i]) > 1:
        print(max_a)
        continue
    print(sorted(a)[-2])

Submission status: Time Limit Exceeded

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

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

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)
	else:
		b = a[:]
		b[j] = 0
		print(max(b))

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 > 1 and i < N - 2:
        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 _ in range(n)]
ma = max(a)

for i in range(n):
  if a[i] != ma:
    print(ma)
  elif a.count(ma) > 1:
    print(ma)
  else:
    temp = a[:]
    del temp[i]
    print(max(temp))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import copy

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

def function(n,ls):
    array = copy.deepcopy(ls)
    array.pop(n)
    return max(array)
    
for i in range(n):
    print(function(i,ls))

Submission status: Time Limit Exceeded

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

for _ in range(n):
  b=a[0:_]+a[_+1:n]
  print(max(b))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = []
B = []

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

    
for i in range(N):
    B = list(A)
    B.pop(i)
    print(np.amax(B))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def ExceptionHandling(arr_len, origin_arr):
    for i in range(arr_len):
        arr = list(origin_arr);
        arr.pop(i);
        print(max(arr))
        arr = origin_arr;

if __name__ == "__main__":
    N = int(input());
    A = [];
    for i in range(N):
        A.append(int(input()));
    ExceptionHandling(N,A)

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

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

Submission status: Time Limit Exceeded

Solution code:
# 入力
N = int(input())

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

num_set = set(num_list)    
num_max = max(num_set)
for i in range(N):
    if num_list[i] >= num_max:
        target = num_list[:i] + num_list[i+1:]
        if num_max in target:
        	print(num_max)
        else:
          	print(max(set(target)))
    else:
        print(num_max)

Submission status: Time Limit Exceeded

Solution code:
def second(s):
    s.sort()
    s.reverse()
    return s[1]

N = int(input())
A = [int(input()) for i in range(N)]
B=A
for i in range(0,N):
    if A[i]==max(A):
        ans=second(B)
        print(ans)
    else:
        print(max(A))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
m = max(A)
for n in range(N):
    if A[n] < m:
        print(m)
        continue
    elif n == 0:
        print(max(A[n + 1:]))
    elif n == N - 1:
        print(max(A[:n]))
    else:
        print(max(max(A[:n]), max(A[n + 1:])))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
max1 = 0
for j in range(n):
    for k in range(n):
        if j == k:
            continue
        else:
            if a[k] > max1:
                max1 = a[k]

    print(max1)
    max1 = 0

Submission status: Time Limit Exceeded

Solution code:
import copy
from sys import stdin
n=int(input())
A=[int(stdin.readline().rstrip()) for _ in range(n)]
for j in range(0,n):
    B=copy.copy(A)
    s=A[j]
    A.pop(j)
    print(max(A))
    A = copy.copy(B)

Submission status: Time Limit Exceeded

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

for j in range(N):
    A += [input()]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())

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

max_value = max(a_list)

for i in range(N):
  if a_list.count(max_value) > 1:
    print(max_value)
  else:
    if a_list[i] == max_value:
      print(sorted(a_list)[-2])
    else:
      print(max_value)

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
lists = [0]*N
ans = []
for i in range(N):
    A = int(input())
    lists[i] = A
i = 0
while 1:
    if i == N:
        break
    tmp = copy.deepcopy(lists[i])
    lists[i] = 0
    print(max(lists))
    lists[i] = tmp
    i += 1

Submission status: Time Limit Exceeded

Solution code:
import sys
# import numpy as np
from copy import deepcopy
input = sys.stdin.readline


def main():
    N = int(input())
    # A = np.array([int(input()) for _ in range(N)])
    A = [int(input()) for _ in range(N)]
    # print(A)

    for j in range(N):
        B = deepcopy(A)
        del B[j]
        print(max(B))
        # if j != A.index(max(A)):
        #     print(max(A))
        # else:
        #     ans = [x for i, x in enumerate(A) if i != j]
        #     print(max(ans))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = [int(input()) for _ in range(N)]
as_tmp = list(As.copy())
for x in As:
  as_tmp.remove(x)
  print(max(as_tmp))
  as_tmp = list(As.copy())

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

Submission status: Time Limit Exceeded

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

max_index=np.argmax(A)
a_max=int(A[max_index])
a_second=int(np.amax(np.delete(A,max_index)))
A[:]=a_max
A[max_index]=a_second
for a in A:
    print(int(a))

Submission status: Time Limit Exceeded

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

for i in range(n):
  if pre_max != a[i]:
    print(pre_max)
  else:
    copy_a = copy.copy(a)
    copy_a.pop(i)
    print(max(copy_a))

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for _ in range(N):
    a = int(input())
    A.append(a)
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:
# -*- coding: utf-8 -*-

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

s_max = max(s)
for i in range(len(s)):
    temp = s.pop(i)
    if (temp == s_max):
        print(max(s))
    else:
        print(s_max)
    s.insert(i, temp)

Submission status: Time Limit Exceeded

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

max_value = max(A)
max_index = [i for i, x in enumerate(A) if x == max_value]
second = sorted(A)[-2]

for i in range(N):
  if i in max_index:
    if len(max_index) >= 2:
      print(max_value)
    else:
      print(second)
  else:
    print(max_value)

Submission status: Time Limit Exceeded

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

for i in range(0,N):
    ans = 0
    for j in range(0,N):
        if i != j and  A[j] > ans :
            ans = A[j]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
data = []

i = input()

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

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

Submission status: Time Limit Exceeded

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

ans = []
front_max = back_max = 0

for i in reversed(range(N)):
    now = A.pop()
    front_max = max(A) if A else 0
    ans.append(max(front_max, back_max))
    back_max = max(now, back_max)

for i in reversed(range(N)):
    print(ans[i])

Submission status: Time Limit Exceeded

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

M = max(r_list)
max_index = [i for i, v in enumerate(r_list) if v == max(r_list)]

if len(max_index) > 1:
    for i in range(n):
        print(M)
if len(max_index) == 1:
    index = int(max_index[0])
    
    for i in range(index):
        print(M)
        
    del(r_list[index])
    print(max(r_list))
    
    for i in range(n-index-1):
        print(M)

Submission status: Time Limit Exceeded

Solution code:
n=input()
n=int(n)
a=[]
for i in range(n):
  s=input()
  a.append(s)
for j in range(n):
  t=a
  b=t[0]
  del t[0]
  print(max(t))
  t.append(b)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import sys
from collections import deque

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

N = int(input())
que = deque([int(input()) for i in range(N)])
tmp = 0
max_num = max(set(que))

for i in range(N):
    tmp = que.popleft()
    if tmp != max_num:
        print(max_num)
    else:
        print(max(set(que)))
    que.append(tmp)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a_list = []
max_v = -1
max_ind = []
for i in range(N):
    a_list.append(int(input()))
    if a_list[-1]>max_v:
        max_v = a_list[-1]
        max_ind = [i]
    elif a_list[-1]==max_v:
        max_ind.append(i)
del a_list[max_ind[-1]]
sec = max(a_list)
for i in range(N):
    if i in max_ind:
        print(sec)
    else:
        print(max_v)

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

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    if i == A.index(max(A)):
        ans = A[:]
        ans.pop(i)
        print(max(ans))
    else:
        print(m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(input())
num_line  =[]
for e in map(int, sys.stdin):
    num_line.append(e)
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:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
for j in range(N):
    if (A[j] != max(A)):
        print(max(A))
    elif(A.count(A[j]) != 1):
        print(A[j])
    else:
        print(sorted(A)[-2])

Submission status: Time Limit Exceeded

Solution code:
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)]
max_a = max(a)
for i in range(len(a)):
    if a[i] != max_a:
        print(max_a)
        continue
    if a.count(a[i]) > 1:
        print(max_a)
        continue
    b = a.copy()
    del b[i]
    print(max(b))

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())
x=list(int(input()) for _ in range(n))

import numpy as np

y=np.array(x)
z=np.ones(n)

for i in range(n):
	z=np.ones(n)
	z[i]=0
	print(int(max(y*z)))

Submission status: Time Limit Exceeded

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

for i in range(N):
    # rem = A[i]
    # A.remove(rem)
    # print(max(A))
    # A.insert(i, rem)
    ans = 0
    for j in range(N):
        if not i == j and ans < A[i]:
            ans = A[j]

    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
    if a[i] == max1:
        a[i] = 0
        max2 = max(a)
        print(max2)
        a[i] = max1
        
    else:
        print(max1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = {}
for i in range(n):
    s[i] = int(input())

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

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):
  a_pop = []
  for j in range(n):
    if i != j:
      a_pop.append(a[j])
  print(max(a_pop))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
count = int(input())
nlist = []
for i in range(count):
    a = int(input())
    nlist.append(a)
mlist = tuple(nlist)
biggest = max(mlist)
nlist.remove(biggest)

for i in range(count):
    if mlist[i] == biggest:
        print(max(nlist))
    else:
        print(biggest)

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):
        Ap = []
        Ap = copy.copy(A)
        del Ap[i]
        print(max(Ap))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())

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

i = 0

while i < n:
    max_value = sorted(set(columns))[-1]
    if max_value == columns[i]:
        tmp = copy.copy(columns)
        del tmp[i]
        print(sorted(set(tmp))[-1])
    else:
        print(max_value)
    i += 1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    A_ = [A[j] for j in range(0, N) if i != j]
    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[1:]))
    elif i == 1 and N == 2:
        print(A[0])
    elif i == 1 and N > 2:
        print(max(A[0], max(A[2:])))
    elif i == N -2:
        print(max(max(A[:N-2]), A[N-1]))
    elif i == N - 1:
        print(max(A[:N-1]))
    else:
        print(max(A[:i]),max(A[i+1:]))

Submission status: Time Limit Exceeded

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

for i in range(n):
  copy_a = copy.copy(a)
  tmp = copy_a.pop(i)
  if pre_max != tmp:
    print(pre_max)
  else:
    this_max = max(copy_a)
    print(this_max)
    pre_max = this_max

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

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):
    if (A[j] != max(A)):
        print(max(A))
    elif(A.count(A[i]) > 1):
        print(A[i])
    else:
        print(sorted(A)[-2])

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)]
	maxNum = max(A)
	maxIndex = [i for i, x in enumerate(A) if x == max(A)]
	if len(maxIndex) > 1:
		for _ in range(N):
			print(maxNum)
	elif maxIndex[0] == 0:
		print(max(A[1:]))
		for i in range(1, N-1):
			if i != maxIndex[0]:
				print(maxNum)
			else:
				prev = max(max(A[:i]), max(A[i+1:]))
				print(prev)
		print(maxNum)
	elif maxIndex[0] == N-1:
		print(maxNum)
		for i in range(1, N-1):
			if i != maxIndex[0]:
				print(maxNum)
			else:
				prev = max(max(A[:i]), max(A[i+1:]))
				print(prev)
		print(max(A[:N-1]))
	else:
		for i in range(N):
			if i != maxIndex[0]:
				print(maxNum)
			else:
				prev = max(max(A[:i]), max(A[i+1:]))
				print(prev)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
for n in range(N):
    if n == 0:
        print(max(A[n + 1:]))
    elif n == N - 1:
        print(max(A[:n]))
    else:
        print(max(max(A[:n]), max(A[n + 1:])))

Submission status: Time Limit Exceeded

Solution code:
data = []

def maxsearchex(n):
	maxInt = 0
	for i in range(len(data)):
		if i != n:
			if maxInt < data[i]:
				maxInt = data[i]
	print(maxInt)

i = input()

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

for i in range(len(data)):
	maxsearchex(i)

Submission status: Time Limit Exceeded

Solution code:
import copy


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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

for i in range(N): 
    if A.index(max(A))==i:
        print(sorted(A)[-2])
    else:    
        print(max(A))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
for i in range(n):
    tmp=0
    for j in range(n):
        if(j!=i and tmp<a[j]):
            tmp = a[j]
    print(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
for i in range(N):
    A_=A[:i]
    A__=A[i+1:]
    print(max(A_+A__))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
a = [int(input()) for i in range(N)]
max_a = np.max(a)
for i in range(N):
    if a[i] != max_a:
        print(max_a)
    else:
#         print(i)
#         print(a[0:i]+a[i+1:])
        premax_a = np.max(a[0:i]+a[i+1:]) 
        print(premax_a)

Submission status: Time Limit Exceeded

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

def select(i):
  s = []
  for j in range(N):
    if j != i :
      s.append(list[j])
      
  print(np.max(s))
     
for n in range(N):
  list.append(int(input()))
  
for i in range(N):
  select(i)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A = [int(input()) for i in range(N)]
for i,a in enumerate(A):
  B = A[:]
  B[i]=0
  print(max(B))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(N):
  L = A.copy()
  L[i]=0
  L.sort()
  print(L[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 = A[:]
    ans.pop(i)
    print(max(ans))

Submission status: Time Limit Exceeded

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

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

for i in range(N):
  backup = array.pop(i)
  print(max(array))
  array.insert(i, backup)

Submission status: Time Limit Exceeded

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

max_value = max(A)
max_index = [i for i, x in enumerate(A) if x == max_value]

for i in range(N):
  if i in max_index:
    if len(max_index) >= 2:
      print(max_value)
    else:
      new_list = A[:]
      x = new_list.pop(i)
      print(max(new_list))
  else:
    print(max_value)

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):
  buf = li.pop(j)
  if buf<m:
    print(m)
  else:
  	print(max(li))
  li.insert(j,buf)

Submission status: Time Limit Exceeded

Solution code:
from builtins import enumerate, len

import numpy as np
import copy

N = int(input())
nums = []

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

a = np.array(nums)
maxIndex = [i for i, x in enumerate(a) if x == np.max(a)]

max1 = 0
max2 = 0

if(len(maxIndex)==1):
    nums2 = copy.copy(nums)
    nums2.pop(maxIndex[0])
    b = np.array(nums2)
    maxIndex2 = [i for i, x in enumerate(b) if x == np.max(b)]
    max1 = nums[maxIndex[0]]
    max2 = nums2[maxIndex2[0]]
else:
    max1 = nums[maxIndex[0]]
    max2 = nums[maxIndex[0]]

for num in nums:
    if(num!=max1):
        print(max1)
    else:
        print(max2)

Submission status: Time Limit Exceeded

Solution code:
cnt = int(input())
lst = [int(input()) for i in range(cnt)]

for i, j in enumerate(lst):
    lst[i] = 0
    print(max(lst))
    lst[i] = j

Submission status: Time Limit Exceeded

Solution code:
sequence = []

N = int(input())

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

# print('sequence', sequence)

for i in range(N):
    temp = sequence[:]
    temp.pop(i)
    # print('temp', temp)
    print(max(temp))

Submission status: Time Limit Exceeded

Solution code:
Nlist = list(range(int(input())))
lst = []
for i in Nlist:
    lst.append(int(input()))

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

now_max = -1
prev_max = 100000000
left_max = -1
right_max = -1
right_max_index = 0

N = int(input())
A_list = [int(input()) for _ in range(N)]
np_A_list = np.array(A_list)
for i, A in enumerate(A_list):
    # 右端
    if i == len(A_list) - 1:
        print(left_max)
        break
    if right_max_index == i:
        slc = np_A_list[i + 1:]
        right_max = slc.max()
        right_max_index = slc.argmax() + i + 1

    if left_max > right_max:
        now_max = left_max
        print(left_max)
    else:
        now_max = right_max
        print(right_max)
    
    if prev_max < now_max:
        left_max = right_max = now_max
        right_max_index = 10000000
    
    prev_max = now_max
    if left_max < A:
        left_max = A