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

for i in range(N):
    tmp = A[:]
    ans = max(tmp)
    if ans == A[i]:
        ans = sorted(tmp)[-2]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
for i in range(N):
    Ai = copy.copy(A)
    Ai.remove(Ai[i])
    Ai.sort(reverse=True)
    print(Ai[0])

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
for i in range(N):
    Ai = copy.copy(A)
    Ai.remove(Ai[i])
    L = copy.copy(Ai)
    L.sort(reverse=True)
    print(L[0])

Submission status: Time Limit Exceeded

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


if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list_A = []
for _ in range(N):
    A = int(input())
    list_A.append(A)
    
A = max(list_A)
index_A = list_A.index(A)
for i in range(N):
    if list_A[i] == A:
      list_B = sorted(list_A, reverse=True)
      B = list_B[1]
      print(B)
    else:
      print(A)

Submission status: Time Limit Exceeded

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [A[0]]
for n in range(N-1):
    B = B+[max(B[-1], A[n + 1])]
C = [A[-1]]
for n in range(N - 1):
    C = [max(C[0], A[-n - 2])] + C
for n in range(N):
    if n == 0:
        print(C[1])
    elif n == N - 1:
        print(B[N - 2])
    else:
        print(max(B[n-1], C[n+1]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [A[0]]
for n in range(N-1):
    B = B+[max(B[-1], A[n + 1])]
C = [A[-1]]
for n in range(N - 1):
    C = [max(C[0], A[-n - 2])] + C
D = [C[1]]+[max(B[n-1], C[n+1]) for n in range(1, N-2+1)]+[B[N-2]]
for d in D:
    print(d)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [max(A[: n+1]) for n in range(N)]
C = [max(A[N - n - 1:]) for n in range(N)][::-1]
D = [C[1]]+[max(B[n-1], C[n+1]) for n in range(1, N-2+1)]+[B[N-2]]
for d in D:
    print(d)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [max(A[: n+1]) for n in range(N)]
C = [max(A[N - n - 1:]) for n in range(N)][::-1]

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
A_max = max(A)
for i in range(N):
    if A[i] != A_max:
        print(A_max)
    else:
        B = A.copy()
        del B[i]
        print(max(B))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
A_max = max(A)
for i in range(N):
    if A[i] != max(A):
        print(max(A))
    else:
        B = A.copy()
        del B[i]
        print(max(B))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
B=[]
for i in range(N):
    a=int(input())
    A.append(a)
    B.append(a)
if B.count(max(B))==1:
    B.remove(max(B))
    b=max(B)
else:
    b=max(B)
c=max(A)
for j in range(N):
    if A[j]==max(A):
        print(b)
    else:
        print(c)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
B=[]
for i in range(N):
    a=int(input())
    A.append(a)
    B.append(a)
if B.count(max(B))==1:
    B.remove(max(B))
    b=max(B)
else:
    b=max(B)
for j in range(N):
    if A[j]==max(A):
        print(b)
    else:
        print(max(A))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
for i in range(N):
    a=int(input())
    A.append(a)
for j in range(N):
    b=A[j]
    del A[j]
    print(max(A))
    A.insert(j, b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for x in range(n)]
m = max(a)
for i in range(n):
    if a[i] != m:
        print(m)
    else:
        print(max(a[:i] + a[i+1:]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for _ in range(N):
    A = int(input())
    list_A.append(A)
    
A = max(list_A)
index_A = list_A.index(A)

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

Submission status: Time Limit Exceeded

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

for _ in range(N):
    A = int(input())
    list_A.append(A)
    
for i in range(N):
    original = list_A[i]
    list_A[i] = 0
    print(max(list_A))
    list_A[i] = original

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys

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


    for j in range(N):
        if j == 0:
            print(max(A[1:]))

        elif j == N-1:
            print(max(A[:N-1]))

        else:
            print(max(max(A[:j]), max(A[j+1:])))


main()

Submission status: Time Limit Exceeded

Solution code:
import sys
 
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
 
    for j in range(N):
        if j == 0:
            print(max(A[1:]))
 
        elif j == N-1:
            print(max(A[:N-1]))
 
        else:
            print(max(max(A[:j]), max(A[j+1:])))
 
 
main()

Submission status: Time Limit Exceeded

Solution code:
import sys

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

    for j in range(N):
        if j == 0:
            print(max(A[1:]))

        elif j == N-1:
            print(max(A[:N-1]))

        else:
            print(max(max(A[:j]), max(A[j+1:])))


main()

Submission status: Time Limit Exceeded

Solution code:
import heapq
N = int(input().strip())
a = [list(map(lambda x: int(x)*(-1), input().split())) for i in range(N)]

for i in range(N):
    tmp=a[:i]+a[i+1:]
    heapq.heapify(tmp)
    ans=heapq.heappop(tmp)[0]*(-1)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))
    for j in range(N):
        a = A[j]
        A[j] = -1
        print(max(A))
        A[j] = a


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input().strip())
a = [list(map(int, input().split())) for i in range(N)]

for i in range(N):
    tmp=a[:i]+a[i+1:]
    print(max(tmp)[0])

Submission status: Time Limit Exceeded

Solution code:
def main(n: int, a: list):
    ans = 0
    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:
# coding: UTF-8
import sys
import copy

numlist = []
for line in sys.stdin.readlines():
  numlist.append(int(line.rstrip()))
N = numlist.pop(0)

for i, num in enumerate(numlist):
  nlist = copy.deepcopy(numlist)
  nlist.pop(i)
  maxN = max(nlist)
  print(maxN)

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
l=[int(input()) for x in range(n)]
ans=[]
for i in range(n):
    ans=copy.copy(l)
    ans.remove(l[i])
    print(max(ans))
    ans.clear()

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
l=[int(input()) for x in range(n)]
ans=[]
for i in range(n):
    ans=copy.copy(l)
    ans.remove(l[i])
    print(max(ans))
    ans.clear

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
k = []
for i in range(N):
  k.append(int(input()))
p = k
x = k.index(max(k))
for i in range(N):
  if i==x:
    p.sort()
    print(p[-2])
  else:
    print(max(k))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

import sys
A = []
for line in sys.stdin.readlines():
    A.append(line.rstrip())
for i in range(N):
  B = A.copy()
  B.pop(i)
  B.sort(reverse=True)
  print(B[0])

Submission status: Time Limit Exceeded

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

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):
  ind = np.ones(N, dtype=bool)
  ind[i] = False
  print(max(A[ind]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lista = []
for i in range(N):
    lista.append(int(input()))
for i in range(N):
    save = lista[i]
    lista.pop(i)
    print(max(lista))
    lista.insert(i,save)

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

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())
ls_a = [int(input()) for _ in range(n)]

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

Submission status: Time Limit Exceeded

Solution code:
import copy
length = int(input())
suretsu=[int(input()) for i in range(length)]
result = []
zantei_max = max(suretsu)
for i in range(length):
    if (zantei_max == suretsu[i]):
        copy_suretsu = copy.deepcopy(suretsu)
        del copy_suretsu[i]
        new_max = max(copy_suretsu)
        result.append(str(new_max))
    else:
        result.append(str(zantei_max))
print('\n'.join(result))

Submission status: Time Limit Exceeded

Solution code:
length = int(input())
suretsu=[int(input()) for i in range(length)]
result = []
for i in range(length):
    pop_suretsu = suretsu[0:i] + suretsu[i+1:]
    result.append(str(max(pop_suretsu)))
print('\n'.join(result))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

for i in range(N):
    if A[i] == max(A) and count>1:
        print(max(A))
    elif A[i] == max(A) and count==1:
        tmp = A[i]
        A[i]=0
        print(max(A))
        A[i]=tmp
    else:
        print(max(A))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

max_number = max(a)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,*a=map(int,open(0).read().split())

for i in range(n):
    temp=a[i]
    b=sorted(a)[::-1]
    if temp!=b[0]:
        print(b[0])
    else:
        print(b[1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

max_num = max(numbers)

for i in range(len(numbers)):
    if numbers[i] == max_num:
        temp_numbers = cp.copy(numbers)
        temp_numbers.pop(i)
        print(max(temp_numbers))
    else :
        print(max_num)

Submission status: Time Limit Exceeded

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

def check_max_num(i,numbers):
    max_num = 0
    for j in range(len(numbers)):
        if j != i:
            if numbers[j] > max_num:
                max_num = numbers[j]
    return max_num

for i in range(len(numbers)):
    print(check_max_num(i,numbers))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy
def main():
    n = int(input())
    
    ans_list = []
    for i in range(n):
        a = int(input())
        ans_list.append(a)

    for j in range(n):
        tmp_list = copy.deepcopy(ans_list)
        tmp_list[j] = 0
    
        print(np.max(tmp_list))



    
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def solve():
    for i in range(n):
        if a[i]!=a_max:
            print(a_max)
        else:
            a[i]=0
            print(max(a))
            a[i]=a_max

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
a_max=max(a)
for i in range(n):
    if a[i]!=a_max:
        print(a_max)
    else:
        a[i]=0
        print(max(a))
        a[i]=a_max

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(input()) for _ in [0]*n]
#最大値が2つある場合に注意しないといけない。
#最大値が2つ以上ある場合を先に処理
import sys
if l.count(max(l))>1:
  for i in range(n):
    print(max(l))
#O(n)の処理なら何回やってもいいくらいの気持ちでいく
else:
  s=set(l)
  m1 = max(s)
  s.remove(max(s))
  m2 = max(s)
  for i in l:
    if i == m1:
      print(m2)
    else:
      print(m1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(input()) for _ in [0]*n]
#最大値が2つある場合に注意しないといけない。
#最大値が2つ以上ある場合を先に処理
import sys
if l.count(max(l))>1:
  for i in range(n):
    print(max(l))
#O(n)の処理なら何回やってもいいくらいの気持ちでいく
else:
  s=set(l)
  s.remove(max(s))
  m = max(s)
  for i in l:
    if i == max(l):
      print(m)
    else:
      print(max(l))

Submission status: Time Limit Exceeded

Solution code:
def calculate(arr):
    arr2 = rank(arr.copy())

    max = arr2[len(arr2) - 1]
    second = arr2[len(arr2) - 2]

    for i in range(len(arr)):
        value = arr[i]
        if max != value:
            print(max)
        else:
            print(second)



def rank(arr):
    lastIndex = len(arr) - 1
    while lastIndex > 0:

        for i in range(lastIndex):
            if arr[i + 1] < arr[i]:
                tmp = arr[i + 1]
                arr[i + 1] = arr[i]
                arr[i] = tmp

        lastIndex = lastIndex - 1

    return arr



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

calculate(arr)

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 = [int(input()) for i in range(n)]
b = [num for num in a]
x = max(a)
for i in range(n) :
    if a[i] != x :
        print(x)
    else :
        b.remove(a[i])
        print(max(b))
        b.append(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):
    max = 0
    for j in range(n):
        if i != j:
            if max < a[j]:
                max = a[j]
    print(max)

Submission status: Time Limit Exceeded

Solution code:
import copy



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

for i in range(N):
   # B = copy.deepcopy(A)
    tmp = A[i]
    A[i] = 0
    ans = max(A)
    A[i] = tmp
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

tmp = []

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

Submission status: Time Limit Exceeded

Solution code:
import copy

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

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

tmp = []

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
m=max(l)
nums=[i for i in range(n)]
for num in nums:
  if(l[num]!=m or l.count(m)!=1):
    print(m)
  else:
    print(s[-2])

Submission status: Time Limit Exceeded

Solution code:
import sys
def main():
    N = int(sys.stdin.readline())
    A = [int(sys.stdin.readline()) for i in range(N)]
    maxa = max(A)
    if A.count(maxa) > 1:
        for i in range(N):
            print(maxa)
    else:
        for i in range(N):
            if i != A.index(maxa):
                print(maxa)
            else:
                print(sorted(A)[-2])
                
main()

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for i in range(N)]
for i in range(N):
    A2 = A.copy()
    A2[i] = 0
    print(max(A2))

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
m = 0
a = []
for _ in range(n):
    _a = int(input())
    m = max(m, _a)
    a.append(_a)

for i in range(n):
    if a[i] == m:
        t = a[:]
        t.pop(i)
        print(max(t))
    else:
        print(m)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

num = int(input())

arr = deque([])

for i in range(num):
    arr.append(int(input()))

for i in range(num):
    a = arr.popleft()
    print(max(list(arr)))
    arr.append(a)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())

arr = []

for i in range(num):
    arr.append(int(input()))

for i in range(num):
    if i == 0:
        print(int(max(arr[1:])))
    elif i == num-1:
        print(int(max(arr[:-1])))
    else:  
        print(int(max(arr[:i]+arr[i+1:])))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=[]
for i in range(N):
  L.append(int(input()))
S=[]
M=[]
t=0
S=L[1:len(L)]
print(max(S))
M=L[0:len(L)-1]
for i in range(1,len(L)-1):
  S=L[0:i]
  M=L[i+1:len(L)]
  print(max(max(S),max(M)))
M=L[0:len(L)-1]
print(max(M))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[int(input()) for i in range(n)]
m=max(l)
nums=[i for i in range(n)]
for num in nums:
  if(l[num]==m and l.count(m)==1):
    print(sorted(l)[-2])
  else:
    print(m)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[int(input()) for i in range(n)]
m=max(l)
nums=[i for i in range(n)]
for num in nums:
  if(l[num]!=m or l.count(m)!=1):
    print(m)
  else:
    print(sorted(l)[-2])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

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:
    print(sorted(a)[-2])

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):
  list = A[:j] + A[j+1:]
  print(max(list))

Submission status: Time Limit Exceeded

Solution code:
import heapq
n=int(input())
a=[-int(input()) for i in range(n)]
for i in range(n):
  x=a[:i]+a[i+1:]
  heapq.heapify(x)
  print(-heapq.heappop(x))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

from collections import deque

n = int(input())
a = deque()
for _ in range(n):
    a.append(int(input()))

for _ in range(n):
    tmp = a.popleft()
    print(max(a))
    a.append(tmp)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

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

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

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=[int(input()) for i in range(a)]
m=max(b) 
for  i in range(0,a,1):
    if b[i]==m:
        c=b.copy()
        c[i]=0
        print(max(c))
    else:
        print (m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

b = sorted(a)

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n = int(input())
    aaa = [int(input()) for _ in range(n)]
    maxa = max(aaa)
    for i in range(n):
        if maxa == aaa[i]:
            print(max(aaa[:i]+aaa[i+1:]))
        else:
            print(maxa)
resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n = int(input())
    aaa = [int(input()) for _ in range(n)]
    for i in range(n):
        ans = max(aaa[:i]+aaa[i+1:])
        print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
A_max = max(A)
for a in A:
    if a==A_max:
        print(sorted(A)[-2])
    else:
        print(A_max)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
s=int(input())
list1=[input() for _ in range(s)]
for i in range(len(list1)):
  list2=copy.copy(list1)
  list2.remove(list2[i])
  list2=sorted(list2,key=lambda x:-int(x))
  print(list2[0])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list()
for i in range(n):
    x = input()
    a.append(int(x))
second = sorted(a)[-2]
m = max(a)
for i in range(n):
    if max(a) == a[i] and a.count(a[i]) == 1:
        print(second)
    else:
        print(m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list()
b = list()
for i in range(n):
    x = input()
    a.append(int(x))
b = sorted(a)
for i in range(n):
    if b[-1] == a[i] and a.count(b[-1]) == 1:
        print(b[-2])
    else:
        print(b[-1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list()
b = list()
for i in range(n):
    x = input()
    a.append(int(x))
b = sorted(a)
for i in range(n):
    if b[-1] == a[i] and a.count(b[-1]):
        print(b[-2])
    else:
        print(b[-1])