Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()

def min_max(arr):
    """リストの中を二つに分けて、総和の小さい方と大きい方を返す"""
    left = 0; right = len(arr)-1
    l_total = arr[left]
    r_total = arr[right]
    while left + 1 < right:
        if l_total <= r_total:
            left += 1
            l_total += arr[left]
        else:
            right -= 1
            r_total += arr[right]
    mi, ma = min(l_total, r_total), max(l_total, r_total)
    return mi, ma

answer = 10 ** 15
mid = N // 2
used = set([0, 1, N-1])

def F(l, mid, r):
    global answer, used
    used.add(mid)
    l_min, l_max = min_max(A[:mid])
    r_min, r_max = min_max(A[mid:])
    temp = max(l_max, r_max) - min(l_min, r_min)
    if temp < answer:
        answer = temp
    if l_min <= r_min:
        m = (mid+r)//2
        if m not in used:
            F(mid, m, r)
    else:
        m = (mid+l)//2
        if m not in used:
            F(l, m, mid)
    if l_max >= r_max:
        m = (mid+l)//2
        if m not in used:
            F(l, m, mid)
    else:
        m = (mid+r)//2
        if m not in used:
            F(mid, m, r)

F(0, mid, N-1)
print(answer)
# 08

Fixed submission:
# coding: utf-8
import sys
from itertools import accumulate

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
Acum = list(accumulate(A))
l_cut = [None] * N  # 左のリストで2つに切り分けるindex
l_cut[1] = 0
l = A[0]; r = A[1]
for i in range(2, N):
    r += A[i]
    diff = abs(r-l)
    index = l_cut[i-1]
    while index < i - 1:
        temp = abs(l + A[index+1] - (r - A[index+1]))
        if temp < diff:
            index += 1
            l += A[index]
            r -= A[index]
            diff = temp
        else:
            break
    l_cut[i] = index

r_cut = [None] * N
r_cut[-2] = N-2
l = A[-2]; r = A[-1]
for i in range(N-3, 0, -1):
    l += A[i]
    diff = abs(r-l)
    index = r_cut[i+1]
    while index > i:
        temp = abs(r + A[index] - (l - A[index]))
        if temp < diff:
            index -= 1
            r += A[index+1]
            l -= A[index+1]
            diff = temp
        else:
            break
    r_cut[i] = index

answer = 10 ** 17
for i in range(1, N-2):
    a = Acum[l_cut[i]]
    b = Acum[i] - a
    c = Acum[r_cut[i+1]] - Acum[i]
    d = Acum[-1] - (a + b + c)
    temp = max(a, b, c, d) - min(a, b, c, d)
    if temp < answer:
        answer = temp

print(answer)
# 27r

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()

def min_max(arr):
    """リストの中を二つに分けて、総和の小さい方と大きい方を返す"""
    left = 0; right = len(arr)-1
    l_total = arr[left]
    r_total = arr[right]
    while left + 1 < right:
        if l_total <= r_total:
            left += 1
            l_total += arr[left]
        else:
            right -= 1
            r_total += arr[right]
    mi, ma = min(l_total, r_total), max(l_total, r_total)
    return mi, ma

answer = 10 ** 15
mid = N // 2
used = set()

def F(l, mid, r):
    global answer, used
    used.add(mid)
    l_min, l_max = min_max(A[:mid])
    r_min, r_max = min_max(A[mid:])
    temp = max(l_max, r_max) - min(l_min, r_min)
    if temp < answer:
        answer = temp
    if l_min <= r_min:
        m = (mid+r)//2
        if m not in used:
            F(mid, m, r)
    else:
        m = (mid+l)//2
        if m not in used:
            F(l, m, mid)
    if l_max >= r_max:
        m = (mid+l)//2
        if m not in used:
            F(l, m, mid)
    else:
        m = (mid+r)//2
        if m not in used:
            F(mid, m, r)

F(0, mid, N-1)
print(answer)
# 08

Fixed submission:
# coding: utf-8
import sys
from itertools import accumulate

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
Acum = list(accumulate(A))
l_cut = [None] * N  # 左のリストで2つに切り分けるindex
l_cut[1] = 0
l = A[0]; r = A[1]
for i in range(2, N):
    r += A[i]
    diff = abs(r-l)
    index = l_cut[i-1]
    while index < i - 1:
        temp = abs(l + A[index+1] - (r - A[index+1]))
        if temp < diff:
            index += 1
            l += A[index]
            r -= A[index]
            diff = temp
        else:
            break
    l_cut[i] = index

r_cut = [None] * N
r_cut[-2] = N-2
l = A[-2]; r = A[-1]
for i in range(N-3, 0, -1):
    l += A[i]
    diff = abs(r-l)
    index = r_cut[i+1]
    while index > i:
        temp = abs(r + A[index] - (l - A[index]))
        if temp < diff:
            index -= 1
            r += A[index+1]
            l -= A[index+1]
            diff = temp
        else:
            break
    r_cut[i] = index

answer = 10 ** 17
for i in range(1, N-2):
    a = Acum[l_cut[i]]
    b = Acum[i] - a
    c = Acum[r_cut[i+1]] - Acum[i]
    d = Acum[-1] - (a + b + c)
    temp = max(a, b, c, d) - min(a, b, c, d)
    if temp < answer:
        answer = temp

print(answer)
# 27r