from itertools import *

n=int(eval(input()))

sumA=[0]+list(accumulate(list(map(int,input().split()))))

def check(l,m,r):

    if m==r:return False

    tmp=sumA[r]+sumA[l]

    return abs(tmp-sumA[m+1]*2)<abs(tmp-sumA[m]*2)

res=float('inf')

li,ri=1,3

for mid in range(2,n-1):

    while check(0,li,mid):li+=1

    while check(mid,ri,n):ri+=1

    x=sorted([sumA[li],sumA[mid]-sumA[li],sumA[ri]-sumA[mid],sumA[n]-sumA[ri]])

    tmp=x[3]-x[0]

    if tmp<res:res=tmp

print(res)
from itertools import *

eval(input())

s=list(accumulate(list(map(int,input().split()))))

l,r,t=0,2,s[-1];a=t

for m in s[1:-2]:

    while abs(t-2*s[r]+m)>abs(t-2*s[r+1]+m):r+=1

    while abs(m-2*s[l])>abs(m-2*s[l+1]):l+=1

    x=sorted([s[l],m-s[l],s[r]-m,t-s[r]])

    a=min(a,x[3]-x[0])

print(a)
from itertools import *

n = int(eval(input()))
sumA = [0] + list(accumulate(list(map(int, input().split()))))


def check(l, m, r):
    if m == r:
        return False
    tmp = sumA[r] + sumA[l]
    return abs(tmp - sumA[m + 1] * 2) < abs(tmp - sumA[m] * 2)


res = float("inf")
li, ri = 1, 3
for mid in range(2, n - 1):
    while check(0, li, mid):
        li += 1
    while check(mid, ri, n):
        ri += 1
    x = sorted(
        [sumA[li], sumA[mid] - sumA[li], sumA[ri] - sumA[mid], sumA[n] - sumA[ri]]
    )
    tmp = x[3] - x[0]
    if tmp < res:
        res = tmp
print(res)

from itertools import *

eval(input())
s = list(accumulate(list(map(int, input().split()))))
l, r, t = 0, 2, s[-1]
a = t
for m in s[1:-2]:
    while abs(t - 2 * s[r] + m) > abs(t - 2 * s[r + 1] + m):
        r += 1
    while abs(m - 2 * s[l]) > abs(m - 2 * s[l + 1]):
        l += 1
    x = sorted([s[l], m - s[l], s[r] - m, t - s[r]])
    a = min(a, x[3] - x[0])
print(a)

-n = int(eval(input())) -sumA = [0] + list(accumulate(list(map(int, input().split())))) - - -def check(l, m, r): -    if m == r: -        return False -    tmp = sumA[r] + sumA[l] -    return abs(tmp - sumA[m + 1] * 2) < abs(tmp - sumA[m] * 2) - - -res = float("inf") -li, ri = 1, 3 -for mid in range(2, n - 1): -    while check(0, li, mid): -        li += 1 -    while check(mid, ri, n): -        ri += 1 -    x = sorted( -        [sumA[li], sumA[mid] - sumA[li], sumA[ri] - sumA[mid], sumA[n] - sumA[ri]] -    ) -    tmp = x[3] - x[0] -    if tmp < res: -        res = tmp -print(res) +eval(input()) +s = list(accumulate(list(map(int, input().split())))) +l, r, t = 0, 2, s[-1] +a = t +for m in s[1:-2]: +    while abs(t - 2 * s[r] + m) > abs(t - 2 * s[r + 1] + m): +        r += 1 +    while abs(m - 2 * s[l]) > abs(m - 2 * s[l + 1]): +        l += 1 +    x = sorted([s[l], m - s[l], s[r] - m, t - s[r]]) +    a = min(a, x[3] - x[0]) +print(a)