int main() {
int S;
scanf_s("%d", &S);
int MAX = 0, thismax = 0;
int s;
for (int i = 0;i < S;i++) {
scanf_s("%d", &s);
thismax += s;
if (thismax > MAX) {
MAX = thismax;
}
else if (thismax < 0) {
thismax = 0;
}
}
printf("%d", MAX);
return 0;
}
int main() {
int S;
scanf_s("%d", &S);
int MAX = 0, thismax = 0, I = 0, J, K;
bool T = true;
int s, a[10000];
for (int i = 0;i < S;i++) {
scanf_s("%d", &s);
a[i] = s;
if (s >= 0)
T = false;
thismax += s;
if (thismax > MAX || (thismax==MAX && MAX==0)) {
K = I;
MAX = thismax;
J = i;
}
else if (thismax < 0) {
thismax = 0;
I = i+1;
}
}
if (!T)
printf("%d %d %d", MAX, a[K], a[J]);
else
printf("%d %d %d", MAX, a[0], a[S-1]);
return 0;
}