#include <stdio.h>
#define MaxSize 100000
int main()
{
    int K;
    int i;
    int a[MaxSize];
    int flag = 0, zero = 0;
    int ThisSum = 0, MaxSum = 0;
    int tempindex = 0;
    scanf("%d", &K); //输入数组长度K
    int first = 0, last = K - 1;
    for (i = 0; i < K; i++)
    {
        scanf("%d", &a[i]); //输入K个整数
        if (a[i] > 0)
            flag = 1; //有正整数
        if (a[i] == 0)
            zero = 1; //有0（一开始把==写成了=）
    }
    if (flag)
    {
        for (i = 0; i < K; i++)
        {
            ThisSum += a[i];
            if (ThisSum > MaxSum)
            {
                MaxSum = ThisSum;
                first = tempindex;
                last = i;
            }
            if (ThisSum < 0)
            {
                ThisSum = 0;
                tempindex = i + 1;
            }
        }
        printf("%d %d %d\n", MaxSum, a[first], a[last]);
    }
    else if (zero)
    {
        printf("0 0 0\n");
    }
    else
    {
        printf("0 %d %d\n", a[first], a[last]);
    }
    return 0;
}
