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:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

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()))
    def d(A,i):
        k=A.pop(i)
        print(max(A))
        A.insert(i,k)
    for i in range(len(A)):
        d(A,i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(input()) for i in range(n)]
a = [0]
ma = 0
for i in range(len(l)):
    if l[i] > ma:
        ma = l[i]
    a.append(ma)
a.append(0)
b = [0]
ma = 0
for i in range(len(l)):
    if l[-i-1] > ma:
        ma = l[-i-1]
    b.insert(0,ma)
b.insert(0,0)
#print(a,b)
for i in range(n):
    print(max(a[i],b[i+2]))

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)


def max(mat):
    max = 0
    for i in range(len(mat)):
        if mat[i] > max:
            max = mat[i]

    return max

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):
    I = copy.deepcopy(A)
    del I[j]
    print(max(I))

Submission status: Time Limit Exceeded

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


for d in range(s):
  list_2=list
  x = list_2[0]
  list_2.remove(x)
  print(max(list_2))
  list_2.append(x)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = [int(input()) for _ in range(n)]
na = np.array(a)
for i in range(n):
    nb = np.copy(na)
    nb[i] = 0
    print(np.max(nb))

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = np.array(A)
for n in range(N):
    ind_rm = [n]
    ind = np.ones(N, dtype=bool)
    ind[ind_rm] = False
    print(max(A[ind]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

r = [max(a[0:i]+a[i+1:]) for i in range(n)]

for answer in r:
     print(answer)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

import copy

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

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

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)

max_a = max(a_lst)

for a in a_lst:
    if a == max_a:
        tmp = copy.copy(a_lst)
        tmp.remove(a)
        print(max(tmp))
    else:
        print(max_a)

Submission status: Time Limit Exceeded

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

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:
        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:
n=int(input())
a=[int(input()) for i in range(n)]
for i in a:
    l=a.copy()
    l.remove(i)
    print(max(l))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a_li=[]
for i in range(n):
    a=int(input()) 
    a_li.append(a)
for i in range(n):
    b=max(a_li)
    if b>a_li[i]:
        ans=b
    else:
        if a_li.count(b)>1:
            ans=b
        else:
            a_li.remove(b)
            ans=max(a_li)
            a_li.insert(i,b)
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

max_value=max(A)
for i in range(N):
    if A[i]<max_value:
        print(max_value)
    else:
        data=A.pop(i)
    #    print(lst,i)
        print(max(A))
        A.insert(i,data)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

#remove duplicate
sorted_a = sorted(a_list, reverse = True)
max_a = sorted_a[0]

result = []
for a in a_list:
    if a == max_a:
        print(max(sorted_a[1:]))
    else:
        print(max_a)

Submission status: Time Limit Exceeded

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

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

most_max = max(value_list)

for i in range(n):
    if value_list[i] == most_max:
        value_list[i] = 0
        print(max(value_list))
        value_list[i] = most_max
    else:
        print(most_max)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
A = [int(input()) for i in range(int(input()))]
for i in range(len(A)):
    print(max(A[:i]+A[i+1:]))

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[0:i] + A[i + 1:len(A)]
    print(max(tmp))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(int(input()))
    
p = max(s)
for i in s:
    if i != p:
        print(p)
    else:
        s.remove(p)
        print(max(s))
        s.insert(0,p)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = np.array(A)
for n in range(N):
    ind_rm = [n]
    ind = np.ones(N, dtype=bool)
    ind[ind_rm] = False
    A_tmp = [a for a in A if a not in ind_rm]
    print(max(A[ind]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

maxes = [max(alist[:i] + alist[i+1:]) for i in range(N)]
for m in maxes:
  print(m)

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())

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

max_a = max(A)

for i in range(N):
    max_l=0
    max_R=0
    if(A[:i]!=[]):
        max_l = max(A[:i])
    if(A[i+1:]!=[]):
        max_r = max(A[i+1:])
    print(max(max_r,max_l))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())

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

for i in range(N):
    tmp_list = copy.copy(a_list)
    tmp_list.pop(i)
    print(max(tmp_list))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
for i in range(N):
  if i==0:
    print(sorted(A[i+1:])[-1])
  if i!=0 and i!=N-1:
    li1=sorted(A[:i])[-1]
    li2=sorted(A[i+1:])[-1]
    print(max(li1,li2))
  if i==N-1:
    print(sorted(A[:i])[-1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
i = 0
A = []
while i < n:
	A.append(int(input()))
	i += 1
	
for i in range(len(A)):
	m = max(A)
	if A[i] == m:
		A1 = A.copy()
		del A1[i]
		print(max(A1))
	else:
		print(max(A))

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 = []
    for y in A:
        t.append(y)
    # print(t)
    t.remove(A[x])
    print(max(t))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
I=[int(input()) for i in range(N)]
for j in range(N):
	X=int(I[j])
	I.remove(I[j])
	print(max(I))
	I.insert(j,X)

Submission status: Time Limit Exceeded

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



"""
for i in range(n):
  if i == 0:
    print(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)
  """

Submission status: Time Limit Exceeded

Solution code:
import copy

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())

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

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

Submission status: Time Limit Exceeded

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        token = lines[0].split()
        n = int(token[0])
        for i in range(n):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        token = lines[0].split()
        n = int(token[0])

    a = []
    for i in range(1, n+1):
        a.append(int(lines[i]))

    return (n, a)


def solve(n, a):

    for i in range(n):
        b = a[:i]
        if b:
          x = max(b)
        else:
          x = -1
        y = a[i]
        c = a[i+1:]
        if c:
          z = max(c)
        else:
          z = -1
        print(max(x, z))



def main():
    # 出力

    solve(*parse_input())

if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

# solve & output
for i in range(N):
    tmp = copy.copy(A)
    del tmp[i]
    print(max(tmp))

Submission status: Time Limit Exceeded

Solution code:
import copy
s=[]
i=0
n=int(input())
while i!=n:
    s.append(int(input()))
    i+=1
maxx=max(s)
g=s.count(maxx)
i=0

#print(g)
while i!=n:

    a=s[0]
    del s[0]
    if maxx==a and g<2:
        print(max(s))
    else:
        print(maxx)


    s.append(a)
    i+=1

Submission status: Time Limit Exceeded

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

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

n = readi()
d = []
for i in range(n):
    k = readi()
    d.append(k)
d = deque(d)
for i in range(n):
    print(max(list(d)[1:n]))
    d.rotate(-1)

Submission status: Time Limit Exceeded

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

normal = max(A)
maxindex = [i for i, x in enumerate(A) if x == max(A)]
A.remove(normal)
exception = max(A)

for i in range(N):
    if i in maxindex:
        print(exception)
    else:
        print(normal)

Submission status: Time Limit Exceeded

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

max_indexs =  [i for i, x in enumerate(li) if x == max(li)]
li.sort()
max_val = li[-1]

if len(max_indexs) == 1:
    for i in range(N):
        if i == max_indexs[0]:
            print(li[-2])
        else:
            print(max_val)
else:
    for i in range(N):
        print(max_val)

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 = [0] * n
  for j in range(n):
    if j == i:
      continue
    else:
      b[j] = a[j]
  print(max(b))

Submission status: Time Limit Exceeded

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


for i in range(N):
    lst2 = lst[:]
    lst2.pop(i)
    print(max(lst2))

Submission status: Time Limit Exceeded

Solution code:
import copy

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

a = []
for i in range(N):
    a.append(int(input()))
print(max(a[1:]))
for i in range(1,N-1):
    a_max = max(a[:i])
    n_a_max = max(a[i+1:])
    if(a_max>=n_a_max):
        print(a_max)
    else:
        print(n_a_max)
print(max(a[:N-1]))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=[]
for i in range(0,n):
    A.extend([int(input())])
for j in range(0,n):
    s=A[j]
    A.pop(j)
    print(max(A))
    A.insert(j,s)

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.copy()
    tmp.pop(i)
    print(max(tmp))

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
n = INT()

ans = 0
# a = [INT() for i in range(n)]
a = []
for i in range(n):
    a.append(INT())
l = []
# print(a)

for i in range(n):
    l = []
    for j in range(n):
        if i != j:
            l.append(a[j])
    print(max(l))
        # print(l)
        # print(max(l))

    # print(a[0:i], a[i:n])
    # print(ans)
#

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, *al = nf()
    for i in range(n):
        ma = 1
        for j, a in enumerate(al):
            if j == i:
                continue
            ma = max(ma, a)
        print(ma)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Max=max(a)
for i in range(n):
    b=a[:]
    if(b[i]==Max):
        del b[i]
        print(max(b))
    else:
        print(Max)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
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 copy

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

jumpIndex = -1

for i in range(N):
    if i == jumpIndex - 1:
        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:
#C
import copy
n = int(input())
a = [int(input()) for _ in range(n)]
for i in range(n):
    tmp = copy.copy(a)
    tmp.pop(i)
    tmp.sort()
    print(tmp[-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

li2 = sorted(li,reverse=True)

for i in range(N):
    ans = max(li)
    if(ans == li[i]):
        print(li2[1])
    else:
        print(ans)

Submission status: Time Limit Exceeded

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

for j in range(n):
    a = list.pop(j)
    print(max(list))
    list.insert(j,a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
for i in range(n):
    tmp = a[:]
    tmp.pop(i)
    tmp.sort()
    print(tmp[-1])

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

Submission status: Time Limit Exceeded

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

    print(max(A[1:]))

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

    print(max(A[:N]))

    return


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())

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

for i in range(N):
  numbers_minus1 = numbers_full.copy()
  del numbers_minus1[i]
  #print(numbers_full, numbers_minus1, str(max(numbers_minus1)))
  print(str(max(numbers_minus1)))

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[i]
    a.pop(i)
    print(max(a))
    a.insert(i,b)

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    x = r_list.pop(i)
    print(max(r_list))
    r_list.insert(i, x)

Submission status: Time Limit Exceeded

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

resultCash = {}

for i in range(N) :
    if AList[i] not in resultCash :
        resultCash[AList[i]] = max(AList[0:i] + AList[i+1:N])
    print(resultCash[AList[i]])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for i in range(N):
        A.append(int(input()))
m = max(A)
for i in range(N):
        if A[i] == m:
                A.remove(m)
                print(max(A))
                A.insert(i,m)
        else:
                print(m)

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
    else:
        out_list.append(a_max)
        
print("\n".join(map(str, out_list)))

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

m = max(A)

print(max(A[1:]))

for i in range(1, n-1):
    if A[i] < m:
        print(m)
    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())
A_LIST = []

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

for i in range(N):
    temp = A_LIST[i]
    A_LIST[i] = 0
    print(max(A_LIST))
    A_LIST[i] = temp

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())
numbers = []
for i in range(N):
    numbers.append(int(input()))
    
for n in numbers:
    numbers_2 = copy.deepcopy(numbers)
    c = copy.deepcopy(n)
    numbers_2.remove(c)
    print(max(numbers_2))

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):
        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:
import copy
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
for j in range(N):
    B=copy.copy(A)
    C=B.pop(j)
    print(max(B))

Submission status: Time Limit Exceeded

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



"""
for i in range(n):
  if i == 0:
    print(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)
  """

Submission status: Time Limit Exceeded

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

j = 0

for j in range(n):
    temp_list = copy.deepcopy(string_list)
    temp_list.pop(j)
    j += 1
    print(max(temp_list))

Submission status: Time Limit Exceeded

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

maxA = max(A)
for n in range(N):
  if A[n] != maxA:
    print(maxA)
  else:
    a = A[n]
    A[n] = 0
    print(max(A))
    A[n] = a

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

ret = []
for i in range(n):
    item = a.pop(0)
    print(max(set(a)))
    a.append(item)

Submission status: Time Limit Exceeded

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

for i in range(len(nums)):
  pop = nums_del.pop(i)
  print(max(nums_del))
  nums_del.insert(i,pop)

Submission status: Time Limit Exceeded

Solution code:
N=input()
N=int(N)
A=[]
for i in range(N):
    b=input()
    b=int(b)
    A.append(b)
for i in range(N):
#    A=a
#    print(A)
    data=A.pop(i)

#    print(lst,i)
    print(max(A))
    A.insert(i,data)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = []
for _ in range(N):
  D.append(int(input()))
 
for i in range(len(D)):
    TD = D.copy()
    del(TD[i])
    print(max(TD))

Submission status: Time Limit Exceeded

Solution code:
#n=list(map(int,input().split()))
n = int(input()) #1行目のNを取得する
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())
a_lst = []
for i in range(n):
    a = int(input())
    a_lst.append(a)

max_a = max(a_lst)
max_a_id_lst = [i for i, elem in enumerate(a_lst) if elem == max_a]

for i in range(n):
    if i in max_a_id_lst:
        if len(max_a_id_lst) == 1:
            a_lst.remove(max_a)
            print(max(a_lst))
        else:
            print(max_a)
    else:
        print(max_a)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
arr = []
for i in range(n):
    a = int(input())
    arr.append(a)
for i in range(n):
    brr = copy.copy(arr)
    brr.pop(i)
    print(max(brr))

Submission status: Time Limit Exceeded

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

for i in range(N):
    for j in range(N):
        if i != j:    
            if max[i] < A[j]:
                max[i] = A[j]

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

Submission status: Time Limit Exceeded

Solution code:
import copy
s=[]
i=0
n=int(input())
while i!=n:
    s.append(int(input()))
    i+=1
maxx=max(s)
i=0
#print(s)
while i!=n:

    a=s[0]
    del s[0]
    if maxx==a:
        print(max(s))
        maxx=max(s)
    else:
        print(maxx)


    s.append(a)
    i+=1

Submission status: Time Limit Exceeded

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

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

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

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):
  x=ls[0]
  ls.pop(0)
  print(max(ls))
  ls.append(x)

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):
  m = A.max()
  if A[i] == m:
    print(np.delete(A, i).max())
  else:
    print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
sum_a = sum(a)
for i in range(n):
    tmp = a[i]
    a[i] = 0
    print(max(a))
    a[i] = tmp

Submission status: Time Limit Exceeded

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