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 copy

n = int(input().split()[0])
a_list = []

for _ in range(n):
    a_list.append(int(input().split()[0]))

max_list = []

for i, a in enumerate(a_list):
    kouho_list = copy.copy(a_list)
    kouho_list.pop(i)
    max_list.append(max(kouho_list))

for x in max_list:
    print(x)

Submission status: Time Limit Exceeded

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

for j in range(n):
    copy_list = a_list.copy()
    del copy_list[j]
    max = 0
    for k in copy_list:
        if k > max:
            max = k
    print(max)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    xs = [int(stdin.readline().rstrip()) for _ in range(n)]

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for j in range(n):
    copy_list = a_list.copy()
    del copy_list[j]
    copy_list.sort()
    print(copy_list[-1])

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    xs = [int(stdin.readline().rstrip()) for _ in range(n)]

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    xs = [int(stdin.readline().rstrip()) for _ in range(n)]

    for i in range(n):
        ys = xs[:]
        ys.pop(i)
        print(max(ys))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
ls = []
for i in range(n):
    ls.append(int(input()))
for j in range(n):
    lss = copy.deepcopy(ls) 
    del lss[j]
    tmpmax = max(lss)
    print(tmpmax)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = [int(input()) for i in range(N)]
a = D[:]
b = [0 for k in range(N)]
for i in range(N):
    a[i] = 0
    print(max(a))
    a = D[:]

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = [int(input()) for i in range(N)]
a = D[:]
b = [0 for k in range(N)]
for i in range(N):
    a[i] = 0
    b[i] = max(a)
    a = D[:]
    
for j in range(N):
    print(b[j])

Submission status: Time Limit Exceeded

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

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


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

Submission status: Time Limit Exceeded

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

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


for i in range(N):
    for j in range(N):
        if j != i:
            B[j] = A[j]
        else:
            B[j] = 0
    print(max(B))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
an = []
for _ in range(n):
  an.append(int(input()))
maxl = [an[0]]
maxr = [an[-1]]
for a in an[1:]:
  maxl.append(max(maxl[-1], a))
for a in an[:-1][::-1]:
  maxr.insert(0, max(maxr[0], a))

print(maxr[1])
for i in range(1, n-1):
  print(max(maxl[i-1], maxr[i+1]))
print(maxl[n-2])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
an = []
for _ in range(n):
  an.append(int(input()))
maxl = [an[0]]
maxr = [an[-1]]
for a in an[1:]:
  maxl.append(max(maxl[-1], a))
for a in an[-2::-1]:
  maxr.insert(0, max(maxr[0], a))

print(maxr[1])
for i in range(1, n-1):
  print(max(maxl[i-1], maxr[i+1]))
print(maxl[n-2])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
if __name__ == "__main__":
    N = input()
    for i in range(int(N)):
        tmpA = input()
        if i == 0:
            A = np.array(int(tmpA))
        else:
            A = np.vstack((A,np.array(int(tmpA))))
    allmaxi = np.argmax(A)
    allmax = np.max(A)
    secondA = np.delete(A,allmaxi,axis=0)
    secondmaxi = np.argmax(secondA)
    secondmax = np.max(secondA)

    for i in range(int(N)):
        if i == allmaxi:
            print(secondmax)
        else:
            print(allmax)

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 sorted(A)[-1] != A[i]:
    print(sorted(A)[-1])
  else:
    print(sorted(A)[-2])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(N):
  if max(A) != A[i]:
    print(max(A))
  else:
    AA = copy.deepcopy(A)
    AA.remove(max(A))
    print(max(AA))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(range(N))
S=list(range(N-1))

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

for i in range(N):
    r=0
    for j in range(N):
     if j!=i:
       if A[j]>r:
          r=A[j]

    print(r)

Submission status: Time Limit Exceeded

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

for i in range(N):
    a = 0
    b = 0
    if (i != 0):
        a = max(num_array[0:i])
    if (i+1 < N):
        b = max(num_array[i+1:N])
    if a > b: 
        print(a)
    else: 
        print(b)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

L_max=max(L)

for i in range(N):
    now=L[i]
    
    if now!=L_max:
        ans=L_max
        
    else:
        L_temp=L.copy()
        L_temp_p=L_temp.pop(i)
        ans=max(L_temp)
    
    print(ans)

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):
    L_temp=L.copy()
    L_temp_p=L_temp.pop(i)
    print(max(L_temp))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = [int(input()) for i in range(n)]
ma = max(a)

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
i=0
for i in range(N):
    temp=A[i]
    del A[i]
    print(max(A))
    A.insert(i,temp)
    i += 1

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
i=0
while i < N:
    cont=A[i]
    del A[i]
    print(max(A))
    A.insert(i,cont)
    i += 1

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
i=0
while i < N:
    cont=A[i]
    del A[i]
    print(max(A))
    A.insert(i,cont)
    i += 1

Submission status: Time Limit Exceeded

Solution code:


N=int(input())
A=[int(input()) for i in range(N)]
A=list(map(int,A))
i=0
while i < N:
    cont=A[i]
    del A[i]
    print(max(A))
    A.insert(i,cont)
    i += 1

Submission status: Time Limit Exceeded

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

for j in range(N):
  num_list = num.copy()
  num_list.pop(j)
  print(max(num_list))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
if __name__ == "__main__":
    N = input()
    for i in range(int(N)):
        tmpA = input()
        if i == 0:
            A = np.array(int(tmpA))
        else:
            A = np.vstack((A,np.array(int(tmpA))))
    for i in range(int(N)):
        print(np.max(np.delete(A,i,axis = 0)))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = []
for i in range(n):
    ls.append(int(input()))
maxnum = max(ls)
for i in range(n):
    if maxnum > ls[i]:
        print(maxnum)
    else:
        lstmp = ls[0:i] + ls[i+1:]
        print(max(lstmp))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
s = []
for _ in range(n):
    s.append(int(input()))
max_s = max(s)
d = copy.copy(s)
for i in range(n):
    if max_s != s[i]:
        print(max_s)
    else:
        d = copy.copy(s)
        del d[i]
        print(max(d))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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[:]
  Ai.pop(i)
  print(max(Ai))

Submission status: Time Limit Exceeded

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

e = [0 for j in range(N)]

for i in range(N):
    e = D[:]
    del e[i]
    print(max(e))

Submission status: Time Limit Exceeded

Solution code:


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

e = [0 for j in range(N)]

for i in range(N):
    e = D[:]
    e[i] = 0
    print(max(e))

Submission status: Time Limit Exceeded

Solution code:
import copy

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

e = [0 for j in range(N)]

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

Submission status: Time Limit Exceeded

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

arr2 = sorted(arr)
  
for i in range(n):
  if max(arr) == arr[i]:
    print(arr2[-2])
  else:
    print(arr2[-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

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

    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)
    AA = sorted(A)
    m = AA[-1]
    m2 = AA[-2]
    maxIndex = [i for i, x in enumerate(A) if x == m]
    
    for i in range(N):
        if i not in maxIndex or len(maxIndex) > 1:
            print(m)
        else:
            print(m2)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

N = int(input())

lst_A = []

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

for i in range(N):
    W = lst_A[0]
    del lst_A[0]
    print(max(lst_A))
    lst_A.append(W)

Submission status: Time Limit Exceeded

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

N = int(input())

values = [0]*N
value_count_map = {}
for i in range(N):
    in_value = int(input())
    values[i] = in_value
    value_count = 0
    if in_value in value_count_map:
        value_count = value_count_map[in_value]
    value_count_map[in_value] = value_count + 1

for row in range(N):
    row_value = values[row]
    max_value = max(value_count_map.keys())
    if row_value != max_value:
        print(max_value)
    elif value_count_map[row_value] != 1:
        print(max_value)
    else:
        # if row value is a unique max value
        value_count = value_count_map.pop(row_value)
        max_value = max(value_count_map.keys())
        print(max_value)
        value_count_map[row_value] = value_count

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
list=[int(input()) for i in range(n)]
max = 0
for i in range(n):
    temp_list = copy.copy(list)
    temp_list.pop(i)
    temp_list.sort(reverse=True)
    print(temp_list[0])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
list=[int(input()) for i in range(n)]
max = 0
for i in range(n):
    if(i == 0):
        max = list[1]
    else:
        max = list[0]
    count = 0
    for c in list:
        if(max < c and i != count):
            max = c
        count += 1
    print(max)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [0]*(n)
for i in range(n):
    a[i] = int(input())
for i in range(n):
    max = 0
    for j in range(n):
        if j == i:
            continue
        if a[j] > max:
            max = a[j]
    print(max)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    if i == 0:
        print(max(A[1:]))
        continue
    elif i == N-1:
        print(max(A[:N]))
        continue
    
    a_l = max(A[:i])
    a_h = max(A[i+1:])
    
    if a_l >= a_h:
        print(a_l)
    else:
        print(a_h)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
escape = min(a) - 1
for i in range(len(a)):
    compare = list(a)
    compare[i] = escape
    print(max(compare))

Submission status: Time Limit Exceeded

Solution code:
def maximum(l,ind):
	max=-90000000
	for i in range(0,len(l)):
		if(i!=ind):
			if(l[i]>max):
				max=l[i]
	return max
n=int(input())
l=[]
for i in range(0,n):
	l.append(int(input()))
for i in range(0,n):
	print(maximum(l,i))

Submission status: Time Limit Exceeded

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

for i in range(N):
  list2 = list1[:i]+list1[i+1:]
  print(max(list2))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = []
for i in range(1, N+1):
  l.append(int(input()))
for i, Ai in enumerate(l):
  del l[i]
  print(max(l))
  l.insert(i, Ai)

Submission status: Time Limit Exceeded

Solution code:
import math
import copy

def first(a):
 a=A

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


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

Submission status: Time Limit Exceeded

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

M = max(lis)

for i in range(n):
    if lis[i] == M:
        lis2 = lis[:i] + lis[(i+1):]
        print(max(lis2))
    else:
        print(M)

Submission status: Time Limit Exceeded

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

m = max(Alist)
for i in range(N):
    if Alist[i]==m:
        print(max(Alist[:i] + Alist[i+1:]))
    else:
        print(m)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    
    d = {}
    [d.update({i:int(input())}) for i in range(N)]
    
    for i in range(N):
        d2 = d.copy()
        d2.pop(i)
        print(max(d2.values()))
    
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for j in range(n):
  p = l.copy()
  #print(p)
  if p[j] != a:
    print(a)
  else:
    p.remove(p[j])
    #print(p)
    print(max(p))

Submission status: Time Limit Exceeded

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

for j in range(n):
  p = l.copy()
  #print(p)
  p.remove(p[j])
  #print(p)
  print(max(p))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
max_a = max(a)
tmp_a = a.copy()
count = 0
for i in range(n):
    if tmp_a[i] == max_a:
        count += 1

if count == 1:
    for i in range(len(a)):
        tmp_a = a.copy()
        if tmp_a[i] == max_a:
            del tmp_a[i]
            print(max(tmp_a))
        else:
            print(max_a)
else:
    for i in range(len(a)):
        print(max_a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
max_a = max(a)
for i in range(len(a)):
    tmp_a = a.copy()
    if tmp_a[i] == max_a:
        del tmp_a[i]
        print(max(tmp_a))
    else:
        print(max_a)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys

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

list =[]  
for i in range(N):
    for j in range(N):
        if(j != i):
            list.append(numbers[j])
            
    print(max(list))
    list.clear()

Submission status: Time Limit Exceeded

Solution code:

iN      =   int(input())
lA      =   []

for i in range(iN):
    iTmp    =   int(input())
    lA.append(iTmp)

for exception_num in range(iN):
    Max =   max(lA[0:exception_num] + lA[exception_num+1:])
    print(Max)

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):
    sub = A[j]
    del A[j]
    print(max(A))
    A.insert(j,sub)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

S = input()
N = int(S)

A = np.zeros([N])
A_temp = np.zeros([N])

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

max = 0

index_max = np.argmax(A)

for i in range(0, N, 1):
    A_temp = np.copy(A)
    if index_max != i:
        print(int(A_temp[index_max]))
    else:
        A_temp[i] = 0
        print(int(np.amax(A_temp)))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for i in range(N)]
for i in range(N):
  copy_A = A[:i]+A[i+1:]
  copy_A.sort(reverse=True)
  print(copy_A[0])

Submission status: Time Limit Exceeded

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

temp=sorted(adic.items(),key=lambda x: x[1],reverse=True)
for i in range(n):
    if i != temp[0][0]:
        print(max(a))
    else:
        print(temp[1][1])

Submission status: Time Limit Exceeded

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

for i in range(n):
    b=a[:]
    del b[i]
    b.sort(reverse=True)
    print(b[0])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input()) #1行目のNを取得する
s = [input() for i in range(N)] #複数行の数値の入力を取得

max_ind = [i for i, a in enumerate(s) if a == max(s)]
max_num = max(s)

if len(max_ind) > 1:
    for i in range(N):
        print(max_num)

else:
    max_ind = s.index(max(s))
    max_num = max(s)
    s.pop(max_ind)
    max2_num = max(s)

    for i in range(N):
        if i == max_ind:
            print(max2_num)
        else:
            print(max_num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
c = sorted(a,reverse=True)
if a.count(max(a))>1:
    for i in range(n):
        print(max(a))
else:
    for i in range(n):
        if i==a.index(max(a)):
            print(c[1])
        else:
            print(max(a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input()) #1行目のNを取得する
s = [input() for i in range(N)] #複数行の数値の入力を取得


for i in range(N):
    buf = s.copy()
    buf.pop(i)
    ans = max(buf)
    print(ans)

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=0
    b=[False for x in range(n)]
    b[i]=True
    for j in range(n):
        if(b[j]==False and l[j]>tmp):
            tmp=l[j]
    print(tmp)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import itertools as ite
import math
import random
import sys
import codecs
from collections import defaultdict

INF = 10 ** 18
MOD = 10 ** 9 + 7

sys.setrecursionlimit(1000000)

N = input()
A = [input() for i in range(N)]
maxA = max(A)
if A.count(maxA) > 1:
    for i in range(N):
        print maxA
else:
    for i in range(N):
        if A[i] == maxA:
            print max(A[:i] + A[i + 1:])
        else:
            print max(A)

Submission status: Time Limit Exceeded

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

max_val = max(a)

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

Submission status: Time Limit Exceeded

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

max_val = max(a)

for i in range(n):
    if max_val > a[i]:
        print(max_val)

    elif max_val == a[i]:
        temp = a[i]
        a[i] = 0
        print(max(a))
        a[i] = temp

Submission status: Time Limit Exceeded

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

#print(a)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def q46(n, a):
    a = np.array(a)
    m = max(a)
    for i in range(n):
        if a[i] < m:
            print(m)
        else:
            ind = np.ones(n, dtype=bool)
            ind[i] = False
            print(max(a[ind]))

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

q46(N, A)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def q46(n, a):
    a = np.array(a)
    for i in range(n):
        ind = np.ones(n, dtype=bool)
        ind[i] = False

        print(max(a[ind]))
        #print(del a[i:i])
N = int(input())
A =[]
for i in range(N):
    A.append(int(input()))

q46(N, A)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input());
num_list=[];
for i in range(n):
    num_list.append(int(input()));
for j in range(n):
    m=num_list[j];
    num_list[j]=0;
    print(max(num_list));
    num_list[j]=m;

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(n):
  print(max_v if arr[i]!=max_v else max(arr[:i]+arr[i+1:]))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
for j in range(n):
    ma=0
    for h in range(n):
        if(h!=j):
            if(ma<a[h]):
                ma=a[h]
    print(str(ma))

Submission status: Time Limit Exceeded

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

a_max = [0 for i in range(n)]
a_max[0] = max(a[1:])
a_max[n-1] = max(a[:n])


for i in range(1,n-1):
    l_max = max(a[:i])
    r_max = max(a[i+1:])
    a_max[i] = max(l_max,r_max)

for i in a_max:
    print(i)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for i in range(N):
  print(np.max(np.delete(A,i)))

Submission status: Time Limit Exceeded

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

max_a = max(l)

for j in range(len(l)):
    if max_a == l[j]:
        tmp = l.pop(j)
        print(max(l))
        l.insert(j, tmp)
    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):
  B = A.copy()
  del B[i]
  print(max(B))

Submission status: Time Limit Exceeded

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

for j in range(len(l)):
    tmp = l.pop(j)
    print(max(l))
    l.insert(j, tmp)

Submission status: Time Limit Exceeded

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

a = max(A)
A_max = []
for i in range(N):
  if A[i] != a:
    A_max.append(a)
  else:
    A_ = A[:]
    A_[i] = 0
    A_max.append(max(A_))
    
for i in A_max:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = []

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for _ in range(0, n):
    a.append(int(input()))
b = max(a)
c = a.index(b)
a.pop(c)
e = a
d = max(e)
a.insert(c, b)
for i in range(0, n):
    if a[i] == max(a):
        print(d)
    else:
        print(b)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for _ in range(0, n):
    a.append(int(input()))
for i in range(0, n):
    if not a[i] == max(a):
        print(max(a))
    else:
        b = a.pop(i)
        print(max(a))
        a.insert(i, b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for _ in range(0, n):
    a.append(int(input()))
kore = []
for i in range(0, n):
    b = a.pop(i)
    kore.append(max(a))
    a.insert(i, b)
for i in kore:
    print(i)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
columns = [int(input()) for i in range(n)]
for order_element in range(0,len(columns)):
    copied=columns.copy()
    copied.pop(order_element)
    print(sorted(copied)[-1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
columns = [int(input()) for i in range(n)]
maximum_keeper=[]
for order_element in range(0,len(columns)):
    copied=columns.copy()
    copied.pop(order_element)
    print(max(copied))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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