#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
#define ll __int64
using namespace std;
int k,i,ans,sum,anss,anse,e,s,a[10005];
int main()
{
while(scanf("%d",&k)&&k)
{
for(i=0;i<k;i++)
scanf("%d",&a[i]);
sum=ans=s=e=anss=anse=a[0];
for(i=1;i<k;i++)
{
if(sum>0)
{
sum+=a[i];
e=a[i];
}
if(sum<=0)
{
sum=a[i];
s=e=a[i];
}
if(sum>ans)
{
ans=sum;
anss=s;
anse=e;
}
}
if(ans>=0) printf("%d %d %d\n",ans,anss,anse);
else printf("0 %d %d\n",a[0],a[k-1]);
}
return 0;
}