Buggy python submission (verdict: Runtime Error):
# A の合計/4での区切り±2を探索

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

S = sum(A)
M = S // 4
C = A.copy()

k   = 1
XYZ = []

for n in range(N):
    if n == 0:
        pass
    else:
        C[n] = C[n] + C[n-1]
    if C[n] > k * M:
        XYZ.append(n)
        k += 1

XYZ = XYZ[:3]

X = [XYZ[0]] + [XYZ[0] + i for i in [-2, -1, 1, 2] if 0 <= XYZ[0] + i and XYZ[0] + i <= N-1]
Y = [XYZ[1]] + [XYZ[1] + i for i in [-2, -1, 1, 2] if 0 <= XYZ[1] + i and XYZ[1] + i <= N-1]
Z = [XYZ[2]] + [XYZ[2] + i for i in [-2, -1, 1, 2] if 0 <= XYZ[2] + i and XYZ[2] + i <= N-1]
R = []

for x in X:
    for y in Y:
        for z in Z:
            if x < y and y < z:
                PQRS = [C[x], C[y] - C[x], C[z] - C[y], S - C[z]]
                R.append(max(PQRS) - min(PQRS))
            else:
                pass

print(min(R))


Fixed submission:
# 解説みて実装
import numpy as np


N = int(input())
A = list(map(int, input().split()))
C = np.cumsum(A).tolist()

LL = [np.inf] * N
LR = [np.inf] * N

l = 0

for m in range(N-1):
    if l < m:
        LL[m] = C[l]
        LR[m] = C[m] - C[l]
        while l < m:
            LL_tmp = C[l+1]
            LR_tmp = C[m] - C[l+1]
            if abs(LL[m] - LR[m]) >= abs(LL_tmp - LR_tmp):
                l    += 1
                LL[m] = C[l]
                LR[m] = C[m] - C[l]
            else:
                break

B = A[::-1]
D = np.cumsum(B).tolist()

RL = [np.inf] * N
RR = [np.inf] * N

r = 0

for m in range(N-1):
    if r < m:
        RR[m] = D[r]
        RL[m] = D[m] - D[r]
        while r < m:
            RR_tmp = D[r+1]
            RL_tmp = D[m] - D[r+1]
            if abs(RR[m] - RL[m]) >= abs(RR_tmp - RL_tmp):
                r    += 1
                RR[m] = D[r]
                RL[m] = D[m] - D[r]
            else:
                break

RR = RR[::-1]
RL = RL[::-1]

X = np.array([LL[:-1], LR[:-1], RL[1:], RR[1:]])[:, 1:-1]

print(int(np.min(np.abs(np.max(X, axis=0) - np.min(X, axis=0)))))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

S = sum(A)
M = S // 4
C = A.copy()

k   = 1
XYZ = []

for n in range(N):
    if n == 0:
        pass
    else:
        C[n] = C[n] + C[n-1]
    if C[n] > k * M:
        XYZ.append(n)
        k += 1

XYZ = XYZ[:3]

X = [XYZ[0] + i for i in list(range(-2, 2+1)) if 0 <= XYZ[0] + i and XYZ[0] + i <= N-1]
Y = [XYZ[1] + i for i in list(range(-2, 2+1)) if 0 <= XYZ[1] + i and XYZ[1] + i <= N-1]
Z = [XYZ[2] + i for i in list(range(-2, 2+1)) if 0 <= XYZ[2] + i and XYZ[2] + i <= N-1]
R = []

for x in X:
    for y in Y:
        for z in Z:
            if x < y and y < z:
                PQRS = [C[x], C[y] - C[x], C[z] - C[y], S - C[z]]
                R.append(max(PQRS) - min(PQRS))
            else:
                pass

print(min(R))


Fixed submission:
# 解説みて実装
import numpy as np


N = int(input())
A = list(map(int, input().split()))
C = np.cumsum(A).tolist()

LL = [np.inf] * N
LR = [np.inf] * N

l = 0

for m in range(N-1):
    if l < m:
        LL[m] = C[l]
        LR[m] = C[m] - C[l]
        while l < m:
            LL_tmp = C[l+1]
            LR_tmp = C[m] - C[l+1]
            if abs(LL[m] - LR[m]) >= abs(LL_tmp - LR_tmp):
                l    += 1
                LL[m] = C[l]
                LR[m] = C[m] - C[l]
            else:
                break

B = A[::-1]
D = np.cumsum(B).tolist()

RL = [np.inf] * N
RR = [np.inf] * N

r = 0

for m in range(N-1):
    if r < m:
        RR[m] = D[r]
        RL[m] = D[m] - D[r]
        while r < m:
            RR_tmp = D[r+1]
            RL_tmp = D[m] - D[r+1]
            if abs(RR[m] - RL[m]) >= abs(RR_tmp - RL_tmp):
                r    += 1
                RR[m] = D[r]
                RL[m] = D[m] - D[r]
            else:
                break

RR = RR[::-1]
RL = RL[::-1]

X = np.array([LL[:-1], LR[:-1], RL[1:], RR[1:]])[:, 1:-1]

print(int(np.min(np.abs(np.max(X, axis=0) - np.min(X, axis=0)))))