#include <bits/stdc++.h>

using namespace std;
const int N = 10010;

int a[N];

int main(){
	int k;
	
	while (cin >> k){
		if (k == 0) continue;
		memset(a, 0, sizeof a);
		int maxx = -1e9, s = 0;
		
		for (int i=1; i<=k; i++){
			scanf("%d", &a[i]);
		}
		bool flag_po = false;
		for (int i=1; i<=k; i++){
			if (a[i] >= 0){
				flag_po = true;
				break;
			}
		}
		if (!flag_po){
			cout << "0" << " "<< a[1] << " " << a[k] << endl;
			continue;
		}
		int st = 1, ed = 1, old_st = 1;
		for (int i=1; i<=k; i++){
			s += a[i];
			if (s > maxx) {
				maxx = s;
				ed = i;
				old_st = st;
			}
			if (s < 0) { // 重新开始 
				s = 0;
				st = i + 1;
			}
			
		}
		
		cout << maxx <<  " " << a[old_st] << " "<< a[ed] << endl;
	}
	
	return 0;
}