Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
N = int(input())
A = tuple(map(int, input().split()))

from itertools import accumulate
CA = list(accumulate(A))

mindiff = CA[-1]
for c in range(1,N-2):
    # left side
    p = 0
    q = CA[-1]
    for i in range(0, c):
        pi = CA[i]
        qi = CA[c] - CA[i]
        if abs(pi- qi) < abs(p - q):
            p = pi; q = qi
        else:
            break

    # right side
    r = 0
    s = CA[-1]
    for i in range(c+1, N):
        ri = CA[i] - CA[c]
        si = CA[-1] - CA[i]
        if abs(ri- si) < abs(r - s):
            r = ri; s = si
        else:
            break
    
    mindiff = min(mindiff, max(p, q, r, s) - min(p, q, r, s))
print(mindiff)

# Example run
# Input:
-17880
665
# Output:
665
N = int(input())
A = tuple(map(int, input().split()))

from itertools import accumulate
CA = list(accumulate(A))

mindiff = CA[-1]
left = 0
right = 2
for c in range(1,N-1):
    # left side
    p = CA[left]
    q = CA[c] - CA[left]
    while True:
        pi = CA[left+1]
        qi = CA[c] - CA[left+1]
        if abs(pi- qi) >= abs(p - q):
            break
        p = pi; q = qi
        left += 1

    # right side
    r = CA[right] - CA[c]
    s = CA[-1] - CA[right]
    while True:
        ri = CA[right+1] - CA[c]
        si = CA[-1] - CA[right+1]
        if abs(ri- si) >= abs(r - s):
            break
        r = ri; s = si
        right += 1

    mindiff = min(mindiff, max(p, q, r, s) - min(p, q, r, s))
print(mindiff)

# Example run
# Input:
1
21507
# Output:
21507
# coding: utf-8

from itertools import accumulate

def getAccumulate(A):
    return list(accumulate(A))

def solve(A):
    accum = getAccumulate(A)
    l_index = 0
    r_index = 2
    accum_max = accum[-1]

    diff = accum_max
    for i in range(1, len(A)-2):
        while accum[i] > accum[l_index] + accum[l_index + 1]:
            l_index += 1
        while accum_max + accum[i] > accum[r_index] + accum[r_index + 1]:
            r_index += 1
        
        left = accum[l_index]
        center = accum[i] - accum[l_index]
        right = accum[r_index] - accum[i]
        last = accum_max - accum[r_index]
        diff = min(diff, max(left, center, right, last) - min(left, center, right, last))
        
    return diff

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(A))



# Example run
# Input:
-418
2147483647
# Output:
2147483647
#102_D
N=int(input())
A=list(map(int,input().split()))
s=0
AS=[]
for i in range(N):
    s+=A[i]
    AS.append(s)
#尺取り法
Ans=AS[N-1]+1
L=0
R=2
for Mid in range(1,N-2):
    Sum_L=AS[Mid]
    Sum_R=AS[N-1]-Sum_L
    while abs(Sum_L-2*AS[L])>abs(Sum_L-2*AS[L+1]):
        L+=1
    
    while R<=N-3 and abs(AS[N-1]-2*AS[R]+AS[Mid])>abs(AS[N-1]-2*AS[R+1]+AS[Mid]):
        R+=1
    P=AS[L]
    Q=AS[Mid]-AS[L]
    S=AS[R]-AS[Mid]
    T=AS[N-1]-AS[R]
    #print(Mid,L,R,abs(max(P,Q,S,T)-min(P,Q,S,T)))
    Ans=min(Ans,abs(max(P,Q,S,T)-min(P,Q,S,T)))
print(Ans)

# Example run
# Input:
1
497083553
# Output:
497083554
#!/usr/bin/env python
from itertools import accumulate as ac
N = int(input())
A = list(ac(map(int, input().split())))
l, r, t = 0, 2, A[-1]
c = t
print(A)
print(A[1:-2])
for m in A[1:-2]:
    while t+m > A[r]+A[r+1]:
        r += 1
    while m > A[l]+A[l+1]:
        l += 1
    x = sorted([A[l],m-A[l],A[r]-m,t-A[r]])
    c = min(c,x[-1]-x[0])
print(c)


# Example run
# Input:
-160045822
155287
# Output:
[155287]
[]
155287
def equal_cut(N: int, A: list) -> int:
    Sa = [0] * (N + 1)  # A の累積和
    for i, a in enumerate(A):
        Sa[i + 1] = Sa[i] + a

    li, ri = 1, 3
    ans = float('inf')
    for mi in range(2, N - 1):
        # 中心の区切り mi を固定して左右の区間内で最適な
        # 区切り位置 li, ri を決めていく
        # B, C, D, E = A[:li], A[li:mi], A[mi:ri], A[ri:]
        if ri <= mi:
            ri = mi + 1

        # 適切な li を決める
        for temp_li in range(li + 1, mi):
            P, Q = Sa[temp_li - 1], Sa[mi] - Sa[temp_li - 1]
            nP, nQ = Sa[temp_li], Sa[mi] - Sa[temp_li]

            if abs(nP - nQ) <= abs(P - Q):
                # nP と nQ が近くなら li を更新する
                li = temp_li
            else:
                # nP と nQ が遠ざかり始めたらこれ以上 li を
                # 右に移動しても差は広がる一方で探索する意味
                # がないので打ち切り
                break

        # 適切な ri を決める
        for temp_ri in range(ri + 1, N):
            R, S = Sa[temp_ri - 1] - Sa[mi], Sa[N] - Sa[temp_ri - 1]
            nR, nS = Sa[temp_ri] - Sa[mi], Sa[N] - Sa[temp_ri]

            if abs(nR - nS) <= abs(R - S):
                ri = temp_ri
            else:
                break

        P = Sa[li]
        Q = Sa[mi] - Sa[li]
        R = Sa[ri] - Sa[mi]
        S = Sa[N] - Sa[ri]
        temp = max(P, Q, R, S) - min(P, Q, R, S)

        if temp < ans:
            ans = temp

    return ans


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = equal_cut(N, A)
    print(ans)


# Example run
# Input:
44
51426
# Output:
0
def solve():
    N = int(input())
    A = tuple(map(int, input().split()))

    from itertools import accumulate
    CA = list(accumulate(A))

    mindiff = CA[-1]
    for c in range(1,N-2):
        # left side
        p = 0
        q = CA[-1]
        for i in range(0, c):
            pi = CA[i]
            qi = CA[c] - CA[i]
            if abs(pi- qi) < abs(p - q):
                p = pi; q = qi
            else:
                break

        # right side
        r = 0
        s = CA[-1]
        for i in range(c+1, N):
            ri = CA[i] - CA[c]
            si = CA[-1] - CA[i]
            if abs(ri- si) < abs(r - s):
                r = ri; s = si
            else:
                break
    
        mindiff = min(mindiff, max(p, q, r, s) - min(p, q, r, s))
    return mindiff
print(solve())

# Example run
# Input:
-4953150
3320259
# Output:
3320259
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def calc(n):
    s = sum(map(int, str(n)))
    return n / s

def main():
    k = ri()
    cand = list(range(1, 10))
    last = 9
    for n in range(1, 15):
        pow10n = pow(10, n)
        for d in range(1, 10):
            lim = (d+1)*pow10n
            e = 0
            while True:
                e1 = d*pow10n+e*(last+1)+last
                if e1 >= lim:
                    break
                e2 = e1 + (last+1)
                if calc(e1) > calc(e2):
                    last = last*10+9
                    e = 0
                    continue
                cand.append(e1)
                e += 1
    print("\n".join(map(str, cand[:k])))


if __name__ == '__main__':
    main()

"""
1 1.0
2 1.0
3 1.0
4 1.0
5 1.0
6 1.0
7 1.0
8 1.0
9 1.0
19 1.9
29 2.6363636363636362
39 3.25
49 3.769230769230769
59 4.214285714285714
69 4.6
79 4.9375
89 5.235294117647059
99 5.5
199 10.473684210526315
299 14.95
399 19.0
499 22.681818181818183
599 26.043478260869566
699 29.125
799 31.96
899 34.57692307692308
999 37.0
1099 57.8421052631579
1199 59.95
1299 61.857142857142854
1399 63.59090909090909
1499 65.17391304347827
1599 66.625
1699 67.96
1799 69.1923076923077
1899 70.33333333333333
1999 71.39285714285714
2999 103.41379310344827
3999 133.3
4999 161.25806451612902
5999 187.46875
6999 212.0909090909091
7999 235.26470588235293
8999 257.1142857142857
9999 277.75
10999 392.82142857142856
11999 413.7586206896552
12999 433.3
13999 451.5806451612903
14999 468.71875
15999 484.8181818181818
16999 499.97058823529414
17999 514.2571428571429
18999 527.75
19999 540.5135135135135
20999 724.1034482758621
21999 733.3
22999 741.9032258064516
23999 749.96875
24999 757.5454545454545
25999 764.6764705882352
26999 771.4
27999 777.75
28999 783.7567567567568
29999 789.4473684210526
39999 1025.6153846153845
49999 1249.975
59999 1463.3902439024391
69999 1666.642857142857
79999 1860.4418604651162
89999 2045.4318181818182
99999 2222.2
109999 2972.945945945946
119999 3157.8684210526317
129999 3333.3076923076924
139999 3499.975
149999 3658.512195121951
159999 3809.5
169999 3953.4651162790697
179999 4090.8863636363635
189999 4222.2
199999 4347.804347826087
209999 5526.289473684211
219999 5641.0
229999 5749.975
239999 5853.634146341464
249999 5952.357142857143
259999 6046.488372093023
269999 6136.340909090909
279999 6222.2
289999 6304.326086956522
299999 6382.95744680851
309999 7948.692307692308
319999 7999.975
329999 8048.756097560976
339999 8095.214285714285
349999 8139.511627906977
359999 8181.795454545455
369999 8222.2
379999 8260.847826086956
389999 8297.851063829787
399999 8333.3125
499999 10204.061224489797
599999 11999.98
699999 13725.470588235294
799999 15384.596153846154
899999 16981.11320754717
999999 18518.5
"""


# Example run
# Input:
0
# Output:
from itertools import accumulate

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

A=[0]+list(accumulate(A))
ans=A[N]
for j in range(2,N-1):
    S=A[j]-A[0]
    start=1
    end=j-1
    while end-start>1:
        t=(end+start)//2
        if S>=2*A[t]:
            start=t
        else:
            end=t
    i1=start
    i2=end

    T=A[N]-A[j]
    start=j+1
    end=N-1
    while end-start>1:
        t=(end+start)//2
        if T>=2*(A[t]-A[j]):
            start=t
        else:
            end=t

    k1=start
    k2=end

    data=[A[N]-A[k1],A[k1]-A[j],A[j]-A[i1],A[i1]-A[0]]
    test1=max(data)-min(data)

    data=[A[N]-A[k2],A[k2]-A[j],A[j]-A[i1],A[i1]-A[0]]
    test2=max(data)-min(data)

    data=[A[N]-A[k1],A[k1]-A[j],A[j]-A[i2],A[i2]-A[0]]
    test3=max(data)-min(data)

    data=[A[N]-A[k2],A[k2]-A[j],A[j]-A[i2],A[i2]-A[0]]
    test4=max(data)-min(data)

    ans=min(ans,test1,test2,test3,test4)

print(ans)

# Example run
# Input:
1
170984
# Output:
170984
# 2つの部分列に分ける
def eqcut(start, end, prev):
    prev_diff = abs(2 * cumA[prev] - cumA[start - 1] - cumA[end])
    for i in range(prev + 1, end + 1):
        diff = abs(2 * cumA[i] - cumA[start - 1] - cumA[end])
        if diff > prev_diff: break
        prev_diff = diff
    return i - 1

N = int(input())
A = [int(x) for x in input().split()]

cumA = [A[0]] + [0] * N  # 累積和  cumA[-1] = 0となるように最後にダミー
for i in range(1, N):
    cumA[i] = cumA[i - 1] + A[i]

S = [0, 0, 0, 0]
B = [0, 0]
ans = cumA[N - 1]
# 3本の境界線のうち中央を探す
for i in range(1, N - 2):
    B[0] = eqcut(0, i, B[0])  # A[0], ..., A[i]を要素の総和が最小となる2つの部分列に分ける
    S[0] = cumA[B[0]]
    S[1] = cumA[i] - cumA[B[0]]

    B[1] = eqcut(i + 1, N - 1, B[1])
    S[2] = cumA[B[1]] - cumA[i]
    S[3] = cumA[N - 1] - cumA[B[1]]

    ans = min(ans, max(S) - min(S))

print(ans)

# Example run
# Input:
0
-5
# Output:
-5
##https://beta.atcoder.jp/contests/abc102/submissions/2779056
n = int(input())
a = list(map(int, input().split()))
s = [a[0]]
for i in range(n-1):
    s.append(s[i] + a[i+1])
ans = s[n-1]

##i,j,kは左側の区間の右端
##iは1からN-3まで
j = 0
k = 2             
for i in range(1, (n - 3) + 1):
    ##BC(i)DE
    ##BCの区間[0, i]: 最低でも2要素→0,1を取るのでi=1から
    ##DEの区間[i+1, N-1]: 最低でも2要素→N-2, N-1を取るので、i+1=N-2よりi=N-3まで

    ##B(j)C(i)DE
    #Bの区間[0, j]
    #Cの区間[j+1, i]
    ##sumB = s[j]
    ##sumC = s[i] - s[j]
    while abs(s[i] - 2 * s[j]) > abs(s[i] - 2 * s[j+1]):
        j += 1

    ##B(j)C(i)D(k)E
    #Dの区間[i+1, k]
    #Eの区間[k+1, N-1]
    ##sumD = s[k] - s[i]
    ##sumE = s[N-1] - s[k]
    while abs(s[n-1] - 2 * s[k] + s[i]) > abs(s[n-1] - 2 * s[k+1] + s[i]):
        k += 1
             
    pqrs = list((s[j],s[i]-s[j],s[k]-s[i],s[n-1]-s[k]))
    ans = min(ans, max(pqrs) - min(pqrs))
print(ans)

# Example run
# Input:
1
-816653
# Output:
-816653
N = int(input())
A_l = list(map(int, input().split()))

import itertools
sp_l = list(itertools.combinations(range(N-1), 3))

calc_l = []

for i,j,k in sp_l:
    
    P = sum(A_l[:i+1])
    Q = sum(A_l[i+1:j+1])
    R = sum(A_l[j+1:k+1])
    S = sum(A_l[k+1:])

    calc_l.append(abs(max(P,Q,R,S) - min(P,Q,R,S)))

print(min(calc_l))

# Example run
# Input:
8
1
# Output:
1
from itertools import accumulate


def run(n, a):
    # sum_a = [sum(a[0:i+1]) for i in range(n)]
    sum_a = list(accumulate(a))
    li = 0
    ri = 2
    t = sum_a[-1]
    diff = sum_a[-1]
    # 真ん中の切れ込みを順に変更
    # 左の切れ込みの位置はiに対して単調増加
    # 左の切れ込みで真ん中の項を移動するかどうかは、
    # 真ん中の項を除いて、小さい方に入れる
    # ただし単調増加なので、左の切れ込みの左側が
    # 小さいときに真ん中を左の切れ込みの左側に入れる
    # 右も同様に考える
    for i in range(1, n-2):
        while sum_a[i] > sum_a[li+1] + sum_a[li]:
            li += 1
        while t + sum_a[i] > sum_a[ri+1] + sum_a[ri]:
            ri += 1
        p = sum_a[li]
        q = sum_a[i] - p
        r = sum_a[ri] - q - p
        s = t - sum_a[ri]
        diff = min(diff, max(p, q, r, s) - min(p, q, r, s))
    return diff


def read_line():
    n = int(input())
    a = list(map(int, input().split()))
    return (n, a)


def main():
    n, a = read_line()
    print(run(n, a))


if __name__ == '__main__':
    main()


# Example run
# Input:
-56556289
12039
# Output:
12039
N = int(input())
A = list(map(int, input().split()))

arrSum = list(sum(A[:idx+1]) for idx in range(N))

ans = float('inf')
##2分する区切り目の左のインデックスi: 1 ～ (N - 3)
for i in range(1, (N - 3) + 1):
    ##左側の区間の右端はi番目まである
    ##区切り目の左のインデックスj: 0 ～ (i - 1)
    buf = float('inf')
    for j in range(i):
        sumB = arrSum[j]
        sumC = arrSum[i] - arrSum[j]
        d = sumB - sumC
        if buf > abs(d):
            buf = abs(d)
            P = sumB
            Q = sumC
    ##右側の区間の左端は(i + 1)番目
    ##区切り目の左のインデックスk: (i + 1) ～ (N - 2)
    buf = float('inf')
    for k in range((i + 1), (N - 2) + 1):
        sumD = arrSum[k] - arrSum[i]
        sumE = arrSum[N-1] - arrSum[k]
        d = sumD - sumE
        if buf > abs(d):
            buf = abs(d)
            R = sumD
            S = sumE
    arr = list((P, Q, R, S))
    ans = min(ans, max(arr) - min(arr))
print(ans)

# Example run
# Input:
56
1049999
# Output:
1049999
N = int(input())
A = list(map(int, input().split()))

answer = 10 ** 9
for i in range(1, N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            p = sum(A[0:i])
            q = sum(A[i:j])
            r = sum(A[j:k])
            s = sum(A[k:])
            #print(A[0:i], A[i:j], A[j:k], A[k:])

            max_ = max([p, q, r, s])
            min_ = min([p, q, r, s])
            #print('max, min:', max_, min_)

            #print(abs(max_-min_))
            answer = min(answer, abs(max_-min_))

print(answer)

# Example run
# Input:
-277733976
-813
# Output:
1000000000
N=int(input())
A=list(map(int, input().split()))

ans=999999999
for a in range(1,N-2):
    for b in range(a+1,N-1):
        for c in range(b+1,N):
            num=[sum(A[:a]),sum(A[a:b]),sum(A[b:c]),sum(A[c:])]
            n=max(num)-min(num)
            if n<ans: ans=n
print(ans)

# Example run
# Input:
-4132772
22158
# Output:
999999999
# https://atcoder.jp/contests/abc102/tasks/arc100_b

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def main():
    n = int(input())
    al = list(map(int, input().split()))

    l, c, r = 1, 2, 3
    P = sum(al[:l])
    Q = sum(al[l:c])
    R = sum(al[c:r])
    S = sum(al[r:])

    ans = max(P, Q, R, S) - min(P, Q, R, S)

    while c <= n - 2:
        while True:
            if abs(P - Q) < abs((P + al[l]) - (Q - al[l])):  # これ以上差が縮まらないなら break
                break

            if l == c - 1:
                break

            P += al[l]
            Q -= al[l]
            l += 1

        while True:
            if abs(R - S) < abs((R + al[r]) - (S - al[r])): # これ以上差が縮まらないなら break
                break
            if r == n - 1:
                break

            R += al[r]
            S -= al[r]
            r += 1

        ans = min(max(P, Q, R, S) - min(P, Q, R, S), ans)

        # center を一つ右に進める
        Q += al[c]
        R -= al[c]
        c += 1

    print(ans)

if __name__ == '__main__':
    main()


# Example run
# Input:
-62350830
260615611
# Output:
260615611
n = int(input())
arr_ia = list(map(int,input().split()))

tmp_arr = [0,0,0,0]
res = 1000000000

for p1 in range(1,n-2):
    tmp_arr[0] = sum(arr_ia[:p1])
    for p2 in range(p1,n-1):
        tmp_arr[1] = sum(arr_ia[p1:p2])
        for p3 in range(p2,n):
            tmp_arr[2] = sum(arr_ia[p2:p3])
            tmp_arr[3] = sum(arr_ia[p3:])
            
            res_arr = sorted(tmp_arr)
            tmp_res = res_arr[-1]-res_arr[0]
            if(res > tmp_res):
                res = tmp_res
            
print(res)

# Example run
# Input:
-6163826
139893
# Output:
1000000000
from bisect import bisect_left, bisect_right
from itertools import accumulate

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

ans=A_sum[N-1]
for m in range(2,N-1):
  sum_left=A_sum[m-1]
  i=bisect_left(A_sum,sum_left/2)
  sum1=A_sum[i]
  if i!=0:
    if A_sum[i]+A_sum[i-1]>sum_left:
      sum1=A_sum[i-1]
  sum2=sum_left-sum1

  sum_right=A_sum[N-1]-sum_left
  i=bisect_left(A_sum,sum_left+sum_right/2)
  sum3=A_sum[i]-sum_left
  if i!=m:
    if A_sum[i]+A_sum[i-1]-2*sum_left>sum_right:
      sum3=A_sum[i-1]-sum_left
  sum4=sum_right-sum3
  max_sum=max(sum1,sum2,sum3,sum4)
  min_sum=min(sum1,sum2,sum3,sum4)
  dif=max_sum-min_sum
  if dif<ans:
    ans=dif

print(ans)

# Example run
# Input:
0
-202544
# Output:
-202544
N = int(input())
A = [0] + list(map(int, input().split()))
for i in range(1, N + 1):
    A[i] += A[i - 1]


# print (A)

ans = 10 ** 9

#基準を求める
stan = A[N]//4

for i in range(2 ** 3):
    PQRS = [0, 0, 0, 0]
    index = 1
    prev_index = 0
    for j in range(3):
        if (i >> j) & 1: #基準以上にするとき
            while A[index] - A[prev_index] < stan and index < N:
                index += 1
            PQRS[j] = A[index] - A[prev_index]
            prev_index = index
            # print (1, end = '')
        else: #基準以下にするとき
            while A[index] - A[prev_index] < stan and index < N:
                index += 1
            PQRS[j] = A[index - 1] - A[prev_index]
            prev_index = index - 1
            # print (0, end = '')
    PQRS[3] = A[N] - A[prev_index]
    # print (PQRS, end = ' ')
    # print (max(PQRS) - min(PQRS))
    ans = min((max(PQRS) - min(PQRS)), ans)

stan = (A[N] + 3)//4

for i in range(2 ** 3):
    PQRS = [0, 0, 0, 0]
    index = 1
    prev_index = 0
    for j in range(3):
        if (i >> j) & 1: #基準以上にするとき
            while A[index] - A[prev_index] < stan and index < N:
                index += 1
            PQRS[j] = A[index] - A[prev_index]
            prev_index = index
            # print (1, end = '')
        else: #基準以下にするとき
            while A[index] - A[prev_index] < stan and index < N:
                index += 1
            PQRS[j] = A[index - 1] - A[prev_index]
            prev_index = index - 1
            # print (0, end = '')
    PQRS[3] = A[N] - A[prev_index]
    # print (PQRS, end = ' ')
    # print (max(PQRS) - min(PQRS))
    ans = min((max(PQRS) - min(PQRS)), ans)


print (ans)

# Example run
# Input:
1
0
# Output:
0
n = int(input())
a = list(map(int, input().split()))
res = 20000000002
for k in range(n-3):
    for l in range(k+1,n-2):
        for m in range(l+1,n-1):
            f = [sum(a[:k+1]),sum(a[k+1:l+1]),sum(a[l+1:m+1]),sum(a[m+1:])]
            kari = max(f)-min(f)
            if kari < res: res = kari
print(res)


# Example run
# Input:
-39645188
-202
# Output:
20000000002
# coding: utf-8
# Your code here!

N = int(input())
A = list(map(int, input().split(" ")))
Acc = []
a = 0
for i in range(N):
    a += A[i]
    Acc.append(a)
print(A)
print(Acc)

def centerPoint(L):
    diff = 10000000000
    p = 0
    for i in range(len(L)):
        if abs(L[i] - (L[-1] - L[i])) < diff:
            diff = abs(L[i] - (L[-1] - L[i]))
            p = i
    return p
ret = 10000000000
for i in range(2, len(A)-1):
    p1 = centerPoint(Acc[:i])
    temp = list(map(lambda x: x - Acc[i-1], Acc[i:]))
    p2 = centerPoint(temp)
    # print(Acc[:i],temp)
    s1 = Acc[p1]
    s2 = Acc[i-1] - Acc[p1]
    s3 = Acc[p2+i] - Acc[i-1]
    s4 = Acc[-1] - Acc[p2+i]
    # print(s1,s2,s3,s4)
    # print(max(s1,s2,s3,s4) - min(s1,s2,s3,s4))
    if max(s1,s2,s3,s4) - min(s1,s2,s3,s4) < ret:
        ret = max(s1,s2,s3,s4) - min(s1,s2,s3,s4)
print(ret)

# Example run
# Input:
0
-17760757
# Output:
[-17760757]
[]
10000000000
N = int(input())
A = list(map(int, input().split()))

ans=sum(A)
for a in range(3,N):
  for b in range(2,a):
    for c in range(1,b):
      sum1=sum(A[:c])
      sum2=sum(A[c:b])
      sum3=sum(A[b:a])
      sum4=sum(A[a:])
      dif=max(sum1,sum2,sum3,sum4)-min(sum1,sum2,sum3,sum4)
      if dif<ans:
        ans=dif

print(ans)

# Example run
# Input:
-7737
-126905272
# Output:
-126905272
N=int(input())
 
A=list(map(int,input().split()))
 
fourdivide=sum(A)//4
P=Q=R=S=0
Pflag=Qflag=Rflag=0
Pindex=Qindex=Rindex=0
Ppre=Qpre=Rpre=Spre=0
answer=10**9

def intr(a,b,c):
	global answer
	d=sum(A)-a-b-c
	answer=min(answer,max(a,b,c,d)-min(a,b,c,d))
	print(a,b,c,d)

for i in range(N):
	if Pflag==0 and i<=N-4:
		P+=A[i]
		if P>=fourdivide:
			Pflag=1
			Pindex=i
			if i!=0:
				Ppre=P-A[i]
	elif Qflag==0 and i<=N-3:
		Q+=A[i]
		if Q>=fourdivide:
			Qflag=1
			Qindex=i
			Qpre=Q-A[i]
	elif Rflag==0 and i<=N-2:
		R+=A[i]
		if R>=fourdivide:
			Rflag=1
			Rindex=i
			Rpre=R-A[i]            

intr(P,Q,R)
if Rpre!=0:
	intr(P,Q,Rpre)
Rflag=0
QpreR=QpreRpre=0

for i in range(Qindex,N):
	if Rflag==0 and i<=N-2:
		QpreR+=A[i]
		if QpreR>=fourdivide:
			Rflag=1
			Rindex=i
			QpreRpre=QpreR-A[i]

if Qpre!=0 and QpreR!=0:
	intr(P,Qpre,QpreR)
if Qpre!=0 and QpreRpre!=0:
	intr(P,Qpre,QpreRpre)

Qflag=0
Rflag=0
PpreQ=PpreQpre=0
PpreR=PpreRpre=0

if Ppre!=0:
	for i in range(Pindex,N):
		if Qflag==0 and i<=N-3:
			PpreQ+=A[i]
			if PpreQ>=fourdivide:
				Qflag=1
				Qindex=i
				PpreQpre=PpreQ-A[i]
		elif Rflag==0 and N-2:
			PpreR+=A[i]
			if PpreR>=fourdivide:
				Rflag=1
				Rindex=i
				PpreRpre=PpreR-A[i]
	if Ppre!=0 and PpreQ!=0 and PpreR!=0:
		intr(Ppre,PpreQ,PpreR)
	if Ppre!=0 and PpreQ!=0 and PpreRPre!=0:
		intr(Ppre,PpreQ,PpreRpre)
	Rflag=0
	PpreQpreR=PpreQpreRpre=0
	for i in range(Qindex,N):
		if Rflag==0 and i<=N-2:
			PpreQpreR+=A[i]
			if PpreQpreR>=fourdivide:
				Rflag=1
				Rindex=i
				PpreQpreRpre=PpreQpreR-A[i]
	if Ppre!=0 and PpreQpre!=0 and PpreQpreR!=0:
		intr(Ppre,PpreQpre,PpreQpreR)
	if Ppre!=0 and PpreQpre!=0 and PpreQpreRpre!=0:
		intr(Ppre,PpreQpre,PpreQpreRpre)
      



print(answer)

# Example run
# Input:
-17168490
-462574
# Output:
0 0 0 -462574
462574
from bisect import bisect_left

N = int(input())
A = [int(i) for i in input().split()]

s = sum(A)
for i in range(1, N) :
    A[i] += A[i-1]


def check(d) :
    ifr = bisect_left(A, (s - 3 * d) // 4)
    ito = bisect_left(A, (s + 3 * d) // 4)
    for i in range(ifr, min(N, ito + 1)) :
        jfr = bisect_left(A, A[i] + (s - A[i] - 2 * d) // 3)
        jto = bisect_left(A, A[i] + (s - A[i] + 2 * d) // 3)
        for j in range(max(i + 1, jfr), min(N, jto + 1)) :
            kfr = bisect_left(A, A[j] + (s - A[j] - d) // 2)
            kto = bisect_left(A, A[j] + (s - A[j] + d) // 2)
            for k in range(max(j + 1, kfr), min(N - 1, kto + 1)) :
                cut = [A[i], A[j] - A[i], A[k] - A[j], s - A[k]]
                if max(cut) - min(cut) <= d :
                    return True
    return False

ng, ok = 0, s
while ok - ng > 1 :
    mid = (ng + ok) // 2
    
    if check(mid) :
        ok = mid
    else :
        ng = mid

print(ok)

# Example run
# Input:
0
227
# Output:
227
N = int(input())
A = list(map(int, input().split()))
s = 0
S = [0]*N
for i, a in enumerate(A):
    s += a
    S[i] = s

t = S[-1]
ans = 10**20
j = 0
k = 2
for i in range(1,N-2):
    s = S[i]
    while abs(s-2*S[j+1]  ) < abs(s-2*S[j]  ): j+=1
    while abs(t-2*S[k+1]+s) < abs(t-2*S[k]+s): k+=1
    
    v = (S[j], s-S[j], S[k]-s, t-S[k])
    ans = min(ans, max(v)-min(v))
    
    #print(i,j,k, v)
print(ans)

# Example run
# Input:
386945
3485
# Output:
0
N = int(input())
A = list(map(int, input().split()))
ans = pow(10,10)
for i in range(1, N - 2):
	for j in range(i + 1, N - 1):
		for k in range(j + 1, N):
			B = list(A[:i])
			C = list(A[i:j])
			D = list(A[j:k])
			E = list(A[k:])
			P = sum(B)
			Q = sum(C)
			R = sum(D)
			S = sum(E)
			ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))
print(ans)


# Example run
# Input:
-10318344
214
# Output:
10000000000