N=int(eval(input()))

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



cut_1=1

cut_2=2

cut_3=3

A_0=A[:cut_1]

S_0=sum(A_0)



A_1=A[cut_1:cut_2]

S_1=sum(A_1)



A_2=A[cut_2:cut_3]

S_2=sum(A_2)



A_3=A[cut_3:]

S_3=sum(A_3)





def irekae(S,T,i):

    if abs(S-T)>abs((S-A[i-1])-(T+A[i-1])):

        

        S=S-A[i-1]

        T=T+A[i-1]

        i=i-1

        

    elif abs(T-S)>abs((T-A[i])-(S+A[i])):

        #print(T,S,T-S,i)

        S=S+A[i]

        T=T-A[i]

        i=i+1

        #print(T,S,T-S,i)



    return (S,T,i)



MIN=[]

cut_1b=0

cut_3b=0

for cut_2 in range(2,N-1):

    cut_1b=0

    cut_3b=0

    while cut_1b != cut_1:

        cut_1b=cut_1

        S_0,S_1,cut_1=irekae(S_0,S_1,cut_1)

        #print(cut_1)



    while cut_3b != cut_3:

        cut_3b=cut_3

        S_2,S_3,cut_3=irekae(S_2,S_3,cut_3)



    MIN+=[max([S_0,S_1,S_2,S_3])-min([S_0,S_1,S_2,S_3])]

    #print(cut_1,cut_2,cut_3,S_0,S_1,S_2,S_3)



    S_1+=A[cut_2]

    S_2-=A[cut_2]



print((min(MIN)))

N=int(eval(input()))

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



SUM=[0]

for a in A:

    SUM.append(SUM[-1]+a)

    

i=1

j=2

k=3

P=SUM[i]

Q=SUM[j]-SUM[i]

R=SUM[k]-SUM[j]

S=SUM[N]-SUM[k]

ANS=10**10

check=1



while j<N-1:

    check=1

    while check==1:

        check=0

        if i<j-1:

            if abs(P-Q)>abs(P+A[i]-Q+A[i]):

                P+=A[i]

                Q-=A[i]

                i+=1

                check=1

        if k<N-1:



            if abs(R-S)>abs(R+A[k]-S+A[k]):

                R+=A[k]

                S-=A[k]

                k+=1

                check=1



    #print(P,Q,R,S,i,j,k)

    

    if ANS>max([P,Q,R,S])-min([P,Q,R,S]):

        ANS=max([P,Q,R,S])-min([P,Q,R,S])



    

    Q+=A[j]

    R-=A[j]

    j+=1



print(ANS)
N = int(eval(input()))
A = list(map(int, input().split()))
cut_1 = 1
cut_2 = 2
cut_3 = 3
A_0 = A[:cut_1]
S_0 = sum(A_0)
A_1 = A[cut_1:cut_2]
S_1 = sum(A_1)
A_2 = A[cut_2:cut_3]
S_2 = sum(A_2)
A_3 = A[cut_3:]
S_3 = sum(A_3)


def irekae(S, T, i):
    if abs(S - T) > abs((S - A[i - 1]) - (T + A[i - 1])):
        S = S - A[i - 1]
        T = T + A[i - 1]
        i = i - 1
    elif abs(T - S) > abs((T - A[i]) - (S + A[i])):
        # print(T,S,T-S,i)
        S = S + A[i]
        T = T - A[i]
        i = i + 1
        # print(T,S,T-S,i)
    return (S, T, i)


MIN = []
cut_1b = 0
cut_3b = 0
for cut_2 in range(2, N - 1):
    cut_1b = 0
    cut_3b = 0
    while cut_1b != cut_1:
        cut_1b = cut_1
        S_0, S_1, cut_1 = irekae(S_0, S_1, cut_1)
        # print(cut_1)
    while cut_3b != cut_3:
        cut_3b = cut_3
        S_2, S_3, cut_3 = irekae(S_2, S_3, cut_3)
    MIN += [max([S_0, S_1, S_2, S_3]) - min([S_0, S_1, S_2, S_3])]
    # print(cut_1,cut_2,cut_3,S_0,S_1,S_2,S_3)
    S_1 += A[cut_2]
    S_2 -= A[cut_2]
print((min(MIN)))

N = int(eval(input()))
A = list(map(int, input().split()))
SUM = [0]
for a in A:
    SUM.append(SUM[-1] + a)
i = 1
j = 2
k = 3
P = SUM[i]
Q = SUM[j] - SUM[i]
R = SUM[k] - SUM[j]
S = SUM[N] - SUM[k]
ANS = 10**10
check = 1
while j < N - 1:
    check = 1
    while check == 1:
        check = 0
        if i < j - 1:
            if abs(P - Q) > abs(P + A[i] - Q + A[i]):
                P += A[i]
                Q -= A[i]
                i += 1
                check = 1
        if k < N - 1:
            if abs(R - S) > abs(R + A[k] - S + A[k]):
                R += A[k]
                S -= A[k]
                k += 1
                check = 1
    # print(P,Q,R,S,i,j,k)
    if ANS > max([P, Q, R, S]) - min([P, Q, R, S]):
        ANS = max([P, Q, R, S]) - min([P, Q, R, S])
    Q += A[j]
    R -= A[j]
    j += 1
print(ANS)

-cut_1 = 1 -cut_2 = 2 -cut_3 = 3 -A_0 = A[:cut_1] -S_0 = sum(A_0) -A_1 = A[cut_1:cut_2] -S_1 = sum(A_1) -A_2 = A[cut_2:cut_3] -S_2 = sum(A_2) -A_3 = A[cut_3:] -S_3 = sum(A_3) - - -def irekae(S, T, i): -    if abs(S - T) > abs((S - A[i - 1]) - (T + A[i - 1])): -        S = S - A[i - 1] -        T = T + A[i - 1] -        i = i - 1 -    elif abs(T - S) > abs((T - A[i]) - (S + A[i])): -        # print(T,S,T-S,i) -        S = S + A[i] -        T = T - A[i] -        i = i + 1 -        # print(T,S,T-S,i) -    return (S, T, i) - - -MIN = [] -cut_1b = 0 -cut_3b = 0 -for cut_2 in range(2, N - 1): -    cut_1b = 0 -    cut_3b = 0 -    while cut_1b != cut_1: -        cut_1b = cut_1 -        S_0, S_1, cut_1 = irekae(S_0, S_1, cut_1) -        # print(cut_1) -    while cut_3b != cut_3: -        cut_3b = cut_3 -        S_2, S_3, cut_3 = irekae(S_2, S_3, cut_3) -    MIN += [max([S_0, S_1, S_2, S_3]) - min([S_0, S_1, S_2, S_3])] -    # print(cut_1,cut_2,cut_3,S_0,S_1,S_2,S_3) -    S_1 += A[cut_2] -    S_2 -= A[cut_2] -print((min(MIN))) +SUM = [0] +for a in A: +    SUM.append(SUM[-1] + a) +i = 1 +j = 2 +k = 3 +P = SUM[i] +Q = SUM[j] - SUM[i] +R = SUM[k] - SUM[j] +S = SUM[N] - SUM[k] +ANS = 10**10 +check = 1 +while j < N - 1: +    check = 1 +    while check == 1: +        check = 0 +        if i < j - 1: +            if abs(P - Q) > abs(P + A[i] - Q + A[i]): +                P += A[i] +                Q -= A[i] +                i += 1 +                check = 1 +        if k < N - 1: +            if abs(R - S) > abs(R + A[k] - S + A[k]): +                R += A[k] +                S -= A[k] +                k += 1 +                check = 1 +    # print(P,Q,R,S,i,j,k) +    if ANS > max([P, Q, R, S]) - min([P, Q, R, S]): +        ANS = max([P, Q, R, S]) - min([P, Q, R, S]) +    Q += A[j] +    R -= A[j] +    j += 1 +print(ANS)