Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = list(map(int,input().split()))

S = [A[0]]
for i in range(1,N):
    S.append(S[i-1]+A[i])

ans = 10**20
for i in range(2, N-1):
    m = bisect.bisect(S[:i], S[:i][-1]//2)

    if m == 0:
        L = [S[:i][0], S[:i][-1]-S[:i][0]]
    else:
        L = [S[:i][m], S[:i][-1]-S[:i][m]]
        L2 = [S[:i][m-1], S[:i][-1]-S[:i][m-1]]

        if(abs(L[0]-L[1]) > abs(L2[0]-L2[1])): L = L2

    m = bisect.bisect(S[i:], (S[i:][-1]+S[:i][-1])//2)
    if m == 0:
        R = [S[i:][0]-S[:i][-1], S[i:][-1]-S[i:][0]]
    else:
        R = [S[i:][m]-S[:i][-1], S[i:][-1]-S[i:][m]]
        R2 = [S[i:][m-1]-S[:i][-1], S[i:][-1]-S[i:][m-1]]

        if(abs(R[0]-R[1]) > abs(R2[0]-R2[1])): R = R2

    #print(L, end="")
    #print(R)

    ans = min(ans, max(L[0],L[1],R[0],R[1]) - min(L[0],L[1],R[0],R[1]))

print(ans)



Fixed submission:
import bisect

N = int(input())
A = list(map(int,input().split()))

S = [A[0]]
for i in range(1,N):
    S.append(S[i-1]+A[i])

ans = 1e18
for i in range(2, N-1):
    # 左側 [0,i)
    left_sum = S[i-1]
    m = bisect.bisect(S, left_sum/2)

    L = [S[m], left_sum-S[m]]

    if m != 0:
        L2 = [S[m-1], left_sum - S[m-1]]
        if(abs(L[0]-L[1]) > abs(L2[0]-L2[1])): L = L2

    # 右側 [i,N)
    m = bisect.bisect(S, (S[-1]+left_sum)/2)
    R = [S[m]-left_sum, S[-1]-S[m]]

    if m != i:
        R2 = [S[m-1]-left_sum, S[-1]-S[m-1]]
        if(abs(R[0]-R[1]) > abs(R2[0]-R2[1])): R = R2


    ans = min(ans, max(L[0],L[1],R[0],R[1]) - min(L[0],L[1],R[0],R[1]))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = list(map(int,input().split()))

S = [A[0]]
for i in range(1,N):
    S.append(S[i-1]+A[i])

ans = 1e18
for i in range(2, N-1):
    left = S[:i]
    m = bisect.bisect(left, left[-1]/2)

    if m == 0:
        L = [left[0], left[-1]-left[0]]
    else:
        L = [left[m], left[-1]-left[m]]
        L2 = [left[m-1], left[-1]-left[m-1]]

        if(abs(L[0]-L[1]) > abs(L2[0]-L2[1])): L = L2

    right = S[i:]
    m = bisect.bisect(right, (right[-1]-left[-1])/2 + left[-1])
    if m == 0:
        R = [right[0]-left[-1], right[-1]-right[0]]
    else:
        R = [right[m]-left[-1], right[-1]-right[m]]
        R2 = [right[m-1]-left[-1], right[-1]-right[m-1]]

        if(abs(R[0]-R[1]) > abs(R2[0]-R2[1])): R = R2

    #print(L)
    #print(R)

    ans = min(ans, max(L[0],L[1],R[0],R[1]) - min(L[0],L[1],R[0],R[1]))

print(ans)



Fixed submission:
import bisect

N = int(input())
A = list(map(int,input().split()))

S = [A[0]]
for i in range(1,N):
    S.append(S[i-1]+A[i])

ans = 1e18
for i in range(2, N-1):
    # 左側 [0,i)
    left_sum = S[i-1]
    m = bisect.bisect(S, left_sum/2)

    L = [S[m], left_sum-S[m]]

    if m != 0:
        L2 = [S[m-1], left_sum - S[m-1]]
        if(abs(L[0]-L[1]) > abs(L2[0]-L2[1])): L = L2

    # 右側 [i,N)
    m = bisect.bisect(S, (S[-1]+left_sum)/2)
    R = [S[m]-left_sum, S[-1]-S[m]]

    if m != i:
        R2 = [S[m-1]-left_sum, S[-1]-S[m-1]]
        if(abs(R[0]-R[1]) > abs(R2[0]-R2[1])): R = R2


    ans = min(ans, max(L[0],L[1],R[0],R[1]) - min(L[0],L[1],R[0],R[1]))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = list(map(int,input().split()))

S = [A[0]]
for i in range(1,N):
    S.append(S[i-1]+A[i])

ans = 1e18
for i in range(2, N-1):
    left = S[:i]
    m = bisect.bisect(left, left[-1]/2)

    if m == 0:
        L = [left[0], left[-1]-left[0]]
    else:
        L = [left[m], left[-1]-left[m]]
        L2 = [left[m-1], left[-1]-left[m-1]]

        if(abs(L[0]-L[1]) > abs(L2[0]-L2[1])): L = L2

    right = S[i:]
    m = bisect.bisect(right, (right[-1]-left[-1])/2 + left[-1])
    if m == 0:
        R = [right[0]-left[-1], right[-1]-right[0]]
    else:
        R = [right[m]-left[-1], right[-1]-right[m]]
        R2 = [right[m-1]-left[-1], right[-1]-right[m-1]]

        if(abs(R[0]-R[1]) > abs(R2[0]-R2[1])): R = R2

    #print(L)
    #print(R)

    ans = min(ans, max(L[0],L[1],R[0],R[1]) - min(L[0],L[1],R[0],R[1]))

print(ans)



Fixed submission:
import bisect

N = int(input())
A = list(map(int,input().split()))

S = [A[0]]
for i in range(1,N):
    S.append(S[i-1]+A[i])

ans = 1e18
for i in range(2, N-1):
    # 左側 [0,i)
    left_sum = S[i-1]
    m = bisect.bisect(S, left_sum/2)

    L = [S[m], left_sum-S[m]]

    if m != 0:
        L2 = [S[m-1], left_sum - S[m-1]]
        if(abs(L[0]-L[1]) > abs(L2[0]-L2[1])): L = L2

    # 右側 [i,N)
    m = bisect.bisect(S, (S[-1]+left_sum)/2)
    R = [S[m]-left_sum, S[-1]-S[m]]

    if m != i:
        R2 = [S[m-1]-left_sum, S[-1]-S[m-1]]
        if(abs(R[0]-R[1]) > abs(R2[0]-R2[1])): R = R2


    ans = min(ans, max(L[0],L[1],R[0],R[1]) - min(L[0],L[1],R[0],R[1]))

print(ans)