#include<cstdio> #include<math.h> #include<climits> using namespace std; #define N 1000001 long long dp[N] ; long long a[N] = {0}; int main(){ int n ; while(scanf("%d",&n) != EOF){ for(int i = 0 ; i < n ;++i){ scanf("%lld ",&a[i]); } long long answer = -INT_MAX; for(int i = 0 ;i < n ; ++i){ if(i == 0 ){ dp[i] = a[i]; }else{ dp[i] = max(a[i],a[i] + dp[i-1]); } answer = max(answer ,dp[i]); } printf("%lld\n",answer); } }