Problem:


Score : 300 points

Problem Statement

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

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

Constraints

2 \leq N \leq 200000

1 \leq A_i \leq 200000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

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

Sample Input 1

3
1
4
3

Sample Output 1

4
3
4

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

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

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

Sample Input 2

2
5
5

Sample Output 2

5
5



Sample input:
3
1
4
3


Sample output:
4
3
4

Submission status: Time Limit Exceeded

Solution code:

N=int(input())

X=[]
for x in range(N):
    X.append(int(input()))

result=[]
Y=[]
for i in range(len(X)):
    Y=X[:]
    Y.pop(i)
    result.append(max(Y))

for x in result:
    print(x)

Submission status: Time Limit Exceeded

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

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


for i, v in enumerate(l):
    origin = copy.copy(l)
    origin.pop(i)
    print(sorted(origin)[-1])

Submission status: Time Limit Exceeded

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

max_index = set([i for i, x in enumerate(A) if x == max(A)])
f = max(A)
A_sort = sorted(A, reverse=True)
A_list=list(set(A_sort))
if len(A_list) != 1:
    s = A_list[1]
else:
    s = f

for i in range(N):
    if i in max_index:
        print(s)
    else:
        print(f)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
# リスト内包表記
numList  = [input() for i in range(n)]

workList = numList.copy()
for j in range(n):
  workList.remove(numList[j])
  print(max(set(workList)))
  workList = numList.copy()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

A_i_max = max(A_i)

for i in range(N):
    if A_i_max == A_i[i] and A_i.count(A_i[i]) == 1:
        A_i_copy = A_i[:]
        A_i_copy.pop(i)
        print(max(A_i_copy))
    else:
        print(A_i_max)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
a = [int(input()) for i in range(N)]

a = np.array(a)
max_a = np.max(a)
max_idx = np.where(a == max_a)[0]

if len(max_idx) != 1:
    for i in range(N):
        print(max_a)
else:
    premax_a = np.max(np.hstack((a[0:max_idx[0]], a[max_idx[0]+1:])))
    for i in range(N):
        if i == max_idx:
            print(premax_a)
        else:
            print(max_a)

Submission status: Time Limit Exceeded

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

for i in range(N):
    remA=A.pop(0)
    mA.append(max(A))
    A.append(remA)

for i in range(N):
    print(str(mA[i]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def resolve():
    N = int(input())
    A = [int(input()) for i in range(N)]
    A = np.array(A)
    idx = np.argsort(A)[::-1]
    A = A[idx]
    for i in range(N):
        print(A[np.where(idx != i)[0][0]])
        
resolve()

Submission status: Time Limit Exceeded

Solution code:
import copy

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [int(input()) for _ in range(n)]
a_unique = list(sorted(set(a), reverse=True))
max_value = max(a_unique)
for i in range(n):
    current_value = a.pop(i)
    if max_value in a:
        print(max_value)
    else:
        print(a_unique[1])
    a.insert(i, current_value)

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.max(A)
j = np.argmax(A)
ans2 = np.max(np.delete(A,j))

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

Submission status: Time Limit Exceeded

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

workList = numList.copy()
for j in range(n):
  workList.remove(numList[j])
  print(max(set(workList)))
  workList = numList.copy()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
data = [int(input()) for _ in range(num)]

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

Submission status: Time Limit Exceeded

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

for i in range(s):
    a0 = a[i]
    a[i] = 0
    b.append(max(a))
    a[i] = a0
    print(b[i])

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)]
    Ap = copy.copy(A)
    set(Ap)
    Ap.sort(reverse=True)
    Am = max(A)
    for i in range(N):
        if i != A.index(Am) or A.count(Am)>1:
            print(Am)
        else:
            print(Ap[1])
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = input()
a = []
for i in range(N):
        a.append(input())
B = max(a)
for i in range(N):
        if a[i] != B:
                print(B)
        else:
                b = a.pop(i)
                print(max(a))
                a.insert(i,b)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
#print(A)
max_index = set([i for i, x in enumerate(A) if x == max(A)])
f = max(A)
A_sort = sorted(A, reverse=True)
A_list=list(set(A_sort))
if len(A_list) != 1:
    s = A_list[1]
else:
    s = f

l = len(max_index)
#print(max_index)
for i in range(N):
    if i in max_index:
        print(s)
    else:
        print(f)

Submission status: Time Limit Exceeded

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

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


for i, v in enumerate(l):
    origin = copy.copy(l)
    origin.pop(i)
    print(max(origin))

Submission status: Time Limit Exceeded

Solution code:
import copy

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
a = [int(input()) for i in range(N)]

a = np.array(a)
max_a = np.max(a)
max_idx = np.where(a == max_a)[0]
if len(max_idx) > 1:
    for i in range(N):
        print(max_a)
else:
    premax_a = np.max(np.hstack((a[0:max_idx[0]], a[max_idx[0]+1:])))
    for i in range(N):
        if i == max_idx:
            print(premax_a)
        else:
            print(max_a)

Submission status: Time Limit Exceeded

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

maximum = max(a)

for i in a:
    if i == maximum:
        b = a.copy()
        b.remove(i)
        print( max(b) )
    else:
        print(maximum)

Submission status: Time Limit Exceeded

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

workList = numList[:]
for j in range(n):
  workList.remove(numList[j])
  print(max(set(workList)))
  workList = numList.copy()

Submission status: Time Limit Exceeded

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

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

for i in range(N):
    d = D[i]
    if d < max(D):
        print(max(D))
    else:
        l = D.copy()
        l.pop(i)
        print(max(l))

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
A = list()
for i in range(N) :
	A.append(int(input()))

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

Submission status: Time Limit Exceeded

Solution code:
N = input()
a = []
for i in range(N):
        a.append(input())
B = max(a)
for i in range(N):
        if B == max(a):
                b = a.pop(i)
                print(max(a))
                a.insert(i,b)
        else:
                print(B)

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;
f = max(b);
for i in range(a):
    if max(b) > b[i]:
        print(f);
    elif max(b) == b[i]:
        d = copy.copy(b);
        del d[i]
        e = max(d);
        print(e);

Submission status: Time Limit Exceeded

Solution code:
import copy


def resolve():
    N = int(input())
    A = [int(input()) for i in range(N)]
    for i in range(N):
        B = copy.copy(A)
        B[i] = 0
        B.sort()
        print(B[-1])
        
        
resolve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
#print(A)
max_index = set([i for i, x in enumerate(A) if x == max(A)])
f = max(A)
A_sort = sorted(A, reverse=True)
A_list=list(set(A_sort))
if len(A_list) != 1:
    s = A_list[1]
else:
    s = f

l = len(max_index)
#print(max_index)
for i in range(N):
    if i in max_index and l-1==0:
        print(s)
    else:
        print(f)

Submission status: Time Limit Exceeded

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

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_i = []
for i in range(N):
    A_i.append(int(input()))

for i in range(N):
    A_i_copy = []
    if i == 0:
        A_i_copy = sorted(A_i[1:N])
    elif i == N - 1:
        A_i_copy = sorted(A_i[0:N-1])
    else:
        A_i_copy = sorted(A_i[0:i] + A_i[i+1:N])

    print(A_i_copy[N - 2])

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)

ans = 0
for i in range(N):
    rem = A[i]
    A[i] = 0
    if A[i] > ans and A[i] > rem:
        print(ans)
    else:
        Ao = sorted(A)
        ans = Ao[N-1]
        A[i] = rem
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
a = [int(input()) for i in range(N)]

a = np.array(a)
max_a = np.max(a)
max_idx = np.where(a == max_a)[0]
if len(max_idx) > 1:
    for i in range(N):
        print(max_a)
else:
    premax_a = np.max(a[a<max_a])
    for i in range(N):
        if i == max_idx:
            print(premax_a)
        else:
            print(max_a)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())

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

maxNum = max(s)

def func(n):
  if maxNum < n:
    return str(maxNum)
  else:
    list = s[:]
    list.remove(n)
    return str(max(list))


def main():
  print('\n'.join(map(func,s)))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

num_list = []
num_max = 0
num_max2 = 0
for i in range(N):
    num_list.append(int(input()))
    num = num_list[i]
    # 1番目に大きい数と２番目に大きい数を保持                                                                          
    if num_max2 < num_list[i]:
        if num_max < num_list[i]:
            num_max = num_list[i]
            continue
        num_max2 = num_list[i]
        continue

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(num_max2)
    else:
        print(num_max)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

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

array = np.array(num_list)

[print((np.delete(array, i).max())) for i in range(N)]

Submission status: Time Limit Exceeded

Solution code:
N, *d = map(int, open(0).read().split())
m=d.index(max(d))
c=[max(d)] *N
  
for j in range(N):
    d[m]=0
    y=max(d)

c[m]=y
for i in range(len(c)):
    print(c[i])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [0 for n in range(n)]
for i in range(n):
  a[i] = 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())
l=[int(input()) for i in range(N)]
for i in range(len(l)):
    t=l.pop(i)
    print(max(l))
    l.insert(i, t)

Submission status: Time Limit Exceeded

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

if len(sorted(set(A))) == 1 or sorted(A)[-1] == sorted(A)[-2]:
  for i in range(N):
    print(max(A))
else:
  for i in range(N):
    if A[i] == max(A) and bool:
      print(sorted(A)[-2])
      bool = False
    else:
      print(max(A))

Submission status: Time Limit Exceeded

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

workList = numList[:]
for j in range(n):
  workList.remove(numList[j])
  workSet = set(workList)
  print(max(workSet))
  workList = numList[:]

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import numpy as np
N = int(input())
A = [int(input()) for _ in range(N)]

# d = deque()
R = deque(A)
R.append(0)
L = deque([0])

maxA = np.max(R)
for i in A:
  R.popleft()
  if i >= maxA: 
    maxA = max(np.max(L), np.max(R))
  print(maxA)
  L.append(i)

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.max(A)
j = np.argmax(A)
ans2 = np.max(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())
lst = []
lst = [int(input()) for i in range(N)]
for i in range(N):
  tmp0 = lst.copy()
  
  tmp0.pop(i)
  print(max(tmp0))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy
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:
N=int(input())
a=[int(input()) for i in range(N)]
for i in range(N):
  b = int(a.pop(i))
  print(max(a))
  a.insert(i,b)

Submission status: Time Limit Exceeded

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

if len(sorted(set(A))) == 1 or sorted(A)[-1] == sorted(A)[-2]:
  for i 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:
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    Am = max(A)
    for i in range(N):
        if i != A.index(Am) or A.count(Am)>1:
            print(Am)
            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())
data = [int(input()) for k in range(n)]
for i in range(n):
	s = [data[t] for t in range(n)]
	s[i] = 0
	s.sort()
	print(s[-1])

Submission status: Time Limit Exceeded

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

#n=list(map(int,input().split()))
n = int(input()) 
num = [input() for _ in range(n)] 

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

Submission status: Time Limit Exceeded

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

for i in range(0,N):
  b=copy.copy(a)
  de=b.pop(i)
  print(max(b))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque 

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

for i in range(N):
    remA=A.popleft()
    print(max(A))
    A.append(remA)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

N = int(input())

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

def hoge(tmp,i):
    tmp.pop(i)
    return tmp


for j in range(N):
    tmp_list = []
    bn = an.copy()
    tmp_list = hoge(bn,j)
    print(max(tmp_list))

# print(tmp_list)
# print(max(tmp_list))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
#print(A)
max_index = set([i for i, x in enumerate(A) if x == max(A)])
l = len(max_index)
#print(max_index)
for i in range(N):
    if i in max_index and l-1==0:
        a = A[:i]+[0]
        b = A[i+1:]+[0]
        print(max(max(a),max(b)))
    else:
        print(max(A))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
mylist = []
for i in range (N):
  A = int(input())
  mylist.append(int(A))
for j in range (N):
  data = mylist[j]
  my = sorted(mylist,reverse=True)
  if data == my[0]:
    print(my[1])
  else:
    print(my[0])
del my[2:]

Submission status: Time Limit Exceeded

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

for i in range(N):
    d = D[i]
    if d < max(D):
        print(max(D))
    else:
        l = D.copy()
        l.pop(i)
        print(max(l))

Submission status: Time Limit Exceeded

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

for i in range(N) :
	x = A[i]
	A[i] = 0
	print(max(A))
	A[i] = x

Submission status: Time Limit Exceeded

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

#n=list(map(int,input().split()))
n = int(input()) 
num = [input() for i in range(n)] 


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

Submission status: Time Limit Exceeded

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

v_max = max(v)
for i in range(n):
    if v[i] == v_max:
        v_i = v.pop(i)
        print(max(v))
        v.insert(i, v_i)
    else:
        print(v_max)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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(n):
    s = cul(i,ls)
    print(s)

Submission status: Time Limit Exceeded

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

index = sorted([i for i, v in enumerate(A) if v == max(A)])
if len(index) == 1:
  for i in range(N):
    if A[i] == max(A):
      print(sorted(A)[-2])
    else:
      print(max(A))
else:
  for _ in range(N):
    print(max(A))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import copy

a = int(input())
nums = [0]*a

for i in range(a):
    nums[i] = int(input())
    
for j in range(a):
    thisnums = copy.deepcopy(nums)
    thisnums[j] = 0
    print(max(thisnums))

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 = [None] * n
 
for i in range(n):
  buf = copy.copy(num_list)
  buf.pop(i)
  print(max(buf))

Submission status: Time Limit Exceeded

Solution code:
import array
from copy import deepcopy

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

a = array.array('i',a)
           
for i in range(0,len(a)):
  ax = deepcopy(a)
  del a[i]

  print(max(a))
  a = deepcopy(ax)
  

  #  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())
D = [0 for i in range(0,N)]
for i in range(0,N):
    D[i] = int(input())

for i in range(N):
    d = D[i]
    if d < max(D):
        print(max(D))
    else:
        l = D.copy()
        l.pop(i)
        print(max(l))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
mylist = []
for i in range (N):
  A = int(input())
  mylist.append(int(A))
for j in range (N):
  data = mylist[j]
  my = sorted(mylist,reverse=True)
  if data == my[0]:
    print(my[1])
  else:
    print(my[0])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def returnmax(numbers, i, N):
    nowmax = 0
    for j in range(N):
        if j != i:
            if nowmax < numbers[j]:
                nowmax = numbers[j]
    return nowmax
    
numbers = []
N = int(input())
for i in range(N):
    numbers.append(int(input()))
for i in range(N):
    print(returnmax(numbers, i, N))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())

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

maxNum = max(s)

def func(n):
  if maxNum < n:
    return maxNum
  else:
    list = s[:]
    list.remove(n)
    return max(list)

for i in s:
  print(func(i))
#print(list(map(func,s)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy

N = int(input())

num_list = []

for i in range(N):
  num = int(input())
  num_list.append(num)
    
for i in range(N):
  dummy_list = copy.copy(num_list)
  del dummy_list[i]
  print(np.amax(dummy_list))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

for i in range(n):
    tmp = num_list.pop(i)
    print(max(num_list))
    num_list.insert(i, tmp)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
x=[]
for i in range(n):
  x.append(int(input()))
cnt = [0] * n
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())
v = [int(input()) for i in range(n)]

for i in range(n):
    v_i = v.pop(i)
    print(max(v))
    v.insert(i, v_i)

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()))
    m = max(A)
    for i in range(0,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()))
for i in range(N):
    Ai=A[i]
    A[i]=0
    print(-min(A))
    A[i]=Ai

Submission status: Time Limit Exceeded

Solution code:
import copy

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

mv = max(l)
for i in range(N):
  if l[i] < mv:
    print(mv)
  if l[i] == mv:
    a = copy.copy(l)
    del a[i]
    print(max(a))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = []
for i in range(0,n):
  lst.append(int(input()))
  
ans = []
for i in range(0,len(lst)):
  sort_lst = lst[:]
  sort_lst.pop(i)
  sort_lst.sort(reverse=True)
  ans.append(sort_lst[0])
 
for d in ans:
  print(d)

Submission status: Time Limit Exceeded

Solution code:
def returnmax(numbers, i, N):
    nowmax = 0
    for j in range(N):
        if j != i:
            if nowmax < numbers[j]:
                nowmax = numbers[j]
    return nowmax
numbers = []
N = int(input())
for i in range(N):
    numbers.append(int(input()))
for i in range(N):
    print(returnmax(numbers, i, N))

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

v = nums 
#max(v[0:0],W[i],W[i+1])):
#1番目を除いたmax
ans_f= max(v[1:N])
print(ans_f)
#forの範囲はiは1からN-1まで
i=N-1
#print(v[i:N]) #i+1番目からN番目の要素まで
#print(v[0:i])
#print(v[i+1:N])
for i in range(1,N-1,1):
    max1=max(v[0:i])
    max2=max(v[i+1:N])
    maxp=max(max1,max2)
    print(maxp)

ans_e= max(v[0:N-1])
print(ans_e)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import numpy as np
N = int(input())
A = [int(input()) for _ in range(N)]

# d = deque()
R = deque(A)
R.append(0)
L = deque([0])

for i in A:
  R.popleft()
  print(max(np.max(L), np.max(R)))
  L.append(i)

Submission status: Time Limit Exceeded

Solution code:
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:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
for j in range(N):
  m = 0
  for k in range(N):
    if k == j:
      continue
    if A[k] > m:
      m = A[k]
  print(m)

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]

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

    exit()

not_arr = arr[arr != a_max]

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np 
n = int(input())
a = [int(input()) for i in range(n)]
aa = np.array(a)

for i in range(n):
    tmp = np.delete(aa,i)
    print(max(tmp))

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)
        list.sort(reverse=True)
        print(list[0])
    else:
        print(maxa)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lst = []
lst = [int(input()) for i in range(N)]
M = len(lst)
for i in range(M):
  tmp0 = lst[i]
  
  lst.pop(i)
  print(max(lst))
  lst.insert(i, tmp0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

maxNum = max(s)

def func(n):
  if maxNum < n:
    return maxNum
  else:
    list = s[:]
    list.remove(n)
    return max(list)

for i in s:
  print(func(i))
#print(list(map(func,s)))

Submission status: Time Limit Exceeded

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

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 = lst[:]
  sort_lst.pop(i)
  sort_lst.sort(reverse=True)
  print(sort_lst[0])

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(str(max(a)))
    a.insert(j, num)
print('\n'.join(ans))

Submission status: Time Limit Exceeded

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

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])    
    del(r_list[index])
    m = max(r_list)
    ans = [M]*(n-1)
    ans.insert(index, m)
    for i in range(n):
        print(ans[i])

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

for i in range(N):
    d = D.copy()
    d.pop(i)
    print(max(d))

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())

a = np.array([int(input()) for _ in range(n)])
[print(np.amax(np.hstack((a[:i], a[i+1:])))) for i in range(n)]

Submission status: Time Limit Exceeded

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