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

first_max = 0
latter_max = max(a[1:])

for i in range(0, N - 1):
  if i > 0:
    first_max = max(first_max, a[i-1])
  if latter_max == a[i]:
    latter_max = max(a[i+1:])
  print(max(first_max, latter_max))

print(max(a[:-1]))

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
input = sys.stdin.readline


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

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

    for i in range(len(A)):
        tmp = A[i]
        A[i] = 0
        print(max(A))
        A[i] = tmp

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

readline = stdin.readline


def nf():
    """
    入力全て(EOFまで)を`int iter`に変換
    """
    return map(int, open(0).read().split())


def main():
    n, *l = nf()
    al = list(l)
    for i in range(n):
        ma = 0
        if i > 0:
            ma = max(al[:i])
        if i < n-1:
            ma = max(max(al[i+1:]), ma)
        print(ma)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
A=[]
B=[]
for i in range(0,n):
    A.extend([int(input())])
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:
# -*- 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=[]
for i in range(N):
  A.append(int(input()))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
A_sub = A.copy()
A_sub.sort(reverse=True)
#print(A)

for i in range(N):
    # print(A[i])
    A_sub2 = A_sub.copy()
    A_sub2.remove(A[i])
    print(A_sub2[0])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [input() for i in range(N)]
ans = 0
for i in range(N):
    wk = A[:]
    wk.pop(i)
    wk.sort()
    ans = wk[-1]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
m_num = max(a)
m_index = [i for i, x in enumerate(a) if x == m_num]

for i in range(n):
  if i in m_index:
    b = a[i]
    del a[i]
    print(max(a))
    a.insert(i, b)
  else:
    print(m_num)

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
B = sorted(A,reverse=True)
for a in A:
    C = copy.copy(B)
    C.remove(a)
    print(C[0])

Submission status: Time Limit Exceeded

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

B = A.copy()
for j in range(N):
  if max(A) == A[j]:
    del A[j]
    print(max(A))
    A = B.copy()
  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):
    left = [A[j] for j in range(0, i)]
    right = [A[j] for j in range(1+i, N)]
    print(max(right + left))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
semi_max = 0
aa = []
for i in range(n):
    a = int(input())
    if i > 0:
        if a >= semi_max and a < max(aa):
            semi_max = a
        elif a == max(aa):
            semi_max = max(aa)
    aa.append(a)
    # print(semi_max)
for each in aa:
    print(max(aa) if each <= semi_max else semi_max)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = []
for i in range(n):
    li.append(int(input()))
m = max(li)
li2 = li.copy()
li2.remove(max(li2))
d = max(li2)
for i in range(n):
    if li[i] == max(li):
        print(d)
    else:
        print(m)

Submission status: Time Limit Exceeded

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

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

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)))
for i in range(max_index):
        print(a_max)
print(a_second)
for i in range(max_index+1,N):
        print(a_max)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list()
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)

Submission status: Time Limit Exceeded

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

for i in range(len(A)):
  a = copy.deepcopy(A)
  a.pop(i)
  print(sorted(a)[-1])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
for i in range(n):
    m=0
    for j in range(n):
        if j!=i and a[j]>=m:
            m=a[j]
    print(m)

Submission status: Time Limit Exceeded

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

set_A = set(A)
count_A = A.count(max(A))
for a in A:
    if a == max(A) and count_A == 1:
        print(sorted(set(set_A))[-2])
    else:
        print(max(A))

Submission status: Time Limit Exceeded

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

maxnum = max(a)

for i in range(n):
  tmp = a.pop(i)
  if tmp == maxnum:
    print(max(a))
  else:
    print(maxnum)
  a.insert(i, tmp)

Submission status: Time Limit Exceeded

Solution code:
import copy
import numpy as np

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

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

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

Submission status: Time Limit Exceeded

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

n = int(input())

a = []

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

a_max = max(a)

for i in range(0,n):
    if a[i] == a_max:
        a1 = a[:i]
        a2 = a[i+1:]

        if len(a1) == 0:
                print(max(a2))
        elif len(a2) == 0:
            print(max(a1)) 
        else:
            print(max(max(a1), max(a2)))
    else:
        print(a_max)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=[int(input()) for i in range(N)]
index1=L.index(max(L))
index2=L.index(sorted(L)[-2])
for i in range(N-1):
	if i==index1:
		print(sorted(L)[-2])
	print(max(L))

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)

B = []
for i in range(N):
    B = A[:]
    bi = B.pop(i)
    if bi == amax and amaxcnt == 1:
        B.sort()
        print(B.pop())
    else:
        print(amax)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
nums = [int(input()) for _ in range(N)]
for i in range(len(nums)):
  nums_del = copy.deepcopy(nums)
  del nums_del[i]
  print(max(nums_del))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(0,int(n)):
  if ( sorted(A)[-1] == A[i]):
  	print (sorted(A)[-2])
  else:
    print(sorted(A)[-1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums = []
for i in range(n):
    a = int(input())
    nums.append(a)
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 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:
        copy = a[:]
        copy.pop(i)
        print(max(copy))
    else:
        print(a_max)

Submission status: Time Limit Exceeded

Solution code:
N=int(input()) 
a=[int(input()) for i in range(N)]
b=sorted(a)
n=0
while True:
    if n==a.index(max(a)):
        print(b[-2])
    else:
        print(b[-1])
    n+=1
    if n==N:
        break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
m = 0
for i in range(N):
    m = int(input())
    A.append(m)
    #A[i] = int(A[i])
task = 0
m = 0
for i in range(N):
    task = A.pop(i)
    m = max(A)
    print(m)
    A.insert(i,task)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

numbers_minus1 = numbers_full
for i, tmp in enumerate(numbers_full):
  numbers_minus1[i] = 0
  print(str(max(numbers_minus1)))
  numbers_minus1[i] = tmp

Submission status: Time Limit Exceeded

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

A_length = len(A)

a = [A.pop(0)]
print(max(A))

for i in range(A_length-2):
    temp = A.pop(i)
    print(max(max(a), max(A)))
    a.append(temp)

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):
        sorted_a = a[0:i]+a[i+1:n]
        sorted_a.sort()
        print(sorted_a[n-2])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


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

    for j in range(N):
        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())
a = [int(input()) for i in range(n)]
for i in range(len(a)):
    b = a.copy()
    del b[i]
    print(max(b))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
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(max(L), max(R)))
  L.append(i)

Submission status: Time Limit Exceeded

Solution code:
import copy,numpy
n=int(input())
A=[int(input()) for _ in range(n)]
for i,_ in enumerate(A):
    B=copy.copy(A)
    del B[i]
    print(numpy.max(B))

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

for i in range(N):
    tmp = que.popleft()
    print(max(que))
    que.append(tmp)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(len(A)):
  a = copy.deepcopy(A)
  a.pop(i)
  print(max(a))

Submission status: Time Limit Exceeded

Solution code:
import copy
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))
    else:
        J = copy.deepcopy(A)
        del J[j]
        print(max(J))

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)))
for i in range(N):
    if i==max_index:
        print(a_second)
    else:
        print(a_max)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
LA = [int(input()) for i in range(n)]
LB = []
LB.extend(LA)
for i in range(n):
    del LB[i]
    print(max(LB))
    LB = []
    LB.extend(LA)

Submission status: Time Limit Exceeded

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

maxleft = [0] * (N+2)
maxright = [0] * (N+2)

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

for i in range(N):
    print(max(maxleft[i], maxright[2+i]))

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())

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

B = copy.copy(A)

for i in range(len(A)):
    A[i] = 0
    print(max(A))
    A[i] = B[i]

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

numbers_minus1 = numbers_full
for i, tmp in enumerate(numbers_full):
  numbers_minus1[i] = 0
  print(str(max(numbers_minus1)))
  numbers_minus1[i] = tmp

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

arr = []
max_num = 0
label = 1
for i in range(n):
    inp = int(input())
    if inp >= max_num:
       max_num = inp
       label = i
    arr.append(inp)


arr_sub = arr[:]
arr_sub.pop(label)
#print(arr)
#print(max(arr))
#print(max(arr_sub))



for i in range(n):
    if i != label:
        print(max(arr))
    else:
        print(max(arr_sub))

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

i=1
while i<=b:
    for x in a:
        c.append(x)
    c[i-1]=0
    c.sort()
    print(c[-1])
    i+=1
    c=[]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, *d = map(int, open(0).read().split())
allmax = 0
for i in range(N):
    if d[i] > allmax:
        allmax = d[i]
for i in range(N):
    max = 0
    for j in range(N):
        if(i == j):
            continue
        if d[j] > max:
            max = d[j]
            if max == allmax:
                break
    print(max)

Submission status: Time Limit Exceeded

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

sa = sorted(a)
for i in range(n):
    val = a[i]
    idx = sa.index(val)
    sa.pop(idx)
    print(sa[-1])
    sa.insert(idx, val)

Submission status: Time Limit Exceeded

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

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

for j in range(n):
  buf = li.pop(j)
  print(max(li))
  li.insert(j,buf)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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:
        print(left_max)
    else:
        print(right_max)
    
    if left_max < A:
        left_max = A

Submission status: Time Limit Exceeded

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

n = int(input())

a = []

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

for i in range(0,n):
    a1 = a[:i]
    a2 = a[i+1:]
    
    if len(a1) == 0:
        print(max(a2))
    elif len(a2) == 0:
        print(max(a1))
    else:
        print(max(max(a1), max(a2)))

Submission status: Time Limit Exceeded

Solution code:
import copy

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

sorted_a_lst = sorted(a_lst)
max_a = sorted_a_lst[-1]

for a in a_lst:
    if a == max_a:
        tmp = copy.copy(a_lst)
        tmp.remove(a)
        tmp = sorted(tmp)
        print(tmp[-1])
    else:
        print(max_a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = {}
#b = []
mx = -10000
#mx1 = -10000
for i in range(n):
    num = int(input())
    if num in a.keys():
        a[num] += 1
    else:
        a[num] = 1
    if mx < num:
        mx = num
        m = i

k = max(a.keys())
if len(a) > 1:

    b = list(a.keys())
    b.sort()
    t = max(b[:len(b)-1])

if a[k] > 1:
    for i in range(n):
        print(k)
else:
    for i in range(n):
        if i == m:
            print(t)
        else:
            print(k)

Submission status: Time Limit Exceeded

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

import copy

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

Amax = max(A)

for i in range(N):
        if A[i] == Amax:
                TMP = copy.deepcopy(A)
                TMP.pop(i)
                print(max(TMP))
        else:
                print(Amax)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

for i in range(N):
  print(max([elem for idx,elem in enumerate(A) if idx != i]))

Submission status: Time Limit Exceeded

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

from copy import deepcopy

for i in range(n):
	y=deepcopy(x)
	del y[i]
	print(max(y))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

#n, d = map(int, input().split())
n= int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

for i in range(N):
  numbers_minus1 = numbers_full
  tmp = numbers_minus1[i]
  numbers_minus1[i] = 0
  print(str(max(numbers_minus1)))
  numbers_minus1[i] = tmp

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
s = [input() for i in range(N)]
mar = s
for i in range(N):
    mar = s[:]
    mar.pop(i)
    print(max(mar))

Submission status: Time Limit Exceeded

Solution code:
import copy,numpy
n=int(input())
A=[int(input()) for _ in range(n)]
for i in range(len(A)):
    B=copy.copy(A)
    del B[i]
    print(numpy.max(B))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
data = [int(input()) for k in range(n)]
for t in range(n):
	data2 = [data[i] for i in range(n) if i != t]
	data2.sort(reverse=True)
	print(data2[0])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = [int(input()) for i in range(0, n)]
l = []

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    for j in range(N):
        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())
I=[int(input()) for i in range(N)]
r=max(I)
for j in range(N):
	X=int(I[j])
	if X!=r:
		print(r)
	else:
		I.remove(I[j])
		print(max(I))
		I.insert(j,X)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
A_m = max(A)
if A.count(max) >= 2:
    for i in range(N):
        print(A_m)
else:
    for i in range(N):
        if A[i] == A_m:
            del A[i]
            A_m_new = max(A)
            print(A_m_new)
            A.append(0)
        else:
            print(A_m)

Submission status: Time Limit Exceeded

Solution code:
from array import array
n = int(input())
a_list = [int(input()) for _ in range(n)]
max_num = max(array('L',a_list))
for i in range(len(a_list)):
    if a_list[i] != max_num:
        print(max_num)
    else:
        print(max(array('L',a_list[:i]+a_list[i+1:])))

Submission status: Time Limit Exceeded

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

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.remove(j)
    print(max(lst))
    lst.insert(i, j)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt

def solve(N, A):
    D = int(sqrt(N))
    M = []
    for i in range(0, N, D):
        M.append(max(A[i:i+D]))
    M.append(0)
    for i in range(0, N):
        d = i // D
        l = d*D
        m = 0
        for j in range(l, min(l+D, N)):
            if i != j and A[j] > m:
                m = A[j]
        m0 = m
        if d == 0:
            m = max(m, max(M[d+1:]))
        elif d >= len(M) - 1:
            m = max(m, max(M[:d]))
            pass
        else:
            #print(d, len(M))
            #print("M[:d]", M[:d])
            #print("M[d+1:]", M[d+1:])
            m = max(m, max(M[:d]), max(M[d+1:]))
        print(m)
        #print("d=%d,"%d, m, max(A[:i]+A[i+1:]))
        #assert m == max(A[:i]+A[i+1:])


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    solve(N, A)

#l = list(range(1, 200))
#solve(len(l), l)
main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

#print(N)
#print(A)

for i in range(N):
    remA=A.pop(i)
    print(max(A))
    A.insert(i, remA)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

B = []
for i in range(N):
    B = A[:]
    bi = B.pop(i)
    if bi == amax:
        B.sort()
        print(B.pop())
    else:
        print(amax)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(int(input()) for i in range(n))
b=[0]
c=[0]
for i in range(n):
    b.append(max(a[:i+1]))
    c.append(max(a[n-i-1:]))
del b[n]
del c[n]

for i in range(n):
    d=b[i]
    e=c[n-1-i]
    print(max(d,e))

Submission status: Time Limit Exceeded

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

list2 = []
for i in range(n):
    list2 = list.copy()
    del(list2[i])
    print(sorted(list2)[-1])

Submission status: Time Limit Exceeded

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

n = int(input())

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

a_sorted = sorted(a, reverse=True)

for i in range(n):
    index = a_sorted.index(a[i])
    if index == 0:
        print(a_sorted[index + 1])
        continue

    print(a_sorted[0])

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
all_list = [int(input()) for _ in range(n)]
for i in range(n):
    tmp = copy.copy(all_list)
    tmp.pop(i)
    print(max(tmp))

Submission status: Time Limit Exceeded

Solution code:
import copy

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

jumpIndex = -1

for i in range(N):
    if i < jumpIndex:
        A.remove(A[i])
        print(tmpMax)
        continue
    tmp = copy.copy(A)
    tmp.remove(A[i])
    tmpMax = max(tmp)
    for j in range(i + 1, N):
        if A[i] == tmpMax:
            jumpIndex = i
    print(tmpMax)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
nplst=np.array([])
for i in range(n):
  a=int(input())
  nplst=np.append(nplst,a)
np2=np.zeros(n).reshape(n,1)
np3=nplst+np2
np3=np3-np.diag(nplst)
for i in range(n):
  print(int(np.max(np3[i])))

Submission status: Time Limit Exceeded

Solution code:
import copy

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

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

is_max = False
#print(a_list)    
for i in range(n):
    if not is_max:
        a_copy = copy.copy(a_list)
        a_copy.pop(i)
        #print(a_copy)
        a_max = max(a_copy)
        #print(a_max)
        out_list.append(a_max)
        if a_list[i] == a_max:
            is_max = True
            out_list += [a_max for i in range(n-i-1)]
#print(out_list)        
print("\n".join(map(str, out_list)))

Submission status: Time Limit Exceeded

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

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

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