# ARC100D



import sys

input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(max(1000, 10**9))





# import numpy as np

import bisect

n = int(eval(input()))

a = list(map(int, input().split()))

# a = np.array(list(map(int, input().split())))

ca = [None] * n #ca[i] = a0~aiの和

s = 0

for i,num in enumerate(a):

    s += a[i]

    ca[i] = s

# ca = a.cumsum()



def sub(l, start, end, init):

    if len(l)==0:

        return 0,0

    elif end-start==1:

        return 0,l[start]-init

    target = (init + l[end-1])/2

    i = bisect.bisect_right(l, target)

    p1 = (l[i]-init, l[end-1]-l[i])

    p2 = (l[i-1]-init, l[end-1]-l[i-1])

    if abs(p1[0] - p1[1]) < abs(p2[0] - p2[1]):

        return min(p1), max(p1)

    else:

        return min(p2), max(p2)

best = 10**15

for i in range(1,n):

    p1 = sub(ca, 0, i, 0)

    p2 = sub(ca, i, n, ca[i-1])

    nn = max(p1[1]-p2[0], p2[1]-p1[0], p1[1]-p1[0], p2[1]-p2[0])

#     print(p1,p2,nn)

    best = min(best, nn)

print(best)
# ARC100D



import sys

input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(max(1000, 10**9))





n = int(eval(input()))

a = list(map(int, input().split()))

ca = [None] * n #ca[i] = a0~aiの和

s = 0

for i,num in enumerate(a):

    s += a[i]

    ca[i] = s



diff = [None] * n



s = 0

t = 1

v1 = 0 # a[:s]

v2 = a[0] # sum(a[s:t])

diff[t-1] = (v1,v2)

while t<n:

#     print(t, v1-v2)

    t += 1

    v2 += a[t-1]

    while v1<v2 and s<t:

        if diff[t-1] is None or abs(v1-v2)<abs(diff[t-1][0] - diff[t-1][1]):

            diff[t-1] = (v1,v2)

        s += 1

        v1 += a[s-1]

        v2 -= a[s-1]

    if diff[t-1] is None or abs(v1-v2)<abs(diff[t-1][0] - diff[t-1][1]):

        diff[t-1] = (v1,v2)        

    if v1>v2 and s>=1:

        v1 -= a[s-1]

        v2 += a[s-1]

        s -= 1



diff2 = [None] * n



s = n

t = n-1

v1 = 0 # sum(a[s:])

v2 = a[-1] # sum(a[t:s])

diff2[t] = (v1,v2)

while t>=1:

    # print(t, v1, v2)

    t -= 1

    v2 += a[t]

    while v1<v2 and s>t:

        if diff2[t] is None or abs(v1-v2)<abs(diff2[t][0] - diff2[t][1]):

            diff2[t] = (v1,v2)

        s -= 1

        v1 += a[s]

        v2 -= a[s]

    if diff2[t] is None or abs(v1-v2)<abs(diff2[t][0] - diff2[t][1]):

        diff2[t] = (v1,v2)        

    if v1>v2 and s<=n-2:

        v1 -= a[s]

        v2 += a[s]

        s += 1

print((min((max(diff[i][0], diff[i][1],diff2[i+1][0],diff2[i+1][1]) - min(diff[i][0], diff[i][1],diff2[i+1][0],diff2[i+1][1])) for i in range(n-1))))
# ARC100D
import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
# import numpy as np
import bisect

n = int(eval(input()))
a = list(map(int, input().split()))
# a = np.array(list(map(int, input().split())))
ca = [None] * n  # ca[i] = a0~aiの和
s = 0
for i, num in enumerate(a):
    s += a[i]
    ca[i] = s
# ca = a.cumsum()
def sub(l, start, end, init):
    if len(l) == 0:
        return 0, 0
    elif end - start == 1:
        return 0, l[start] - init
    target = (init + l[end - 1]) / 2
    i = bisect.bisect_right(l, target)
    p1 = (l[i] - init, l[end - 1] - l[i])
    p2 = (l[i - 1] - init, l[end - 1] - l[i - 1])
    if abs(p1[0] - p1[1]) < abs(p2[0] - p2[1]):
        return min(p1), max(p1)
    else:
        return min(p2), max(p2)


best = 10**15
for i in range(1, n):
    p1 = sub(ca, 0, i, 0)
    p2 = sub(ca, i, n, ca[i - 1])
    nn = max(p1[1] - p2[0], p2[1] - p1[0], p1[1] - p1[0], p2[1] - p2[0])
    #     print(p1,p2,nn)
    best = min(best, nn)
print(best)

# ARC100D
import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
n = int(eval(input()))
a = list(map(int, input().split()))
ca = [None] * n  # ca[i] = a0~aiの和
s = 0
for i, num in enumerate(a):
    s += a[i]
    ca[i] = s
diff = [None] * n
s = 0
t = 1
v1 = 0  # a[:s]
v2 = a[0]  # sum(a[s:t])
diff[t - 1] = (v1, v2)
while t < n:
    #     print(t, v1-v2)
    t += 1
    v2 += a[t - 1]
    while v1 < v2 and s < t:
        if diff[t - 1] is None or abs(v1 - v2) < abs(diff[t - 1][0] - diff[t - 1][1]):
            diff[t - 1] = (v1, v2)
        s += 1
        v1 += a[s - 1]
        v2 -= a[s - 1]
    if diff[t - 1] is None or abs(v1 - v2) < abs(diff[t - 1][0] - diff[t - 1][1]):
        diff[t - 1] = (v1, v2)
    if v1 > v2 and s >= 1:
        v1 -= a[s - 1]
        v2 += a[s - 1]
        s -= 1
diff2 = [None] * n
s = n
t = n - 1
v1 = 0  # sum(a[s:])
v2 = a[-1]  # sum(a[t:s])
diff2[t] = (v1, v2)
while t >= 1:
    # print(t, v1, v2)
    t -= 1
    v2 += a[t]
    while v1 < v2 and s > t:
        if diff2[t] is None or abs(v1 - v2) < abs(diff2[t][0] - diff2[t][1]):
            diff2[t] = (v1, v2)
        s -= 1
        v1 += a[s]
        v2 -= a[s]
    if diff2[t] is None or abs(v1 - v2) < abs(diff2[t][0] - diff2[t][1]):
        diff2[t] = (v1, v2)
    if v1 > v2 and s <= n - 2:
        v1 -= a[s]
        v2 += a[s]
        s += 1
print(
    (
        min(
            (
                max(diff[i][0], diff[i][1], diff2[i + 1][0], diff2[i + 1][1])
                - min(diff[i][0], diff[i][1], diff2[i + 1][0], diff2[i + 1][1])
            )
            for i in range(n - 1)
        )
    )
)

-# import numpy as np -import bisect - -# a = np.array(list(map(int, input().split()))) -# ca = a.cumsum() -def sub(l, start, end, init): -    if len(l) == 0: -        return 0, 0 -    elif end - start == 1: -        return 0, l[start] - init -    target = (init + l[end - 1]) / 2 -    i = bisect.bisect_right(l, target) -    p1 = (l[i] - init, l[end - 1] - l[i]) -    p2 = (l[i - 1] - init, l[end - 1] - l[i - 1]) -    if abs(p1[0] - p1[1]) < abs(p2[0] - p2[1]): -        return min(p1), max(p1) -    else: -        return min(p2), max(p2) - - -best = 10**15 -for i in range(1, n): -    p1 = sub(ca, 0, i, 0) -    p2 = sub(ca, i, n, ca[i - 1]) -    nn = max(p1[1] - p2[0], p2[1] - p1[0], p1[1] - p1[0], p2[1] - p2[0]) -    #     print(p1,p2,nn) -    best = min(best, nn) -print(best) +diff = [None] * n +s = 0 +t = 1 +v1 = 0  # a[:s] +v2 = a[0]  # sum(a[s:t]) +diff[t - 1] = (v1, v2) +while t < n: +    #     print(t, v1-v2) +    t += 1 +    v2 += a[t - 1] +    while v1 < v2 and s < t: +        if diff[t - 1] is None or abs(v1 - v2) < abs(diff[t - 1][0] - diff[t - 1][1]): +            diff[t - 1] = (v1, v2) +        s += 1 +        v1 += a[s - 1] +        v2 -= a[s - 1] +    if diff[t - 1] is None or abs(v1 - v2) < abs(diff[t - 1][0] - diff[t - 1][1]): +        diff[t - 1] = (v1, v2) +    if v1 > v2 and s >= 1: +        v1 -= a[s - 1] +        v2 += a[s - 1] +        s -= 1 +diff2 = [None] * n +s = n +t = n - 1 +v1 = 0  # sum(a[s:]) +v2 = a[-1]  # sum(a[t:s]) +diff2[t] = (v1, v2) +while t >= 1: +    # print(t, v1, v2) +    t -= 1 +    v2 += a[t] +    while v1 < v2 and s > t: +        if diff2[t] is None or abs(v1 - v2) < abs(diff2[t][0] - diff2[t][1]): +            diff2[t] = (v1, v2) +        s -= 1 +        v1 += a[s] +        v2 -= a[s] +    if diff2[t] is None or abs(v1 - v2) < abs(diff2[t][0] - diff2[t][1]): +        diff2[t] = (v1, v2) +    if v1 > v2 and s <= n - 2: +        v1 -= a[s] +        v2 += a[s] +        s += 1 +print( +    ( +        min( +            ( +                max(diff[i][0], diff[i][1], diff2[i + 1][0], diff2[i + 1][1]) +                - min(diff[i][0], diff[i][1], diff2[i + 1][0], diff2[i + 1][1]) +            ) +            for i in range(n - 1) +        ) +    ) +)