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++: // includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n;
  while(true){
    cin >> n;
    if(n == 0)break;
    vector<ll> a, sum;
    rep(i, n){
      ll x;
      cin >> x;
      a.pb(x);
      if(i > 0)sum.pb(sum[i-1] + x);
      else sum.pb(x);
    }
    ll res = - inf;
    rep(i, n){
      FOR(j, i, n){
        ll tmp = sum[j];
        if(i > 0)tmp -= sum[i - 1];
        res = max(res, tmp);
      }
    }
    cout << res << endl;
  }
	return 0;
}

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

int main() {
	int n;
	while (cin >> n && n) {
		int a[5001], min, max_a;
		min = a[0] = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			if (i == 1) max_a = a[i] - a[0];
			a[i] += a[i - 1];
			if (a[i] - min > max_a) max_a = a[i] - min;
			if (a[i] < min) min = a[i];
		}
		cout << max_a << endl;
	}
}

C++: #include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n;
    int A[5000];
    while (cin >> n && n)
    {
        for (int i = 0; i < n; i++)
        {
            cin >> A[i];
        }
        int S[5000];
        S[0] = A[0];
        int max = A[0];
        for (int i = 1; i < n; i++)
        {
            S[i] = S[i - 1] + A[i];
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = i; j < n; j++)
            {
                int sum = 0;
                if (i != 0)
                {
                    sum = S[j] - S[i - 1];
                }
                else
                {
                    sum = S[j];
                }
                if (max < sum)
                {
                    max = sum;
                }
            }
        }
        cout << max << endl;
    }
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n,a[5000];
	while(1){
		int maxa=-10001;
		scanf("%d",&n);
		if(n==0)
			break;
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				maxa=max(maxa,sum);
			}
		}
		printf("%d\n",maxa);
	}
	return 0;
}

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 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>
using namespace std;
int main()
{
int n;
while(cin>>n&&n!=0)
{
int a[n];
int A=0;
int R=-100000;
for(int h=0;h<n;h++)
{
	cin>>a[h];
}
for(int i=0;i<n;i++)
{
	for(int j=0;j<n-i;j++)
	{
	for(int k=i;k<=j;k++)
	{
		A=A+a[k];
		
	}	
	if(R<A)
	{
		R=A;
	}
	A=0;
	}
}
cout<<R<<endl;
}
return 0;
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){

	while(1){
		int n;
		cin>> n;
		if(!n) break;
		
		vector<int> a(n,0);
		for(int i=0;i<n;i++){
			cin>> a[i];
		}
		int sum=0;
		for(int i=0;i<n-1;i++){
			int sum2 = a[i];
			if(sum < sum2) sum = sum2;
			for(int j=i+1;j<n;j++){
				sum2 += a[j];
				if(sum < sum2) sum = sum2;
			}
		}
		
		cout<< sum<< endl;
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

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

int maxsum(const vector<int>& data){
  int maxsumval=0,n=data.size();
  for(int i=0;i<n-1;i++){
    int sum=0;
    for(int j=0;j<n;j++){
      sum+=data[i+j];
      if(sum>maxsumval)maxsumval=sum;
    }
  }
  return maxsumval;

}
int main(){
  int n;
  while(cin>>n&&n){
    vector<int> data(n);
    for(int i=0;i<n;i++){
      cin>>data[i];
    }
    int maxsumval=maxsum(data);
    cout<<maxsumval<<endl;
  }

}

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

int sumData(int data[], int s, int n) {
  int sum = 0;
  for(int i = 0; i < n; i++) {
    sum += data[s+i];
  }
  return sum;
}

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

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

    int max = INT_MIN;
    for(int i = 1; i <= n; i++) {
      for(int j = 0; j <= n-i; j++) {
	int temp = sumData(data, j, i);
	if(temp > max) max = temp;
      }
    }

    cout << max << endl;
  }
  return 0;
}