#include <climits> #include <iostream> #include <vector> using namespace std; const int N = 10010; int dp[N]; int a[N]; int main() { int n; while (cin >> n) { if (!n)break; dp[0] = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; dp[i] = 0; } int ans = INT_MIN; vector<int> st; int ed; for (int i = 1; i <= n; i++) { if (a[i] >= dp[i - 1] + a[i]) { dp[i] = a[i]; st.push_back(i); // cout<<i<<endl; } else { dp[i] = dp[i - 1] + a[i]; } if (dp[i] > ans) { ans = dp[i]; ed = i; //cout<<ed<<endl; } } if (st.size()) { int idx; for (idx = 0; idx < st.size(); idx++) { if (st[idx] > ed)break; } idx--; //cout<<i<<endl; //cout<<st[i]<<endl; cout << ans << ' ' << a[st[idx]] << ' ' << a[ed] << endl; } } return 0; }