Buggy python submission (verdict: Time Limit Exceeded):

import numpy as np
from numba import jit

n = int(input())
sa = np.cumsum(np.array([0]+list(map(int,input().split()))))

@jit
def solve():
    ans = 10**15
    for i in range(1,n-2):
        left = sa[i+1]
        right = sa[-1] - sa[i+1]
        lsplit = min(sa[:i+1].searchsorted(left//2, side="right") - 2, i-1)
        rsplit = min(sa[i+1:].searchsorted(right//2 + left, side="right") + i-1, n-2)
        lleft = [(sa[lsplit + 1],sa[i+1] - sa[lsplit + 1]),(sa[lsplit + 2],sa[i+1] - sa[lsplit + 2])]
        rright = [(sa[rsplit+1] - sa[i+1],sa[-1] - sa[rsplit+1]),(sa[rsplit+2] - sa[i+1],sa[-1] - sa[rsplit+2])]
        for s,t in [(0,0),(0,1),(1,0),(1,1)]:
            l = lleft[s]
            r = rright[t]
            m = min(l+r)
            M = max(l+r)
            ans = min(ans,M-m)
    return ans

print(solve())

Fixed submission:
# arc 100 D

def ruiseki(n,array):
    res = [0]*(n)
    for i in range(n):
        res[i] = res[i-1] + array[i]
    return res

n = int(input())
A = list(map(int,input().split()))
sa = ruiseki(n,A)

ans = 10**15
left_c = 0
right_c = 2
for center in range(1,n-1):
    while left_c+1 < center:
        if abs(sa[center]-2*sa[left_c]) > abs(sa[center]-2*sa[left_c+1]):
            left_c+=1
        else:
            break

    right_c = max(right_c, center+1)
    while right_c+1 < n-1:
        if abs(sa[-1] + sa[center] - 2*sa[right_c]) > abs(sa[-1] + sa[center] - 2*sa[right_c+1]):
            right_c+=1
        else:
            break
    
    x = max(sa[left_c], sa[center]-sa[left_c], sa[right_c]-sa[center], sa[-1]-sa[right_c])
    y = min(sa[left_c], sa[center]-sa[left_c], sa[right_c]-sa[center], sa[-1]-sa[right_c])
    ans = min(ans, x-y)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# arc 100 D

def ruiseki(n,array):
    res = [0]*(n+1)
    for i in range(n):
        res[i+1] = res[i] + array[i]
    return res

n = int(input())
A = list(map(int,input().split()))
sa = ruiseki(n,A)

from bisect import bisect_right

ans = 10**15
for i in range(1,n-2):
    left = sa[i+1]
    right = sa[-1] - sa[i+1]

    lsplit = min(bisect_right(sa[:i+1],left//2) - 2,i-1)
    rsplit = min(bisect_right(sa[i+1:],right//2 + left) + i-1,n-2)
    lleft = [(sa[lsplit + 1],sa[i+1] - sa[lsplit + 1]),(sa[lsplit + 2],sa[i+1] - sa[lsplit + 2])]
    rright = [(sa[rsplit+1] - sa[i+1],sa[-1] - sa[rsplit+1]),(sa[rsplit+2] - sa[i+1],sa[-1] - sa[rsplit+2])]
    for s,t in [(0,0),(0,1),(1,0),(1,1)]:
        l = lleft[s]
        r = rright[t]
        m = min(l+r)
        M = max(l+r)
        ans = min(ans,M-m)

print(ans)




Fixed submission:
# arc 100 D

def ruiseki(n,array):
    res = [0]*(n)
    for i in range(n):
        res[i] = res[i-1] + array[i]
    return res

n = int(input())
A = list(map(int,input().split()))
sa = ruiseki(n,A)

ans = 10**15
left_c = 0
right_c = 2
for center in range(1,n-1):
    while left_c+1 < center:
        if abs(sa[center]-2*sa[left_c]) > abs(sa[center]-2*sa[left_c+1]):
            left_c+=1
        else:
            break

    right_c = max(right_c, center+1)
    while right_c+1 < n-1:
        if abs(sa[-1] + sa[center] - 2*sa[right_c]) > abs(sa[-1] + sa[center] - 2*sa[right_c+1]):
            right_c+=1
        else:
            break
    
    x = max(sa[left_c], sa[center]-sa[left_c], sa[right_c]-sa[center], sa[-1]-sa[right_c])
    y = min(sa[left_c], sa[center]-sa[left_c], sa[right_c]-sa[center], sa[-1]-sa[right_c])
    ans = min(ans, x-y)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# arc 100 D

def ruiseki(n,array):
    res = [0]*(n+1)
    for i in range(n):
        res[i+1] = res[i] + array[i]
    return res

n = int(input())
A = list(map(int,input().split()))
sa = ruiseki(n,A)

from bisect import bisect_right
import itertools
ans = 10**15
for i in range(1,n-2):
    left = sa[i+1]
    right = sa[-1] - sa[i+1]

    lsplit = min(bisect_right(sa[:i+1],left//2) - 2,i-1)
    rsplit = min(bisect_right(sa[i+1:],right//2 + left) + i-1,n-2)
    lleft = [(sa[lsplit + 1],sa[i+1] - sa[lsplit + 1]),(sa[lsplit + 2],sa[i+1] - sa[lsplit + 2])]
    rright = [(sa[rsplit+1] - sa[i+1],sa[-1] - sa[rsplit+1]),(sa[rsplit+2] - sa[i+1],sa[-1] - sa[rsplit+2])]
    for l,r in itertools.product(lleft,rright):
        m = min(l+r)
        M = max(l+r)
        ans = min(ans,M-m)
print(ans)




Fixed submission:
# arc 100 D

def ruiseki(n,array):
    res = [0]*(n)
    for i in range(n):
        res[i] = res[i-1] + array[i]
    return res

n = int(input())
A = list(map(int,input().split()))
sa = ruiseki(n,A)

ans = 10**15
left_c = 0
right_c = 2
for center in range(1,n-1):
    while left_c+1 < center:
        if abs(sa[center]-2*sa[left_c]) > abs(sa[center]-2*sa[left_c+1]):
            left_c+=1
        else:
            break

    right_c = max(right_c, center+1)
    while right_c+1 < n-1:
        if abs(sa[-1] + sa[center] - 2*sa[right_c]) > abs(sa[-1] + sa[center] - 2*sa[right_c+1]):
            right_c+=1
        else:
            break
    
    x = max(sa[left_c], sa[center]-sa[left_c], sa[right_c]-sa[center], sa[-1]-sa[right_c])
    y = min(sa[left_c], sa[center]-sa[left_c], sa[right_c]-sa[center], sa[-1]-sa[right_c])
    ans = min(ans, x-y)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# arc 100 D

def ruiseki(n,array):
    res = [0]*(n+1)
    for i in range(n):
        res[i+1] = res[i] + array[i]
    return res

n = int(input())
A = list(map(int,input().split()))
sa = ruiseki(n,A)

from bisect import bisect_right
import itertools
ans = 10**15
for i in range(1,n-2):
    left = sa[i+1]
    right = sa[-1] - sa[i+1]

    lsplit = min(bisect_right(sa[:i+1],left//2) - 2,i-1)
    rsplit = min(bisect_right(sa[i+1:],right//2 + left) + i-1,n-2)
    lleft = [(sa[lsplit + 1],sa[i+1] - sa[lsplit + 1]),(sa[lsplit + 2],sa[i+1] - sa[lsplit + 2])]
    rright = [(sa[rsplit+1] - sa[i+1],sa[-1] - sa[rsplit+1]),(sa[rsplit+2] - sa[i+1],sa[-1] - sa[rsplit+2])]
    for l,r in itertools.product(lleft,rright):
        m = min(l+r)
        M = max(l+r)
        ans = min(ans,M-m)
print(ans)




Fixed submission:
# arc 100 D

def ruiseki(n,array):
    res = [0]*(n)
    for i in range(n):
        res[i] = res[i-1] + array[i]
    return res

n = int(input())
A = list(map(int,input().split()))
sa = ruiseki(n,A)

ans = 10**15
left_c = 0
right_c = 2
for center in range(1,n-1):
    while left_c+1 < center:
        if abs(sa[center]-2*sa[left_c]) > abs(sa[center]-2*sa[left_c+1]):
            left_c+=1
        else:
            break

    right_c = max(right_c, center+1)
    while right_c+1 < n-1:
        if abs(sa[-1] + sa[center] - 2*sa[right_c]) > abs(sa[-1] + sa[center] - 2*sa[right_c+1]):
            right_c+=1
        else:
            break
    
    x = max(sa[left_c], sa[center]-sa[left_c], sa[right_c]-sa[center], sa[-1]-sa[right_c])
    y = min(sa[left_c], sa[center]-sa[left_c], sa[right_c]-sa[center], sa[-1]-sa[right_c])
    ans = min(ans, x-y)

print(ans)