#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define MN 200005
using namespace std;
int n,ll,rr;
long long a[MN],ans=1e18;
long long solve(int mid){
	long long lst=1e18;
    int l=mid-1,r=n-1;
    for (int i=ll;i<mid;i++){
        long long tmp=abs(a[mid]-a[i]-a[i]);
        if (tmp>=lst){l=i-1;break;}lst=tmp;
    }lst=1e18;
    for (int i=rr;i<n;i++){
        long long tmp=abs(a[n]-a[i]-(a[i]-a[mid]));
        if(tmp>=lst){r=i-1;break;}lst=tmp;
    }rr=r,ll=l;return max(max(max(a[n]-a[r],a[r]-a[mid]),a[mid]-a[l]),a[l])-min(min(min(a[n]-a[r],a[r]-a[mid]),a[mid]-a[l]),a[l]);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),a[i]+=a[i-1];
	for(int i=2;i<n-1;i++)ans=min(ans,solve(i));
	printf("%lld\n",ans);
}
