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<bits/stdc++.h>
#define rep(i,n)for(ll i=0;i<n;i++)
using namespace std;
typedef long long ll;

ll sum[100001];
int main() {
	ll n;
	while (scanf("%lld", &n), n) {
		ll cnt = 0;
		rep(i, n) {
			sum[i] = cnt;
			int a; scanf("%d", &a);
			cnt += a;
		}
		sum[n] = cnt;
		ll Max = LLONG_MIN;
		rep(i, n) {
			for (int j = i + 1; j <= n; j++) {
				Max = max(Max, sum[j] - sum[i]);
			}
		}
		cout << Max << endl;
	}
	return 0;
}

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

int main(){
	int n;
	while(cin >> n, n){
		vector<int> vec;
		for(int i = 0; i < n; i++){
			int a;
			cin >> a;
			vec.push_back(a);
		}

		int max = vec[0] + vec[1];
		for(int i = 0; i < vec.size(); i++){
			for(int j = i+1; j < vec.size(); j++){
				int add = 0;
				for(int k = i; k <= j; k++){
					add += vec[k];
				}
				if(max < add) max = add;
			}
		}

		cout << max << endl;
	}
}

C++: #include <iostream>
#include <map>
#include <cmath>
#include <cstring>
#include <vector>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)

int n;
vector<int> v;
long long s[5000];

int main(){
    while(cin>>n,n){
        v=vector<int>(n);
        REP(i,n)cin>>v[i];
        long long ans=-(1<<30);
        REP(i,n){
            s[i]=v[i];
            ans=max(s[i],ans);
            for(int j=i+1; j<n; j++){
                s[j]=s[j-1]+v[j];
                ans=max(s[j],ans);
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include<stdio.h>

int main(void) 
{
    long int num[5000];
	int cut_i;
	int kousuu;
	long int nyuryoku;
	
	while(1){
		scanf("%d",&kousuu);
		
		if(kousuu == 0){
			break;
		}

		int kou = 0;
		long long int max = -100000;
		for(cut_i=0;cut_i<kousuu;cut_i++){
			num[cut_i]=0;
		}

		for(cut_i=0;cut_i<kousuu;cut_i++){
			scanf("%d",&nyuryoku);

			if(num[kou] * nyuryoku <0){
				kou++;
			}
			num[kou]+=nyuryoku;
			
			if(max<num[kou]){
				max = num[kou];
			}
		}

		kou++;
		cut_i = 0;
		
		for(cut_i=0;cut_i<kou;cut_i++){

			if(max<num[cut_i]){
				max = num[cut_i];
			}
			
			if(num[cut_i]+num[cut_i+1] > 0){
				num[cut_i+1]+=num[cut_i];
			}
		}

		printf("%d\n",max);

	}
    return 0;
}

C++: #include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
  // ifstream cin("../test.txt");
  int n;
  while (true) {
    cin >> n;
    if (!n) break;
    vector<int> a(n);
    vector<int> sub_sum(n); // a[0] + ... + a[i]
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sub_sum[0] = a[0];
    int max_sum = -100000000;
    for (int i = 1; i < n; i++) {
      sub_sum[i] = sub_sum[i-1] + a[i];
      max_sum = max(max_sum, sub_sum[i]);
    }
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < i; j++) {
        max_sum = max(max_sum, sub_sum[i] - sub_sum[j]);
      }
    }
    cout << max_sum << endl;
  }
}

C++: 7
-5
-1
6
4
9
-6
-7
13
1
2
3
2
-2
-1
1
2
3
2
1
-2
1
3
1000
-200
201
0

C++: #include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> maxSum(n);
		int a;
		cin >> a;
		maxSum[0] = a;
		int max = -999999999;
		for(int i = 1; i < n; ++i)
		{
			cin >> a;
			if(maxSum[i - 1] + a < a)
			{
				maxSum[i] = a;
			}
			else
			{
				maxSum[i] = maxSum[i - 1] + a;
			}
			if(max < maxSum[i])
			{
				max = maxSum[i];
			}
		}
		cout << max << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;
int main(void)
{
	int n, a[5001];
	while (1) {
		cin >> n;
		if (n == 0)
			break;
		for (int i = 1; i <= n; i++)
			cin >> a[i];
		int goukei = 0, ryuta = -10000000;
		for (int i = 1; i <= n; i++)
		{
			goukei = 0;
			for (int j = i; j <= n; j++)
			{
				goukei = goukei + a[j];
				ryuta = max(goukei, ryuta);
			}
		}
		cout << ryuta << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio.h>
using namespace std;
int main (){
while (1){
long n,dset[5000],max=-99999,temp=0;
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
                temp=temp+dset[j];
                if (max<temp){
                        max=temp;
                }
        }
temp=0;
}
printf ("%d\n",max);
}
return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;

#define ITER( c ) __typeof( c ).begin()
#define REP( i, m, n ) for ( int i = m; i < n; i++ )
#define UREP( i, m, n ) for ( unsigned int i = m; i < n; i++ )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) c.begin(), c.end()
#define PB( n ) push_back( n );
#define MP( a, b ) make_pair( a, b )
#define fst first
#define snd second

int main()
{
	while ( true )
	{
		int n;
		cin >> n;

		if ( n == 0 )
		{
			break;
		}

		vector<int> sum;
		sum.PB( 0 );

		REP( i, 0, n )
		{
			int in;
			cin >> in;
			sum.PB( *sum.rbegin() + in );
		}

		int max = INT_MIN;

		REP( i, 0, sum.size() )
		{
			REP( j, i, sum.size() )
			{
				int tmp = sum[j] - sum[i];
				if ( max < tmp )
				{
					max = tmp;
				}
			}
		}

		cout << max << endl;
	}

	return 0;
}

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

int main(){
  int n;
  int a[5000];
  while(cin >> n && n>0){
    for(int i=0;i<n;i++)
      cin >> a[i];
    long long sum=0,tmp=0,ma=-100000;
    int m=-100000;
    bool flg=true;
    for(int i=0;i<n;i++){
      if(flg) m=max(m,a[i]);
      if(a[i]>0){
	flg=false;
	sum+=a[i];
	continue;
      }
      ma=ma>sum?ma:sum;
      for(tmp=sum;i<n && a[i]<=0;i++){
	tmp+=a[i];
      }i--;
      if(tmp>0)
	sum=tmp;
      else
	sum=0;
    }
    ma=ma>sum?ma:sum;

    cout << (flg?m:ma) << endl;
  }
}

C++: #include<cstdio>
int main(){int n,i,j,s,m,a[5000];while(scanf("%d",&n)&&n){for(i=0;i<n;i++)scanf("%d",&a[i]);m=-2147483647;for(i=0;i<n;i++,s=0)for(j=i;j<n;)if((s+=a[j++])>m)m=s;printf("%d\n",m);}}

C++: #include<cstdio>

int main(){
	int n,max,sum,t;
	scanf("%d", &n);
	while(n){
		scanf("%d", &t);
		max = sum = t;
		for(int i = 1; i < n; i++){
			if(sum < 0){
				sum = 0;
			}
			scanf("%d", &t);
			sum += t;
			if(sum > max){
				max = sum;
			}
		}
		printf("%d\n", max);
		scanf("%d", &n);
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
  for(;;){
    int n;scanf("%d",&n);
    if(!n){break;}
    int min=0, max=0x80000000, sum=0;
    REP(i,n){
      int a;scanf("%d",&a);
      min=std::min(min,sum);
      max=std::max(std::max(max,sum+a-min),a);
      sum+=a;
    }
    printf("%d\n",max);
  }
}