#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fst first
#define snd second
#define pb push_back
#define mset(a,v) memset(a,v,sizeof(a))
#define forn(i,a,b) for(int i = a; i<b; i++)
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
template <typename T>
using iset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#ifdef D
#define debug(x) cout<<x
#else
#define debug(x) //nothing
#endif
const int MAXN = 5003;
struct STree{
int n;
int cnt;
vector<pair<int,int>> st;
STree(int n=0, int cnt=0):n(n),cnt(cnt), st(3*n+5,pair<int,int>{-1000000,-1}) {}
void upd(int k, int l, int r ,int p, pair<int,int> v){
if(l+1==r){ st[k]=v; return; }
int mid = (l+r)/2;
if(mid>p) upd(2*k,l,mid,p,v);
else upd(2*k+1,mid,r,p,v);
st[k]=max(st[2*k],st[2*k+1]);
}
pair<int,int> query(int k, int l, int r, int L, int R){
if(l>=R || r<=L) return pair<int,int>{-1000000,-1};
if(l>=L && r<=R) return st[k];
int mid = (l+r)/2;
return max(query(2*k,l,mid,L,R),query(2*k+1,mid,r,L,R));
}
void upd(int p, pair<int,int> v){ upd(1,0,n,p-cnt,v); }
pair<int,int> query(int l, int r){ return query(1,0,n,l-cnt,r-cnt); }
};
int n;
ll ps[MAXN];
STree dp[MAXN];
int main(){ FIN;
cin>>n;
forn(i,1,n+1) dp[i]=STree(n+2-i,i);
forn(i,1,n+1) cin>>ps[i];
ps[0]=0;
forn(i,2,n+1) ps[i]+=ps[i-1];
//cout<<"Update base\n";
forn(i,1,n+1) dp[i].upd(n,{1,n});
//cout<<"calculo dp\n";
int l,r,mid;
for(int i = n; i>=1; i--){
for(int j = n-1; j>=i; j--){
l = 1; r=n;
while(l<=r){
mid = (l+r)/2;
//cout<<mid<<" "<<l<<" "<<r<<'\n';
if(ps[mid]-ps[j]>=ps[j]-ps[i-1]) r=mid-1;
else l = mid+1;
}
if(l<=n) dp[i].upd(j,{dp[j+1].query(l,n+1).fst+1,j});
}
}
/*forn(i,1,n+1){
forn(j,i,n+1){
cout<<i<<" "<<j<<": ";cout<<"{"<<dp[i].query(j,j+1).fst<<" "<<dp[i].query(j,j+1).snd<<"}"<<'\n';
}
}*/
cout<<dp[1].query(1,n+1).fst<<'\n';
return 0;
int L = 1;
int R = dp[1].query(1,n+1).snd;
cout<<ps[R]-ps[L-1]<<" ";
while(R!=n){
//cout<<L<<" "<<R<<" = ";
int nL = R+1;
int nR;
l = 1; r=n;
while(l<=r){
mid = (l+r)/2;
if(ps[mid]-ps[nL-1]>=ps[R]-ps[L-1]) r=mid-1;
else l = mid+1;
}
nR=dp[nL].query(l,n+1).snd;
cout<<ps[nR]-ps[nL-1]<<' ';
L=nL;
R=nR;
}
cout<<'\n';
return 0;
}