Buggy python submission (verdict: Time Limit Exceeded):
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])

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


A_hash = {}
for i in range(N):
        if A[i] in A_hash:
                A_hash[A[i]] += 1
        else:
                A_hash[A[i]] = 1


A_max = max(A)
A_keys = list(A_hash.keys())
A_keys.sort()

if len(A_keys) > 1:
        A_second_max = A_keys[-2]
else:
        A_second_max = A_keys[-1]



for i in range(N):
        if A[i] == A_max:
                if A_hash[A_max] == 1:
                        print(A_second_max)
                else:
                        print(A_max)
        else:
                print(A_max)

Buggy python submission (verdict: Time Limit Exceeded):
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])

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


A_hash = {}
for i in range(N):
        if A[i] in A_hash:
                A_hash[A[i]] += 1
        else:
                A_hash[A[i]] = 1


A_max = max(A)
A_keys = list(A_hash.keys())
A_keys.sort()

if len(A_keys) > 1:
        A_second_max = A_keys[-2]
else:
        A_second_max = A_keys[-1]



for i in range(N):
        if A[i] == A_max:
                if A_hash[A_max] == 1:
                        print(A_second_max)
                else:
                        print(A_max)
        else:
                print(A_max)

Buggy python submission (verdict: Time Limit Exceeded):
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])

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


A_hash = {}
for i in range(N):
        if A[i] in A_hash:
                A_hash[A[i]] += 1
        else:
                A_hash[A[i]] = 1


A_max = max(A)
A_keys = list(A_hash.keys())
A_keys.sort()

if len(A_keys) > 1:
        A_second_max = A_keys[-2]
else:
        A_second_max = A_keys[-1]



for i in range(N):
        if A[i] == A_max:
                if A_hash[A_max] == 1:
                        print(A_second_max)
                else:
                        print(A_max)
        else:
                print(A_max)