Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
A = [int(input()) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
c = collections.Counter(A)
Max = max(A)
Max_list = [i for i, v in enumerate(A) if v == max(A)]
for i in range(N):
    if A[i] == Max:
            if len(Max_list) > 1:
                print(A[i])
            else:
                print(set_A[1])
    else:
        print(Max)


Fixed submission:
import copy
N = int(input())
A = [int(input()) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
A_copy = copy.deepcopy(A)
A_copy.sort(reverse=True)
Max = max(A)
cnt = 0
for i in range(N):
    if A[i] == Max:
        cnt += 1
for i in range(N):
    if A[i] == Max:
        if cnt > 1:
            print(Max)
        else:
            print(set_A[1])
    else:
        print(Max)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
A = [int(input()) for i in range(N)]

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


Fixed submission:
import copy
N = int(input())
A = [int(input()) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
A_copy = copy.deepcopy(A)
A_copy.sort(reverse=True)
Max = max(A)
cnt = 0
for i in range(N):
    if A[i] == Max:
        cnt += 1
for i in range(N):
    if A[i] == Max:
        if cnt > 1:
            print(Max)
        else:
            print(set_A[1])
    else:
        print(Max)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
A = [int(input()) for i in range(N)]
A_copy = copy.deepcopy(A)
for i in range(N):
    A = copy.deepcopy(A_copy)
    A.pop(i)
    print(max(A))


Fixed submission:
import copy
N = int(input())
A = [int(input()) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
A_copy = copy.deepcopy(A)
A_copy.sort(reverse=True)
Max = max(A)
cnt = 0
for i in range(N):
    if A[i] == Max:
        cnt += 1
for i in range(N):
    if A[i] == Max:
        if cnt > 1:
            print(Max)
        else:
            print(set_A[1])
    else:
        print(Max)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
A = [int(input()) for i in range(N)]
A_copy = copy.deepcopy(A)
for i in range(N):
    A = copy.deepcopy(A_copy)
    A.pop(i)
    print(max(A))


Fixed submission:
import copy
N = int(input())
A = [int(input()) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
A_copy = copy.deepcopy(A)
A_copy.sort(reverse=True)
Max = max(A)
cnt = 0
for i in range(N):
    if A[i] == Max:
        cnt += 1
for i in range(N):
    if A[i] == Max:
        if cnt > 1:
            print(Max)
        else:
            print(set_A[1])
    else:
        print(Max)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
lists = [0]*N
ans = []
for i in range(N):
    A = int(input())
    lists[i] = A
i = 0
while 1:
    if i == N:
        break
    tmp = copy.deepcopy(lists[i])
    lists[i] = 0
    print(max(lists))
    lists[i] = tmp
    i += 1


Fixed submission:
import copy
N = int(input())
A = [int(input()) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
A_copy = copy.deepcopy(A)
A_copy.sort(reverse=True)
Max = max(A)
cnt = 0
for i in range(N):
    if A[i] == Max:
        cnt += 1
for i in range(N):
    if A[i] == Max:
        if cnt > 1:
            print(Max)
        else:
            print(set_A[1])
    else:
        print(Max)