/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
using namespace std;
int n;
int a[10005];
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
while(scanf("%d", &n) == 1){
if(!n) break;
for (int i = 1; i <= n; i++){
scanf("%d", &a[i]);
}
int l = a[1], r = a[1], l1 = a[1];
int maxx = a[1];
int now = 0;
for (int i = 1; i <= n; i++){
if(now < 0){
now = a[i];
l1 = a[i];
}else now += a[i];
if(now > maxx){
l = l1;
maxx = now;
r = a[i];
}
}
if(maxx < 0){
printf("0 %d %d\n", a[1], a[n]);
}else{
printf("%d %d %d\n", maxx, l, r);
}
}
return 0;
}
/**/