Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

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;
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a[5000];
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int best=0;
	for(int lon=1;lon<=n;lon++){
		int g=0;
		for(int i=0;i<lon;i++)
			g+=a[i];
		if(g>best)
			best=g;
		for(int first=1;first+lon<=n+1;first++){
			g+=a[first+lon-1]-a[first-1];
			if(g>best)
				best=g;
		}
	}
	cout<<best<<endl;
	}
	return 0;
}