#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int k,val,sum,ans,ans_s,ans_e,temps,tempe;
	vector<int>vec;
	while(cin >> k && k){
        vec.clear();
        while(k--){
			cin >> val;
			vec.push_back(val);
		}
        ans = -10000000;
        sum = 0;
        temps = vec[0];
        for(int i = 0;i < vec.size();++i){
            if(sum < 0){
                sum = vec[i];
                temps = vec[i];
            }
            else{
                sum += vec[i];
            }
            tempe = vec[i];
            if(ans < sum){
                ans = sum;
                ans_s = temps;
                ans_e = tempe;
            }
        }
        if(ans < 0)
            cout << 0 << " " << vec[0] << " " << vec.back() << endl;
        else
            cout << ans << " " << ans_s << " " << ans_e << endl;
	}
}