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


Fixed submission:
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [0 for n in range(N)]
B[0] = A[0]
for n in range(N-1):
    B[n+1] = max(B[n], A[n + 1])
C = [0 for n in range(N)]
C[-1] = A[-1]
for n in range(N - 1):
    C[-n-2] = max(C[-n-1], A[-n - 2])
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]))

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


Fixed submission:
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [0 for n in range(N)]
B[0] = A[0]
for n in range(N-1):
    B[n+1] = max(B[n], A[n + 1])
C = [0 for n in range(N)]
C[-1] = A[-1]
for n in range(N - 1):
    C[-n-2] = max(C[-n-1], A[-n - 2])
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]))

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


Fixed submission:
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [0 for n in range(N)]
B[0] = A[0]
for n in range(N-1):
    B[n+1] = max(B[n], A[n + 1])
C = [0 for n in range(N)]
C[-1] = A[-1]
for n in range(N - 1):
    C[-n-2] = max(C[-n-1], A[-n - 2])
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]))

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


Fixed submission:
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [0 for n in range(N)]
B[0] = A[0]
for n in range(N-1):
    B[n+1] = max(B[n], A[n + 1])
C = [0 for n in range(N)]
C[-1] = A[-1]
for n in range(N - 1):
    C[-n-2] = max(C[-n-1], A[-n - 2])
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]))

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


Fixed submission:
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [0 for n in range(N)]
B[0] = A[0]
for n in range(N-1):
    B[n+1] = max(B[n], A[n + 1])
C = [0 for n in range(N)]
C[-1] = A[-1]
for n in range(N - 1):
    C[-n-2] = max(C[-n-1], A[-n - 2])
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]))