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

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

Submission status: Time Limit Exceeded

Solution code:
def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	A = [int(input()) for _ in range(N)]
	prev = max(A[1:])
	print(prev)
	for i in range(1, N-1):
		if A[i] != prev:
			prev = max(A[i-1], prev) 
			print(prev)
		else:
			prev = max(max(A[:i]), max(A[i+1:]))
			print(prev)

	print(max(A[:N-1]))

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

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

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(a))
    a.append(item)

Submission status: Time Limit Exceeded

Solution code:
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())
num = []
for i in range(n):
    a = int(input())
    num.append(a)

max_n = max(num)

for i in range(n):
    b = num[i]
    if b == max_n:
        num_c = num
        c = num_c[i]
        num_c[i] = 0
        print(max(num_c))
        num_c[i] = c
    else:
        print(max_n)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

# a[0]の場合
temp_list = a[1:]
temp_list.sort()
print(temp_list[-1])

# それ以外の場合
for i in range(1, n):
  temp_list = a[:i] + a[i+1:]
  temp_list.sort()
  print(temp_list[-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):
    b=a[:]
    del b[i]
    print(max(b))

Submission status: Time Limit Exceeded

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

a_sort = sorted(a)
for i in range(n):
	if max(a) == a[i]:
		print(a_sort[-2])
	else:
		print(max(a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

suuretu_list = []
kari_list = []

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

c = max(suuretu_list)

d = suuretu_list.index(c)

for u in suuretu_list:
    if u != c:
        print(c)
    else:
        e = max(kari_list)
        f = kari_list.index(e)
        kari_list.pop(f)
        g = max(kari_list)
        print(g)
        kari_list.append(g)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[]
for i in range(n):
    x=int(input())
    l.append(x)
for i in range(n):
    x=l[i]
    l.pop(i)
    y=max(l)
    l.insert(i,x)
    print(y)

Submission status: Time Limit Exceeded

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

for i in range(n):
	print(maxs[i])

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

Submission status: Time Limit Exceeded

Solution code:
import copy

n=int(input())
info=[]
for i in range(n):
    info.append(int(input()))
   
for i in range(n):
    info2=copy.deepcopy(info)
    del info2[i]
    print(max(info2))

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
ma =max(a)
for i in range(n):
  if a[i]==ma:
    b=copy.deepcopy(a)
    del b[i]
    print(max(b))
  else:
    print(ma)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    # print(A)
    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())

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

for i in range(n):
  list = copy.copy(s)
  list.pop(i)
  print(max(list))

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
a = [list(map(int, input().split())) for _ in range(n)]
a=sum(a,[])
a_sort=copy.copy(a)
a_sort.sort()
a_last,a_last2=a_sort[-1],a_sort[-2]
if a_last==a_last2:
  for i in range(n):
    print(a_last)
else:
  for i in range(n):
    if a[i]!=a_last:
      print(a_last)
    else:
      print(a_last2)

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())

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

for i in range(len(x_list)):
    tmp_list = copy.deepcopy(x_list)
    tmp_list.pop(i)
    print(max(tmp_list))

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
a_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)
        if a_list[i] == a_max:
            is_max = True
    else:
        print(a_max)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    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()))

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

for i in a:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

n = int(input())

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

max_a = max(A)

for i in range(n):
    if max_a == A[i]:
        print(max(A[0:i] + A[i+1:n]))
    else:
        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):
    B=copy.copy(A)
    B.pop(j)
    print(max(B))

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
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 LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    a = [INT() for _ in range(n)]

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

if  __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

readline = stdin.readline


def ns():
    """
    入力を`[\\s]`を除いて文字列として取得
    """
    return readline().rstrip()


def ni():
    """
    入力を`int`に変換
    """
    return int(ns())


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


def main():
    n, *a = nf()
    for i in range(n):
        tmp = a[:]
        tmp.pop(i)
        print(max(tmp))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = np.zeros(n, dtype=np.int64)
for i in range(n):
    a[i] = int(input())
for i in range(n):
    max1 = 0
    max2 = 0
    if len(a[:i]) != 0:
        max1 = np.max(a[:i])
    if len(a[i+1:]) != 0:
        max2 = np.max(a[i+1:])
    print(max(max1, max2))

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())

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

for i in range(len(A)):
    B = copy.copy(A)
    del(B[i])
    # print("B = {}".format(B))
    print(max(B))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def main():
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))

    # print(A)
    for j in range(N):
        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=[int(input())  for i in range(n)]
b=list(a)
b.remove(max(a))
for i in range(n):
    if a[i] != max(a):
        print(max(a))
    else:
        print(max(b))

Submission status: Time Limit Exceeded

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

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

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 = [int(input()) for i in range(n)]
for i in range(n):
    if i == 0:
        print(max(a[1:]))
    elif i == n-1:
        print(max(a[:n-1]))
    else:
        print(max(max(a[0:i]), max(a[i+1:])))

Submission status: Time Limit Exceeded

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


left_max = [-1] * N
right_max = [0]
all = sum(A)
left_max[0] = A[0]
right_max[0] = A[-1]
for i in range(1, N):
        left_max[i] = max(left_max[i-1], A[i])
for i in reversed(range(0, N-1)):
        right_max.insert(0, max(right_max[0], A[i]))


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

Submission status: Time Limit Exceeded

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

for i in range(N):
    a_copy = copy.copy(a)
    a_copy.pop(i)
    print(max(a_copy))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
#n=list(map(int,input().split()))
n=int(input())

num=[]
for i in range(n):
    num.append(int(input()))
    
for i in range(n):
    print(max(num[:i]+num[i+1:]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = []
max1 = 0
max2 = 0

for i in range(N):
  B = int(input())
  if B>max1:
    max1 = B
  else:
    if B>max2:
      max2 = B
      
  A.append(B) 

for i in range(N):
  if A[i] == max(A):
    print(max2)
  else:
    print(max1)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    for i in range(N):
        Ap = copy.copy(A)
        del Ap[i]
        print(max(Ap))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy

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

ans = []

for i in range(n):
    tmp = copy.deepcopy(lst)
    tmp.pop(i)
    ans.append(max(tmp))
    print(max(tmp))

Submission status: Time Limit Exceeded

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

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):
    A_ = [A[j] for j in range(N) if i != j]
    print(max(A_))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
max_i=0
max_n=0
for i in range(n):
  a.append(int(input()))
  max_i=a.index(max(a))

max_n=max(a)
a.pop(max_i)
semi_n=max(a)

for j in range(n):
  if j != max_i:
    print(max_n)
  else:
    print(semi_n)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=[]
for i in range(0,n):
    A.append(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:
from collections import deque
n = int(input())
de = deque([int(input()) for _ in range(n)])
for i in range(n):
  f = de[0]
  del de[0]
  print(max(de))
  de.append(f)

Submission status: Time Limit Exceeded

Solution code:


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

dup = [x for x in set(a) if a.count(x) > 1]

tmp_a = sorted(list(set(a)), reverse=True)
no1 = tmp_a[0]
no2 = tmp_a[1] if len(tmp_a)>1 else tmp_a[0]

for each in a:
  if each == no1 and each not in dup:
    print(no2)
  else:
    print(no1)

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

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):
    if(A[i] != max_a):
        print(max_a)
    else:
        B = copy.deepcopy(A)
        B.pop(i)
        print(max(B))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A = []
for _ in range(n):
  x = int(input())
  A.append(x)
standard = max(A)
for i in range(n):
  if A[i] != standard:
    print(standard)
  else:
    temp = 0
    for t in range(n):
      if t != i:
        if A[t] >= temp:
          temp = A[t]
    print(temp)

Submission status: Time Limit Exceeded

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

for i in range(len(num)):
    a = max(num[:i]) if i > 0 else -1e9
    b = max(num[i+1:]) if i < len(num)-1 else -1e9
    print(max(a, b))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n=int(input())
a=deque([int(input()) for _ in range(n)])
for _ in range(n):
    ans=a
    x=ans.popleft()
    print(max(ans))
    ans.append(x)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

c = []
for j in range(N):
    c = a.copy()
    c.pop(j)
    print(max(c))

Submission status: Time Limit Exceeded

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

ans = max(ls)
for i in range(len(ls)):
    ls2 = copy.copy(ls)
    del ls2[i]
    if ans in ls2:
        print(ans)
    else:
        ls2.sort()
        print(ls2[-1])

Submission status: Time Limit Exceeded

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

for i in range(n):
    a=l[i]
    l.remove(a)
    #print(a,l)
    print(max(l))
    l.insert(i,a)

Submission status: Time Limit Exceeded

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

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

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Maxi = [0] * N
for i in range(N):
	Ai = int(input())
	for j in range(N):
		if j == i:
			continue
		if Ai > Maxi[j]:
			Maxi[j] = Ai

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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_list = copy.deepcopy(A)
    tmp_list.pop(i)
    print(max(tmp_list))

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
value_list = []

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

for i in range(n):
    keep_list = copy.copy(value_list)
    keep_list[i] = 0
    print(max(keep_list))

Submission status: Time Limit Exceeded

Solution code:
a=[]
m1,m2=0,0
for _ in range(input()):
    n=input()
    a.append(n)
    if n>m1:
        m2=m1
        m1=n
    elif n>m2:
        m2=n
for i in a:
    if i==m1:
        print m2
    else:
        print m1

Submission status: Time Limit Exceeded

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

for i in range(N):
    tmp=AN.copy()
    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)]

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
nums = np.array([int(input()) for _ in range(N)])

org_indices = np.ones(N, dtype=bool)
for i in range(N):
    indices = np.copy(org_indices)
    indices[i] = False
    print(np.amax(nums[indices]))

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.pop(0)
    print(max(a))
    a.append(tmp)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
li = []
for _ in range(N):
    li.append(int(input()))
    
for i in range(N):
    if i != 0:
        a = max(li[:i])
    else:
        a = 0
    
    if i != N-1:
        b = max(li[i+1:])
    else:
        b = 0
    print(max([a,b]))

Submission status: Time Limit Exceeded

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

import numpy as np
an = np.array(an)
for i in range(n):
	ind = np.ones(n, dtype=bool)
	ind[i] = False
	res = np.max(an[ind])
	print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
for i in range(N):
    A_new1 = A[:i] + [0]
    A_new2 = A[i+1:] + [0]
    if max(A_new1) >= max(A_new2):
        print(max(A_new1))
    else:
        print(max(A_new2))

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:
import copy

N = int(input())

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


_max = max(A)

for i in range(N):
    if A[i] == _max:
        _A = copy.deepcopy(A)
        del _A[i]
        print(max(_A))

    else:
        print(_max)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
for i in range(n):
	a.append(int(input()))
ma=max(a)
keiken=0
b=[]
for i in range(n):
	if a[i]==ma and keiken==0:
		for ii in range(n):
			if ii!=i:
				b.append(a[ii])
		print(max(b))
	else:
		print(ma)

Submission status: Time Limit Exceeded

Solution code:
import copy as c
n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
maxs = []
for i in range(n):
	a2 = c.copy(a)
	a2[i] = 0
	maxs.append(max(a2))

for i in range(n):
	print(maxs[i])

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

Submission status: Time Limit Exceeded

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

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

for i in range(N):
	b = l.pop(0)
	print(max(l))
	l.append(b)

Submission status: Time Limit Exceeded

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    A_ = [int(input()) for _ in range(N)]

    max_A = max(A_)
    
    for i in range(N):
        if A_[i] == max_A:
            L = A_[0:i]
            L.extend(A_[i+1:])
            print(max(L))
        else:
            print(max_A)
            
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

for i in A:
  array = sorted_A.copy()
  array.remove(i)
  print(array[-1])

Submission status: Time Limit Exceeded

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


def main():
    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])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
c=max(a)
check=False
for i in range(n):
    if a[i]==c and check==False:
        b=a[:i]+a[i+1:]
        d=max(b)
        print(d)
    elif a[i]==c and check==True:
        print(d)
    else:
        print(c)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
N = int(input())
A = [int(input()) for _ in range(N)]
for i in range(N):
    B = A[:]
    B.pop(i)
    print(max(B))

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
aa=[]
for _ in range(n):
    aa.append(int(input()))
a = aa[0]
b = max(aa[1:])
print(b)
for i in range(1,n):
    if a >= b:
        print(a)
        b = a
        a = aa[i]
    else:
        if aa[i] != b:
            print(b)
            a = aa[i]
        else:
            a = aa[i]
            b = max(aa[:i]+aa[i+1:])
            print(b)

Submission status: Time Limit Exceeded

Solution code:
import copy
N=int(input())
A = [int(input()) for i in range(N)]
big=max(A)
flag=0
for i in range(N):
    if A[i]==big:
        if flag==0:
            flag==1
            hoge=copy.copy(A)
            hoge.pop(i)
            bigger=max(hoge)
            if bigger==big:
                print(big)
            else:
                print(bigger)
        else:
            print(bigger)
    else:
        print(big)

Submission status: Time Limit Exceeded

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

max_=0
for _ in range(n-1):
  res=li[0]
  del li[0]
  ans=max(li)
  if ans>max_:
    print(ans)
  else:
    print(max_)
  if res>max_:
    max_=res
    
print(max_)

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):
    l.remove(l[i])
    print(max(l))
    l.insert(i,k[i])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
for n in range(N):
    a = [A[m] for m in range(N) if m != n]
    print(max(a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [0] * n
#dp = []

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

maxV = max(a)

for i in range(n):
    if a[i] == maxV:
        new = list(a)
        del new[i]
        print(max(new))
    else:
        print(maxV)

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    m=0
    for j in range(n):
        if i == j:
            continue
        m=max(m,a[j])
    print m

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

S = sorted(A)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())

a = [0] * n

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

# a_s = set(a)

for i in range(n):
    tmp = copy.deepcopy(a)
    # tmp.discard(a[i])
    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

i=0
while i!=n:
    a=s[0]
    del s[0]
    print(max(s))
    s.append(a)
    i+=1

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for i in [0] * 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):
  tmp = int(input())
  A.append(tmp)
  
for i in range(N):
  tmp_list = A[:]
  tmp_list.pop(i)
  #print(tmp_list)
  tmp_set = set(tmp_list)
  print(max(tmp_set))

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

if len(a) > 1:
    t = sorted(list(a.keys()))[-2]
k = max(a.keys())
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:
N=int(input())
A=[int(input()) for i in range(N)]
for i in range(N):
  if i==0:
    print(max(A[i+1:]))
  if i!=0 and i!=N-1:
    li1=max(A[:i])
    li2=max(A[i+1:])
    print(max(li1,li2))
  if i==N-1:
    print(max(A[:i]))

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = [int(input()) for _ in range(n)]
for i in range(n):
  if i == 0:
    print(max(li[1:]))
  elif i == n:
    print(max(li[:-1]))
  else:
    print(max(li[:i]+li[i+1:]))

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.pop(0)
    print(max(a))
    a.append(tmp)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = [int(input()) for i 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[:-1]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input() for i in range(N)]
for i in range(N):
    x=s[:]
    x.pop(i)
    print(sorted(x)[-1])