#include <iostream> using namespace std; int main() { int k; while (cin >> k) { if (k == 0) break; int nums[k]; bool flag = true; for (int i = 0; i < k; i++) { cin >> nums[i]; if (nums[i] >= 0) flag = false; } if (flag) { cout << 0 << ' ' << nums[0] << ' ' << nums[k - 1] << endl; continue; } int dp[k]; dp[0] = nums[0]; int maxSum = dp[0]; int start = 0, end = 0, temp = 0; for (int i = 1; i < k; i++) { if (dp[i - 1] + nums[i] < nums[i]) { dp[i] = nums[i]; temp = i; } else { dp[i] = dp[i - 1] + nums[i]; } if (dp[i] > maxSum) { maxSum = dp[i]; start = temp; end = i; } } cout << maxSum << ' ' << nums[start] << ' ' << nums[end] << endl; } return 0; }