#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    while(cin>>n){
        if(n==0)return 0;
        int arr[n];
        //读取数组
        for(int i =0;i<n;i++)
            cin>>arr[i];
        //构造dp
        int dp[n];
        for(int i =0;i<n;i++)
            dp[i]=INT_MIN;
        int left=arr[0],right=arr[0];
        dp[0] = arr[0];
        int maybe = arr[0];
        for(int i=1;i<n;i++){
            dp[i] = max(arr[i],arr[i]+dp[i-1]);
            //可能需要移动left
            if(arr[i]>arr[i]+dp[i-1]){
                maybe = arr[i];
                // cout<<"mark"<<i<<endl;
            }
            if(dp[i] >*max_element(dp,dp+i) && ((dp[i] >*max_element(dp+i+1,dp+n))||(i == n-1))){
                left = maybe;
            }
        }
        int maxNum=dp[0];
        for(int i =1;i<n;i++){
            if(dp[i]>maxNum){
                maxNum = dp[i];
                right = arr[i];
            }
        }
        if(maxNum<0){
            cout<<0<<" "<<arr[0]<<" "<<arr[n-1]<<endl;
        }else{
            cout<<maxNum<<" "<<left<<" "<<right<<endl;
        }
            
        
    }
}
// 64 位输出请用 printf("%lld")

缝缝补补的屎山...