Go: package main

import (
        "fmt"
)

func main() {
        for {
                var n int
                _, err := fmt.Scanf("%d", &n)
                if err != nil || n == 0 {
                        break
                }

                var sum [5001]int

                for i := 1; i <= n; i++ {
                        fmt.Scanf("%d", &(sum[i]))
                        if i > 1 {
                                sum[i] += sum[i-1]
                        }
                }

                max_sum := sum[1]
                for i := 1; i <= n; i++ {
                        for j := 0; j < i; j++ {
                                if max_sum < sum[i] - sum[j] {
                                        max_sum = sum[i] - sum[j]
                                }
                        }
                }
                fmt.Printf("%d\n", max_sum)
        }
}

C++: #include <iostream>
#include <climits>
using namespace std;

void solve(int n) 
{
    int seq[n];
    for (int i = 0; i < n; i++) {
        cin >> seq[i];
    }

    bool all_minus = true;
    for (int i = 0; i < n; i++) {
        if (seq[i] >= 0) {
            all_minus = false;
        }
    }
    if (all_minus) {
        int min = seq[0];
        for (int i = 1; i < n; i++) {
            min = seq[i] > min ? seq[i] : min;
        }
        cout << min << endl;
    }

    int cur_sum = seq[0];
    int cur_max = seq[0];

    for (int i = 1; i < n; i++) {
        cur_sum += seq[i];
        if (cur_sum < 0) {
            cur_sum = 0;
        } else {
            cur_max = cur_sum > cur_max ? cur_sum : cur_max;
        }
    }
    cur_max = (cur_max > cur_sum ? cur_max : cur_sum);
    cout << cur_max << endl;
}

int main(void)
{
    int n;
    while (cin >> n) {
        if (n == 0) break;
        solve(n);
    }
    return 0;
}

C++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)         __typeof__((c).begin())
#define FOREACH(it, c)  for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)        __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define REVREP(i, n)    for (int i = ((n)-1); i >= 0; --i)
#define FIND(c, n)      std::find((c).begin(), (c).end(), (n));
#define BSEARCH(c, n)   std::binary_search((c).begin(), (c).end(), (n))
#define LLPOW(p1,p2)    ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)      (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)      (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)      (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC     do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)       fgets((p), sizeof(p), stdin)
#define CHOMP(p)        do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n') *_q = 0; } while(0)

int main(){
    int n;
    while(cin >> n, n){
        list<int> v;
        int p = 0;
        REP(i, n){
            int in;
            cin >> in;
            if((p <= 0 && in < 0) || p >= 0 && in > 0 || in == 0){
                p += in;
            } else {
                v.push_back(p);
                p = in;
            }
        }
        v.push_back(p);

        while(v.size() >= 3){
            bool f = false;
            FOREACH(it, v){
                int p1 = *it;
                if(p1 < 0) continue;
                ITER(v) it2 = it; it2++;
                if(it2 == v.end()) break;
                int p2 = *it2;
                ITER(v) it3 = it2; it3++;
                if(it3 == v.end()) break;
                int p3 = *it3;

                if(p2+p3 >= 0){
                    v.erase(it2);
                    v.erase(it3);
                    *it += (p2+p3);
                    f = true;
                    break;
                }
            }
            if(!f) break;
        }

        int max = INT_MIN;
        FOREACH(it, v){
            if(max < *it) max = *it;
        }
        cout << max << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <climits>
#include <algorithm>
using namespace std;

int main() 
{
    int n;
    while (scanf("%d", &n)&&n!=0) {
        int a[n];
        for (int i=0; i<n; i++) scanf("%d", &a[i]);
        int dp[n];
        dp[0] = a[0];
        int res = INT_MIN;
        for (int i=1; i<n; i++) {
            dp[i] = max(a[i], dp[i-1]+a[i]);
            res = max(res, dp[i]);
        }
        printf("%d\n", res);
    }
}

C++: #include<iostream>
using namespace std;
int main(){
    int n=0,a[5000],saidai=-100000,kazu;
    while(cin>>n && n!=0){
saidai=-100000;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n;i++){
            kazu=0;
            for(int x=i;x<n;x++){
                kazu=kazu+a[x];
                cout<<kazu<<endl;
                if(saidai<kazu){
                   
                }
            }
        }
        cout<<saidai<<endl;
    }
}

C++: #include <iostream>

using namespace std;

int main(void){

  int n;
  while( cin >> n , n ){

    int m = - 99999999;
    int s = 0;
    while(n--){

      int x;
      cin >> x;
      s += x;
      m = max( m , s );
      if( s < 0 ) s = 0;

    }
    cout << m << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
typedef long double D;
const D INF = 1e100;
using namespace std;
int main(void){
        int n; int num[5000]; int MAX,CMAX;
        while(cin >> n ,n){
				MAX=-INF,CMAX=0;
                for(int i=0; i<n; i++)
                        cin >> num[i];
				for(int i=0; i<n; i++){
					CMAX+=num[i];
					MAX=max(MAX,CMAX);
					if(CMAX<0)
						CMAX=0;
				}
                cout << MAX << endl;
        }
 
 
}

C++: #include <iostream>
#include <cstdio>
#include <climits>
using namespace std;

int main(void) {
    int num;
    while(cin >> num, num != 0) {
        int ary[num + 1];
        ary[0] = 0;
        for(int r = 1; r <= num; r++) {
            int input; cin >> input;
            ary[r] = ary[r - 1] + input;
        }
        int max = INT_MIN;
        for(int r = 1; r <= num; r++) {
            for(int c = 0; c < r; c++) {
                int val = ary[r] - ary[c];
                if(val > max) max = val;
            }
        }
        
        cout << max << endl;
    }
    return(0);
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


int main(){
	  
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		
		int in[5555];
		rep(i,n)cin>>in[i];
		
		
		int ans = -1000000000;
		reps(i,1,n+1){
			
			int sum = 0;
			rep(j,i)sum += in[j];
			
			ans = max(ans,sum);
			reps(j,i,n){
				sum-=in[j-i];
				sum+=in[j];
				ans = max(ans,sum);
			}
		}
		printf("%d\n",ans);
	}
	
}

C++: #include<stdio.h>
int main(){
	int a;
	while(1){
		scanf("%d",&a);
		if(a==0)return 0;
		int n[10000];
		for(int i=0;i<a;i++)scanf("%d",n+i);
		int dp[10000];
		dp[0]=n[0];
		int max=0;
		for(int i=1;i<a;i++){
			if(dp[i-1]>0)dp[i]=dp[i-1]+n[i];
			else dp[i]=n[i];
			if(max<dp[i])max=dp[i];
		}
		printf("%d\n",max);
	}
}

C++: #include <iostream>
using namespace std;

int main()
{
	int n,t,mx;
	while(cin >> n, n)
	{
		mx = 0;
		int dt[5000]={0};
		for(int i=0; i< n; i++)
		{
			cin >> t;
			for(int j=0; j<=i; j++)
			{
				dt[j]+=t;
				mx=max(mx,dt[j]);
			}
		}
		cout << mx << endl;
	}
}