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 = [int(input()) for i in range(n)]
b = [-1]*n
for i in range(n):
    b[i] = max(a[:i]+a[i+1:])
for key in b:
    print(key)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for _ 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())
a = []
for i in range(n):
  a.append(int(input()))
m = max(a)
for j in a:
  if j < m:
    print(m)
  elif j == m:
    b = sorted(a.copy())
    print(b[n-2])

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):
  b = a.copy()
  aj = a[j]
  b.remove(a[j])
  print(max(b))

Submission status: Time Limit Exceeded

Solution code:

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

b = []

for i in range(n):
    tmp = a[i]
    del a[i]
    b.append(max(a))
    a.insert(i,tmp)

for i in range(len(b)):
    print(b[i])

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 = A[i]
    A[i] = -1
    print(sorted(A,reverse=True)[0])
    A[i] = tmp

Submission status: Time Limit Exceeded

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

for i in range(N):
    tmp = A[i]
    A[i] = -1
    print(max(A))
    A[i] = tmp

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
# 列ベクトルとかの受け取り
lists = [int(input()) for _ in range(n)]
ans = []
for i in range(n):
    ans.append(max(lists[:i] + lists[i+1:]))

print(*ans,sep="\n")   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する

Submission status: Time Limit Exceeded

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

    for i in range(N):
        if A[i]<max(A):
            temp[i]=max(A)
        elif A.count(max(A))!=1:
            temp[i]=max(A)
        else:
            temp[i]=max(A[:i]+A[i+1:])
    for i in temp:
        print(i)



resolve()

Submission status: Time Limit Exceeded

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

def resolve():
    N=int(input())
    A=[int(input()) for i in range(N)]
    temp=[0]*N

    for i in range(N):
        if A[i]<max(A):
            temp[i]=max(A)
        elif A.count(max(A))!=1:
            temp[i]=max(A)
        else:
            temp[i]=max(A[:i]+A[i+1:])
    for i in temp:
        print(i)



resolve()

Submission status: Time Limit Exceeded

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

for _ in range(n):
    _list.append(int(input()))

for i in range(n):
    if i==0:
        tmp_list = _list[1:]
        tmp_max = max(tmp_list)
        print(tmp_max)
        
        if _list[0] < tmp_max:
            maxi = tmp_max
        else:
            maxi = _list[0]

    elif 0<i<n-1:
        if _list[i] < maxi:
            print(maxi)
        else:
            tmp_list = _list[:i] + _list[i+1:]
            print(max(tmp_list))

    else:
        if _list[i] < maxi:
            print(maxi)
        else:
            tmp_list = _list[:n-1]
            print(max(tmp_list))

Submission status: Time Limit Exceeded

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

for _ in range(n):
    _list.append(int(input()))

maxi = 0
for i in range(n):
    if i==0:
        tmp_list = _list[1:]
    elif 0<i<n-1:
        tmp_list = _list[:i] + _list[i+1:]
    else:
        tmp_list = _list[:n-1]

    tmp_max = max(tmp_list)
    print(tmp_max)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())
    A = [int(sys.stdin.readline().rstrip()) for _ in range(N)]

    for n in range(N):
        l = len(A)
        a = A[0:n] if len(A[0:n]) > 0 else [0]
        b = A[n + 1:l] if len(A[n + 1: l]) else [0]
        print(max(max(a), max(b)))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import os
import copy


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())
    A = [int(sys.stdin.readline().rstrip()) for _ in range(N)]

    for n in range(N):
        ary = copy.copy(A)
        ary.pop(n)
        print(max(ary))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(input()) for _ in range(N)]
for i in range(N):
    front = a[:i]
    back = a[i + 1:]
    f_max = max(front) if front else 0
    b_max = max(back) if back else 0
    print(max(f_max, b_max))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0] * N
m = 0
for i in range(N):
    A[i] = int(input())
    if A[i] > m:
        m = A[i]
for i in range(N):
    if A[i] != m:
        print(m)
    else:
        A[i] = 0
        print(max(A))
        A[i] = m

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

list_ans = list_score.copy()
list_ans.sort()
heapq.heapify(list_ans)

for i in range(n):
    a = list_score[i]
    list_ans.remove(a)
    print(list_ans[-1])
    heapq.heappush(list_ans, a)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():
	n = int(input())
	# n,m = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	l = [str(input()) for i in range(n)]
	#R行C列
	# a = [list(map(int,input().split())) for x in range(m)]
	# print(' '.join(map(str,)))
	ans = []

	# i = 0
	print(max(l[1:n]))

	# 0 < i < n
	for i in range(1,n):
		# print("i is {}".format(i))
		ans = l[0:i] + l[i+1:n]
		# print(ans)
		print(max(ans))


if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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

for a in A:
    if a==max(A):
        print(B[-2])
    else:
        print(B[-1])

Submission status: Time Limit Exceeded

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


k=sorted(l)
dic_lst={}
for i in l:
  if i not in dic_lst:
    dic_lst[i]=1
  else:
    dic_lst[i]+=1
for i in l:
  max_num=max(dic_lst.keys())
  if i<max_num:
    print(max_num)
  if i==max_num:
    if dic_lst[i]>1:
      print(max_num)
    elif dic_lst[i]==1:
      print(k[-2])

Submission status: Time Limit Exceeded

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

k=copy.copy(l)
k.sort()
dic_lst={}
for i in l:
  if i not in dic_lst:
    dic_lst[i]=1
  else:
    dic_lst[i]+=1
for i in l:
  max_num=max(dic_lst.keys())
  if i<max_num:
    print(max_num)
  if i==max_num:
    if dic_lst[i]>1:
      print(max_num)
    elif dic_lst[i]==1:
      print(k[-2])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for x in range(N)]
As = sorted(A)

for i in range(N):
    As.remove(A[i])
    print(As[-1])
    As.insert(i, A[i])

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(stdin.readline().rstrip()) for _ in range(n)]

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

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):
    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 _ in range(n)]

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

Submission status: Time Limit Exceeded

Solution code:
def main(n: int, a: list):
    for i in range(n):
        t = a.copy()
        t[i] = 0

        print(max(t))


if __name__ == "__main__":
    n = int(input())
    a = [int(input()) for _ in range(n)]

    main(n, a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from copy import copy


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    for i in range(N):
        tmp = copy(A)
        tmp[i] = 0
        print(max(tmp))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=[]
for i in range(n):
    a=int(input())
    A.append(a)
M=max(A)
for i in range(n):
    if A[i]!=M:
        print(M)
    else:
        b=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):
    a=int(input())
    A.append(a)
for i in range(n):
    b=A.pop(i)
    print(max(A))
    A.insert(i,b)

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

Submission status: Time Limit Exceeded

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

import copy

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

Submission status: Time Limit Exceeded

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

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

B = A.copy()

heapq.heapify(B)
max_1 = 0 - heapq.heappop(B)
max_2 = 0 - heapq.heappop(B)

if max_1 == max_2:
    for _ in range(N):
        print(max_1)
        
else:
    for i in range(N):
        if i == A.index(-max_1):
            print(max_2)
        else:
            print(max_1)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    s = sorted(list(set(A)))

    for a in A:
        if len(s) == 1:
            print(s[-1])
        elif a == s[-1] and A.count(a) == 1:
            print(s[-2])
        else:
            print(s[-1])


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
lst = []
for _ in range(n):
    lst.append(int(input()))
clean_lst = copy.deepcopy(lst)

for i in clean_lst:
    lst.remove(i)
    print(max(lst))
    lst.append(i)

Submission status: Time Limit Exceeded

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

for _ in range(n):
    val = a.pop(0)
    print(max(a))
    a.append(val)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy
N=int(input())
A=[int(input()) for _ in range(N)]
l=[]
for i in range(N):
    Ad = copy.deepcopy(A)
    del Ad[i]
    Ad.sort(reverse=True)
    print(Ad[0])

Submission status: Time Limit Exceeded

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

for i in range(N):
  if A[i] != M:
    print(M)
  else:
    a = A[:i] + A[i+1:]
    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())

x = sorted(set(a), reverse = True)
t = [0]*2
if len(x) > 1:
  t[0],t[1] = x[0],x[1]
else:
  t[0],t[1] = x[0],x[0]
  
max = t[0]  
for i in range(n):
  if a[i] == max:
    if a.count(max) > 1:
      print(max)
    else:
      print(t[1])
  else:
    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):
  t = a[i]
  a[i] = 0
  print(max(a))
  a[i] = t

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
ans = max(A)
for i in range(N):
  if A[i] == ans:
    a = A[:i] + A[i+1:]
    print(max(a))
  else:
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list()
for i in range(N):
  A.append(int(input()))
ma = max(A)
for i in range(N):
  if ma != A[i]:
    print(ma)
  else:
    X = A[i]
    A[i] = 0
    print(max(A))
    A[i] = X

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for _ in range(N):
  A += [int(input())]
for i in range(N):
  print(max([A[j] for j in range(N) if j != i]))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = []
A_count_list = []
for i in range(N):
    A = int(input())
    A_count_list.append(A)
    for j in range(len(A_list)):
        if A_list[j] < A:
            A_list.insert(j, A)
            A = 0
    if A != 0:
        A_list.append(A)
max_index = A_count_list.index(max(A_count_list))
for i in range(N):
    if i == max_index:
        print(A_list[1])
    else:
        print(A_list[0])

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

input = sys.stdin.readline
n = int(input())
s = list(int(input()) for _ in range(n))
i = 0
maxn = 0
s2 = []
for i in range(n):
    s2 = s.copy()
    del s2[i]
    print(np.max(np.array(s2)))
    i += 1

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

input = sys.stdin.readline
n = int(input())
s = list(int(input()) for _ in range(n))
i = 0
maxn = 0
s2 = []
while i < n:
    s2 = s.copy()
    del s2[i]
    print(np.max(np.array(s2)))
    i += 1

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(int(input()) for _ in range(n))
i = 0
s2 = []
while i < n:
    s2 = s.copy()
    s2.pop(i)
    print(max(s2))
    i += 1

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for _ 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())
array = []

for x in range(N):
  array.append(int(input()))
for x in range(N):
  print(max(array[:x]+array[x+1:]))

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = sys.stdin.readline

def main():
    n = int(input())
    As = [int(input()) for i in range(n)]
    mn = max(As)
    for i in range(n):
        if As[i] == mn:
            print(max(As[:i] + As[i+1:]))
        else:
            print(mn)
    return 

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = sys.stdin.readline

def main():
    n = int(input())
    As = [int(input()) for i in range(n)]

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

    return

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import heapq

num = int(input())
nums = [int(input()) for _ in range(num)]

for n in nums:
  maxs = heapq.nlargest(2, nums)
  if maxs[0] > n:
    print(maxs[0])
  else:
    print(maxs[1])

Submission status: Time Limit Exceeded

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

for i in range(len(nums)):
  n = nums[i]
  del nums[i]
  print(max(nums))
  nums.insert(i, n)

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:
import numpy as np

n = int(input())
a = [int(input()) for _ in range(n)]
sort_a = list(np.sort(a))
sort_arg = np.argsort(a)
for i in range(n):
    tmp_l = sort_a[:]
    tmp_l.pop(sort_arg[i])
    print(tmp_l.pop(-1))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = [int(input()) for _ in range(n)]
sort_a = list(np.sort(a))
#sort_arg = np.argsort(a)
for i in range(n):
    tmp_l = sort_a[:]
    tmp_l.remove(a[i])
    print(tmp_l.pop(-1))

Submission status: Time Limit Exceeded

Solution code:
#abc134 c
n=int(input())
a=[]
for i in range(n):
    x=int(input())
    a.append(x)
for i in range(n):
    max_a=0
    for j in range(n):
        if i==j:
            continue
        if max_a<=a[j]:
            max_a=a[j]
    print(max_a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(input()) for i in range(n)]
B = A[:]
for i in range(n):
    a = B[i]
    B[i] = 0
    print(max(B))
    B[i] = 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[:]
    B.pop(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(A[:i]+A[i+1:]))

Submission status: Time Limit Exceeded

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

def delete(n):
  B=copy.deepcopy(A)
  del B[n]
  return(max(B))

for i in range(N):
  print(delete(i))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
max1 = 0
max2 = -1
for i in range(N):
  a = int(input())
  A.append(a)
for i in range(N):
  a = A.pop(i)
  print(sorted(A)[-1])
  A.insert(i, a)

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:
A = int(input())
r = []
for i in range(A):
    r.append(int(input()))
max_r = max(r)
for i in range(A):
    if max_r == r[i]:
        r.pop(i)
        print(max(r))
        r.insert(i,max_r)
    else:
        print(max_r)

Submission status: Time Limit Exceeded

Solution code:
#

n=int(input())
l = [int(input()) for _ in [0] * n]
x = 0
for i in range(n):
    y = l[:]
    y.pop(i)
    print(max(y))

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:
N = int(input())
li = []
for i in range(N):
  s = int(input())
  li.append(s)
  
  new = sorted(li, reverse=True)

s = max(li)
for index, i in enumerate(li):
  if s == li[index]:
    print(new[1])
  else:
    print(new[0])

Submission status: Time Limit Exceeded

Solution code:
import copy

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

for index, i in enumerate(li):
  tmp = copy.copy(li)

  ans = max(tmp)

  if ans == tmp[index]:
    tmp.pop(index)
    print(max(tmp))
  else:
    print(ans)

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,*a=map(int,open(0).read().split())
for i in range(n):
  b=a[:]
  b.pop(i)
  print(max(b))

Submission status: Time Limit Exceeded

Solution code:
import copy

def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]
    
    for i in range(n):
        tmp = copy.deepcopy(num_list)
        tmp.pop(i)
        print(max(set(tmp)))
        
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy

def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]
    
    for i in range(n):
        tmp = copy.deepcopy(num_list)
        tmp.pop(i)
        print(max(tmp))
        
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list()
for i in range (n):
    a.append(int(input()))
new_a_reverse=sorted(a,reverse=True)
for i in range(n):
    if(max(a)==a[i]):
        print(new_a_reverse[1])
    elif(max(a)!=a[i]):
        print(max(a))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list()
for i in range (n):
    a.append(int(input()))
for i in range(n):
    if(max(a)==a[i]):
        new_a_reverse=sorted(a,reverse=True)
        print(new_a_reverse[1])
    elif(max(a)!=a[i]):
        print(max(a))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(n):
  li = l[:i] + l[i+1:]
  print(max(li))

Submission status: Time Limit Exceeded

Solution code:
"""
セグメント木：蟻本P153
できること：a[i]の更新(O(log n))、a[L],...,a[R-1]の最小値など(O(log n))
入力：n,a(配列)
     'ide_ele' : 単位元(min:∞, 和:0, 積:1, gcd:0)
     'segfunc' : return min(x,y) とかにする
出力:'init(a)': 配列aで初期化。O(N)
     'update(k,x)': a[k]をxに変更 O(logN)
     'query(p,q)': [p,q)について "segfunc" したものを返す O(logN)
"""
n=int(input())
a=[int(input()) for i in range(n)]
#####segfunc######
def segfunc(x,y):
    return max(x,y)


def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
ide_ele = 0
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num
init(a)
print(query(1,n))
for i in range(1,n):
    print(max(query(0,i),query(i+1,n)))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
A = deque([int(input()) for _ in range(N)])

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

m = max(a)

for i in range(n):
  if a[i]!=m:
    print(m)
  else:
    ans = max([x for j, x in enumerate(a) if j!=i])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[input() for _ in range(N)]
for i in range(0,N):
    l=A.pop(i)
    print(max(A))
    A.insert(i,l)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[input() for _ in range(N)]
for i in range(0,N):
    l=A.pop(i)
    s=max(A)
    print(s)
    A.insert(i,l)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(input()) for _ in range(n)]
B = A[:]
max_A = max(A)
for i in range(n):
    if A[i] == max_A:
        B[i] = 0
        print(max(B))
        B[i] = max_A
    else:
        print(max_A)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
alis=[int(input()) for i in range(n)]
anslis=[0]*n
if alis.count(max(alis))>=2:
	for i in range(n):
		print(max(alis))
else:
	for i in range(n):
		if i!=alis.index(max(alis)):
			print(max(alis))
		else:
			print(sorted(alis)[-2])

Submission status: Time Limit Exceeded

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

all_max = max(nums)
for num in range(N):
    if nums[num] == all_max:
        new_nums = list(nums)
        new_nums.pop(num)
        print(max(new_nums))
    else:
        print(all_max)

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
l = [int(input()) for i in range(n)]
for i in range(n):
    s = l[:i]+l[i+1:]
    print(sorted(s)[-1])

Submission status: Time Limit Exceeded

Solution code:
import copy

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

Submission status: Time Limit Exceeded

Solution code:
import copy

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

ans = 0
for i in range(N):
    tmp = A[:]
    tmp.sort(reverse=True)
    
    if tmp[0] == A[i]:
      print(tmp[1])
    else:
      print(tmp[0])