Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(i,j):
    ma=j
    mi=i
    while ma-mi>1:
        mid = (ma + mi)//2
        a=A[j]-A[mid]
        b=A[mid-1]-A[i]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [A[mi]-A[i],A[j]-A[mi]]
num=10**14
for i in range(2,N-1):
    ans=[]
    ans+=dou(0,i)
    ans+=dou(i,N)
    #print(ans)
    t=max(ans)-min(ans)
    num=min(num,t)
print(num)

Fixed submission:
from collections import deque
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(i,j):
    ma=j
    mi=i
    while ma-mi>1:
        mid = (ma + mi)//2
        a=A[j]-A[mid]
        b=A[mid-1]-A[i]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [A[mi]-A[i],A[j]-A[mi]]
num=10**14
for i in range(2,N-1):
    ans=[]
    ans+=dou(0,i)
    ans+=dou(i,N)
    #print(ans)
    t=max(ans)-min(ans)
    num=min(num,t)
print(num)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(X):
    n=len(X)
    ma=len(X)-1
    mi=0
    while ma-mi>1:
        mid = (ma + mi)//2
        a=X[n-1]-X[mid]
        b=X[mid-1]-X[0]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [X[mi]-X[0],X[n-1]-X[mi]]
num=10**14
K=A[:2]
L=deque(A[2:])
for i in range(2,N-1):
    a=L.popleft()
    L.appendleft(a)
    K.append(a)
    #print(K,L)
    ans=[]
    ans=ans+dou(K)+dou(L)
    #print(ans)
    #print(abs(max(ans)-min(ans)))
    num=min(num,abs(max(ans)-min(ans)))
    L.popleft()
print(num)

Fixed submission:
from collections import deque
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(i,j):
    ma=j
    mi=i
    while ma-mi>1:
        mid = (ma + mi)//2
        a=A[j]-A[mid]
        b=A[mid-1]-A[i]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [A[mi]-A[i],A[j]-A[mi]]
num=10**14
for i in range(2,N-1):
    ans=[]
    ans+=dou(0,i)
    ans+=dou(i,N)
    #print(ans)
    t=max(ans)-min(ans)
    num=min(num,t)
print(num)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(X):
    n=len(X)
    ma=len(X)-1
    mi=0
    while ma-mi>1:
        mid = (ma + mi)//2
        a=X[n-1]-X[mid]
        b=X[mid-1]-X[0]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [X[mi]-X[0],X[n-1]-X[mi]]
num=10**14
K=A[:2]
L=deque(A[2:])
for i in range(2,N-1):
    a=L[0]
    K.append(a)
    #print(K,L)
    ans=[]
    ans=ans+dou(K)+dou(L)
    #print(ans)
    #print(abs(max(ans)-min(ans)))
    num=min(num,abs(max(ans)-min(ans)))
    L.popleft()
print(num)

Fixed submission:
from collections import deque
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(i,j):
    ma=j
    mi=i
    while ma-mi>1:
        mid = (ma + mi)//2
        a=A[j]-A[mid]
        b=A[mid-1]-A[i]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [A[mi]-A[i],A[j]-A[mi]]
num=10**14
for i in range(2,N-1):
    ans=[]
    ans+=dou(0,i)
    ans+=dou(i,N)
    #print(ans)
    t=max(ans)-min(ans)
    num=min(num,t)
print(num)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(X):
    n=len(X)
    ma=len(X)-1
    mi=0
    while ma-mi>1:
        mid = (ma + mi)//2
        a=X[n-1]-X[mid]
        b=X[mid-1]-X[0]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [X[mi]-X[0],X[n-1]-X[mi]]
num=10**14
K=A[:2]
L=deque(A[2:])
for i in range(2,N-1):
    a=L[0]
    K.append(a)
    #print(K,L)
    ans=[]
    ans=ans+dou(K)+dou(L)
    #print(ans)
    #print(abs(max(ans)-min(ans)))
    num=min(num,abs(max(ans)-min(ans)))
    L.popleft()
print(num)

Fixed submission:
from collections import deque
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(i,j):
    ma=j
    mi=i
    while ma-mi>1:
        mid = (ma + mi)//2
        a=A[j]-A[mid]
        b=A[mid-1]-A[i]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [A[mi]-A[i],A[j]-A[mi]]
num=10**14
for i in range(2,N-1):
    ans=[]
    ans+=dou(0,i)
    ans+=dou(i,N)
    #print(ans)
    t=max(ans)-min(ans)
    num=min(num,t)
print(num)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(X):
    n=len(X)
    ma=len(X)-1
    mi=0
    while ma-mi>1:
        mid = (ma + mi)//2
        a=X[n-1]-X[mid]
        b=X[mid-1]-X[0]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [X[mi]-X[0],X[n-1]-X[mi]]
num=10**14
for i in range(2,N-1):
    K=A[:i+1]
    L=A[i:]
    #print(K,L)
    ans=[]
    ans=ans+dou(K)+dou(L)
    #print(ans)
    num=min(num,abs(max(ans)-min(ans)))
print(num)

Fixed submission:
from collections import deque
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(i,j):
    ma=j
    mi=i
    while ma-mi>1:
        mid = (ma + mi)//2
        a=A[j]-A[mid]
        b=A[mid-1]-A[i]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [A[mi]-A[i],A[j]-A[mi]]
num=10**14
for i in range(2,N-1):
    ans=[]
    ans+=dou(0,i)
    ans+=dou(i,N)
    #print(ans)
    t=max(ans)-min(ans)
    num=min(num,t)
print(num)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(X):
    n=len(X)
    ma=len(X)-1
    mi=0
    while ma-mi>1:
        mid = (ma + mi)//2
        a=X[n-1]-X[mid]
        b=X[mid-1]-X[0]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [X[mi]-X[0],X[n-1]-X[mi]]
num=10**14
for i in range(2,N-1):
    K=A[:i+1]
    L=A[i:]
    #print(K,L)
    ans=[]
    ans=ans+dou(K)+dou(L)
    #print(ans)
    num=min(num,abs(max(ans)-min(ans)))
print(num)

Fixed submission:
from collections import deque
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(i,j):
    ma=j
    mi=i
    while ma-mi>1:
        mid = (ma + mi)//2
        a=A[j]-A[mid]
        b=A[mid-1]-A[i]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [A[mi]-A[i],A[j]-A[mi]]
num=10**14
for i in range(2,N-1):
    ans=[]
    ans+=dou(0,i)
    ans+=dou(i,N)
    #print(ans)
    t=max(ans)-min(ans)
    num=min(num,t)
print(num)