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++: #include <iostream>
#include <vector>

using namespace std;

int findMax(vector<int>& a) {
  int r = 0, sum, max;
  for (int i = 0, max = 0; i < a.size(); i++) {
    for (int j = i, sum = 0; j < a.size(); j++) {
      sum += a[j];
      if (max < sum) max = sum;
    }
    if (max > r) r = max;
  }
  return r;
}

int main() {
  int n, t;
  while (1) {
    cin >> n;
    if (n == 0) break;

    vector<int> a;
    for (int i = 0; i < n; i++) {
      cin >> t;
      a.push_back(t);
    }
    cout << findMax(a) << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
int n,dset[5000],temp=0,MINEdset[5000],max=0,h[5000],b=0;
while (1){
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];
                MINEdset[j]=temp;
        }
        for (int j=i;j<n;j++){
                if (max<MINEdset[j]){
                        max=MINEdset[j];
                }
        }
        h[b]=max;
        max=0;
        b++;
        temp=0;
}
max=0;
for (int i=0;i<b;i++){
        if (max<h[i]){
                max=h[i];
        }
}
cout<<max<<endl;
}
return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
	long???long int n,ans = 0;
	while(cin >> n){
		if(n == 0)break;

		long int a[n];

		for(int i = 0;i < n;i++){
			cin >> a[i];
			ans += a[i];
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;

int main (void){
  
    int number;
    int max;
    int answer[5010] = {0};
    int l = 0;
    while(cin >> number,number)
    {
        int a[5010] = {0};
        vector<int>tempmax(5010,0);
        vector<int>tempmax2(5010,0);
        int temp = 0;
        REP(i,number)
        cin >> a[i];
        for(int j = 0; j<number;j++)
            for(int k = j;k<number;k++)
            {
                for(int l = k;l<number;l++)
                {
                    if(k == l)
                        tempmax2[k] = a[k];
                    else{
                        
                        tempmax2[k] += a[l];
                    }
                    if(temp <= tempmax2[k])
                        temp = tempmax2[k];
                }
            
            }
        //sort(tempmax.begin(),tempmax.end(),greater<int>());
        //sort(tempmax2.begin(),tempmax2.end(),greater<int>());
        //if(tempmax[0]>temp)
            //answer[l] = tempmax[0];
        //else
           // answer[l] = temp;
        printf("%d\n",temp);
        temp = 0;
    }
    return 0;
}

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

int main(){

	int n;
	long long m, a[5001];

	a[0] = 0;
	while(cin >> n, n != 0){
		for(int i=1; i<=n; i++){
			cin >> a[i];
			a[i] += a[i-1];
		}

		m = 0;
		for(int i=0; i<=n; i++){
			for(int j=1; j<=n; j++){
				m = max(m, a[j] - a[i]);
			}
		}
		cout << m << endl;
	}
	cout << endl;
	return 0;
}

C++: //include----------------------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>

//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1 << 25
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << "\n";
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;

//const------------------------------------------------------------------------------------------------------------------------
const double EPS = 1e-10;
const double PI = acos( -1.0 );

//global-----------------------------------------------------------------------------------------------------------------------
int n;
VI ar;
LL ans = 0;

//function---------------------------------------------------------------------------------------------------------------------
void solve( int now_check, LL sum ) {
	if ( ans < sum ) {
		ans = sum;
	}
	if ( now_check == n ) {
		return;
	}
	if ( sum + ar[ now_check ] < 0 ) {
		solve( now_check + 1, 0 );
	}
	else {
		solve( now_check + 1, sum + ar[ now_check ] );

	}
}

int main() {
	while ( scanf( "%d", &n ) ) {
		if ( !n ) {
			return 0;
		}
		ans = 0;
		ar.resize( n );
		rep( i, n ) {
			scanf( "%d", &ar[ i ] );
		}
		solve( 0, 0 );
		printf( "%lld\n", ans );
	}
	return 0;
}

C++: /*Filename: aoj0022.cpp
 *Author: Mushiyo
 */

#include <iostream>
#include <cmath>

using namespace std;

int main(){
	int n = 0;

    while(cin >> n){
    	if(n == 0){
    		break;
    	}

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

        int sum[n];
        sum[0] = a[0];
        for(int i = 1; i < n; ++i){
        	sum[i] = sum[i - 1] + a[i];
        }

        int maxSum = 0;
        int minSum = 0;
        for(int i = 0; i < n; ++i){
        	maxSum = max(maxSum, sum[i] - minSum);
        	minSum = min(minSum, sum[i]);
        }
        
        cout << maxSum << endl;
    }

	return 0;
}

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

using namespace std;

int main () {
  int n;
  while( 1 ){
    cin >> n;
    if( !n ){ return EXIT_SUCCESS; }
    vector<int> v;
    v.reserve( n );
    for( int i = 0; i < n; i++ ) {
      cin >> v[ i ];
    }
    int summax = v[ 0 ];
    for( int i = 0; i < n; i++ ) {
      int sum = v[ i ];
      for( int j = i + 1; j < n; j++ ) {
         sum = sum + v[ j ];
         if( sum > summax ) {
           summax = sum;
         }
      }
    }
    cout << summax << endl;
  } 
}

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

int a[5000];
int dp[5000];
int k,n;
int main(){
  while(1){
    cin>>n;
    if(n==0) break;
    for(int i=0;i<n;i++)cin>>a[i];
    dp[0]=a[0];
    for(int i=1;i<n;i++)dp[i]=max(dp[i-1]+a[i],a[i]);
    int ans=-9999999;
    for(int i=0;i<n;i++)ans=max(ans,dp[i]);
    cout<<ans<<"\n";
  }
}