#include <stdio.h>#define N 1001intmaxsum(inta[],intn){intsum=a[0];intb=0;for(inti=0;i<n;i++){if(b>=0)b+=a[i];elseb=a[i];if(b>sum)sum=b;}returnsum;}intmain(){intn,a[N];scanf("%d",&n);for(inti=0;i<n;i++)scanf("%d",&a[i]);printf("%d",maxsum(a,n));return0;}