INF = 2 * 10**5 * 10**9

n = int(eval(input()))

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

s = [0]

for x in a:

    s.append(s[-1]+x)

ans = INF

p1 = 1

p = 2

p2 = 3

def update():

    global ans

    if p1 < p and p2 < n:

        ans = min(ans , max(s[p1],s[p]-s[p1],s[p2]-s[p],s[n]-s[p2]) -  min(s[p1],s[p]-s[p1],s[p2]-s[p],s[n]-s[p2]) )

    if p2 < n and p1 - 1 >= 1:

        ans = min(ans , max(s[p1-1],s[p]-s[p1-1],s[p2]-s[p],s[n]-s[p2]) -  min(s[p1-1],s[p]-s[p1-1],s[p2]-s[p],s[n]-s[p2]) )

    if p1 < p and p2-1 >= p:

        ans = min(ans , max(s[p1],s[p]-s[p1],s[p2-1]-s[p],s[n]-s[p2-1]) -  min(s[p1],s[p]-s[p1],s[p2-1]-s[p],s[n]-s[p2-1]) )

    if p1-1 >= 1 and p2-1 >= p:

        ans = min(ans , max(s[p1-1],s[p]-s[p1-1],s[p2-1]-s[p],s[n]-s[p2-1]) -  min(s[p1-1],s[p]-s[p1-1],s[p2-1]-s[p],s[n]-s[p2-1]) ) 

while p2 < n and s[p2] - s[p] < s[n] - s[p2]:

    p2 += 1

update()

while True:

    p += 1

    if p + 1 >= n:

        break

    while p1 < p and s[p1] < s[p] - s[p1]:

        p1 += 1

    while p2 < n and s[p2] - s[p] < s[n] - s[p2]:

        p2 += 1

    update()

print(ans)
INF = 2 * 10**5 * 10**9

n = int(eval(input()))

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

s = [0]

for x in a:

    s.append(s[-1]+x)

ans = INF

p1 = 1

p = 1

p2 = 3

while True:

    p += 1

    if p + 1 >= n:

        break

    while p1 < p and abs(s[p1] - s[p] + s[p1]) > abs(s[p1+1] - s[p] + s[p1 + 1]):

        p1 += 1

    while p2 < n and abs(s[p2] - s[p]  - s[n] + s[p2]) > abs(s[p2+1] - s[p]  - s[n] + s[p2+1]):

        p2 += 1

    ans = min(ans , max(s[p1],s[p]-s[p1],s[p2]-s[p],s[n]-s[p2]) -  min(s[p1],s[p]-s[p1],s[p2]-s[p],s[n]-s[p2]) )

print(ans)
INF = 2 * 10**5 * 10**9
n = int(eval(input()))
a = list(map(int, input().split()))
s = [0]
for x in a:
    s.append(s[-1] + x)
ans = INF
p1 = 1
p = 2
p2 = 3


def update():
    global ans
    if p1 < p and p2 < n:
        ans = min(
            ans,
            max(s[p1], s[p] - s[p1], s[p2] - s[p], s[n] - s[p2])
            - min(s[p1], s[p] - s[p1], s[p2] - s[p], s[n] - s[p2]),
        )
    if p2 < n and p1 - 1 >= 1:
        ans = min(
            ans,
            max(s[p1 - 1], s[p] - s[p1 - 1], s[p2] - s[p], s[n] - s[p2])
            - min(s[p1 - 1], s[p] - s[p1 - 1], s[p2] - s[p], s[n] - s[p2]),
        )
    if p1 < p and p2 - 1 >= p:
        ans = min(
            ans,
            max(s[p1], s[p] - s[p1], s[p2 - 1] - s[p], s[n] - s[p2 - 1])
            - min(s[p1], s[p] - s[p1], s[p2 - 1] - s[p], s[n] - s[p2 - 1]),
        )
    if p1 - 1 >= 1 and p2 - 1 >= p:
        ans = min(
            ans,
            max(s[p1 - 1], s[p] - s[p1 - 1], s[p2 - 1] - s[p], s[n] - s[p2 - 1])
            - min(s[p1 - 1], s[p] - s[p1 - 1], s[p2 - 1] - s[p], s[n] - s[p2 - 1]),
        )


while p2 < n and s[p2] - s[p] < s[n] - s[p2]:
    p2 += 1
update()
while True:
    p += 1
    if p + 1 >= n:
        break
    while p1 < p and s[p1] < s[p] - s[p1]:
        p1 += 1
    while p2 < n and s[p2] - s[p] < s[n] - s[p2]:
        p2 += 1
    update()
print(ans)

INF = 2 * 10**5 * 10**9
n = int(eval(input()))
a = list(map(int, input().split()))
s = [0]
for x in a:
    s.append(s[-1] + x)
ans = INF
p1 = 1
p = 1
p2 = 3
while True:
    p += 1
    if p + 1 >= n:
        break
    while p1 < p and abs(s[p1] - s[p] + s[p1]) > abs(s[p1 + 1] - s[p] + s[p1 + 1]):
        p1 += 1
    while p2 < n and abs(s[p2] - s[p] - s[n] + s[p2]) > abs(
        s[p2 + 1] - s[p] - s[n] + s[p2 + 1]
    ):
        p2 += 1
    ans = min(
        ans,
        max(s[p1], s[p] - s[p1], s[p2] - s[p], s[n] - s[p2])
        - min(s[p1], s[p] - s[p1], s[p2] - s[p], s[n] - s[p2]),
    )
print(ans)

-p = 2 +p = 1 - - -def update(): -    global ans -    if p1 < p and p2 < n: -        ans = min( -            ans, -            max(s[p1], s[p] - s[p1], s[p2] - s[p], s[n] - s[p2]) -            - min(s[p1], s[p] - s[p1], s[p2] - s[p], s[n] - s[p2]), -        ) -    if p2 < n and p1 - 1 >= 1: -        ans = min( -            ans, -            max(s[p1 - 1], s[p] - s[p1 - 1], s[p2] - s[p], s[n] - s[p2]) -            - min(s[p1 - 1], s[p] - s[p1 - 1], s[p2] - s[p], s[n] - s[p2]), -        ) -    if p1 < p and p2 - 1 >= p: -        ans = min( -            ans, -            max(s[p1], s[p] - s[p1], s[p2 - 1] - s[p], s[n] - s[p2 - 1]) -            - min(s[p1], s[p] - s[p1], s[p2 - 1] - s[p], s[n] - s[p2 - 1]), -        ) -    if p1 - 1 >= 1 and p2 - 1 >= p: -        ans = min( -            ans, -            max(s[p1 - 1], s[p] - s[p1 - 1], s[p2 - 1] - s[p], s[n] - s[p2 - 1]) -            - min(s[p1 - 1], s[p] - s[p1 - 1], s[p2 - 1] - s[p], s[n] - s[p2 - 1]), -        ) - - -while p2 < n and s[p2] - s[p] < s[n] - s[p2]: -    p2 += 1 -update() -    while p1 < p and s[p1] < s[p] - s[p1]: +    while p1 < p and abs(s[p1] - s[p] + s[p1]) > abs(s[p1 + 1] - s[p] + s[p1 + 1]): -    while p2 < n and s[p2] - s[p] < s[n] - s[p2]: +    while p2 < n and abs(s[p2] - s[p] - s[n] + s[p2]) > abs( +        s[p2 + 1] - s[p] - s[n] + s[p2 + 1] +    ): -    update() +    ans = min( +        ans, +        max(s[p1], s[p] - s[p1], s[p2] - s[p], s[n] - s[p2]) +        - min(s[p1], s[p] - s[p1], s[p2] - s[p], s[n] - s[p2]), +    )