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 <stdio.h>

int main()
{
	int n, x, p;
	
	while(scanf("%d", &n) != 0){
		if (n == 0) break;
		
		int a[n];

		for(int i = 0; i < n; i++){
			scanf("%d", &a[i]);
		}

		x = a[0];

		for(int i = 1; i <= n; i++){
			for(int j = 0; j < n-i+1; j++){
				p = 0;

				for(int k = 0; k < i; k++){
					p += a[j+k];
				}

				if(x < p) x = p;
			}
		}

		printf("%d\n", x);
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a[5001];
	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;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,math[5010],most,bell;
  while(1){
    cin >> n;
    if(n==0){
      break;
    }

    most=0;

    for(int i=0;i<n;i++){
      cin >> math[i];
    }
    for(int i=0;i<n;i++){
      bell=math[i];
      for(int j=i+1;j<n;j++){
	bell+=math[j];
	if(most<bell){
	  most=bell;
	}
      }
    }
    cout << most << endl;
  }
}

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

int main() {
	int n, a, zip = 0;
	vector<int> an;
	vector<vector<int>> AN;
	while (cin >> n) {
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> a;
			if (a >= 0)zip += a;
			else {
				if(zip==0)an.push_back(a);
				else {
					an.push_back(zip);
					an.push_back(a);
					zip = 0;
				}
			}
		}
		AN.push_back(an); an.clear();
	}

	for (int i = 0; i < AN.size(); i++) {
		int max = 0, MAX = 0 , counter = 0;
		for (int j = 0; j < AN[i].size(); j++) {
			if (AN[i][j] >= 0) {
				max += AN[i][j];
				if (MAX < max)MAX = max;
				counter = 1;
			}
			else {
				if (counter==1){
					if (AN[i][j] + max >= 0)max += AN[i][j];
					else {
						if (MAX < max)MAX = max;
						max = 0;
						counter = 0;
					}
				}
			}
		}
		cout << MAX << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<iomanip>
#include<string>
#include<algorithm>
using namespace std;

int gcd(long long int m,long long int n){
	while(m!=n){
		if(m>n){m=m-n;
		}
		else n=n-m;
	}
	return m;
}
int lmc(long long int m,long long int n){
return m*n/gcd(m,n);
}

int main(){
int n;
while(cin>>n,n!=0){
	int a[5000];
	long int sum[5000]={0};
	long int prev=-10000;
	int num;
	for (int i=0;i<n;i++){
		cin>>a[i];
		if(i==0){
			sum[i]=a[i];
		}
		else
		{sum[i]=sum[i-1]+a[i];}
		if(sum[i]>prev){
			prev=sum[i];
			num=i;
		}
	}
	int ans[5000]={0};
	ans[0]=prev;
	for (int i=0;i<num;i++){
		ans[i+1]=prev-sum[i];
	}
	sort(ans,ans+5000);
	cout<<ans[4999]<<endl;
}

}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

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

int main(void){  
  int n;
  while(cin>>n,n){
    int maxs = 0;
    int a[10001] = {0};
    REP(i,n) cin >> a[i];
    FOR(i,0,n){
      int sum =0;
      FOR(j,i,n){
        sum += a[j];
        maxs = max(sum, maxs);
      }
    }
    cout << maxs << endl;
  }
  return 0;
}

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

int main() {
	int n;
	while (true) {
		cin >> n;
		if (n == 0)break;
		int* nums = new int[n];
		for (int i = 0; i < n; i++) {
			cin >> nums[i];
		}
		int max = 0; 
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n - i; j++) {
				int tmp = 0;
				for (int k = i; k <= j; k++) {
					tmp += nums[k];
				}
				if (max < tmp)max = tmp;
			}
		}
		cout << max << endl;
	}
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[5001];
int main(){
	int N;
	int x;
	while(cin>>N&&N){
		int index=0;
		int ans = 0;
		
		FOR(i,1,N+1){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,1,N+1){
			FOR(j,i,N+1){
				ans = max(ans,sum[j]-sum[i-1]);
			}
		}
		cout<< ans <<endl;
	}
}

C++: #include <cstdio>
#include <bitset>
#include <cmath>
#include <complex>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#define EPS 1e-6

using namespace std;
typedef complex<double> coor;

double cross(coor a, coor b)
{
  return a.real() * b.imag() - a.imag() * b.real();
}

double dot(coor a, coor b)
{
  return a.real() * b.real() + a.imag() * b.imag();
}

int main()
{
  int N;
  while (scanf(" %d ", &N) == 1) {
    if (N == 0) {break;}
    vector<int> series(N);
    
    for (int i = 0; i < N; i++) {
      int n;
      scanf(" %d ", &n);
      series[i] = n;
    }
    
    int mx = -1000000000;
    for (int i = 0; i < N; i++) {
      int sum = 0;
      for (int j = i; j < N; j++) {
	sum += series[j];

	mx = max(mx, sum);
      }
    }
    printf("%d\n", mx);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n,ans;
    cin >> n;
    while(n!=0){
        int a[5001];
        for(int i=0;i<n;++i){
            cin >> a[i];
        }
        ans=a[1]+a[0];
        for(int i=0;i<n-2;++i){
            ans=max(ans,a[i+2]+a[i+1]);
        }
        cout << ans << endl;
        cin >> n;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
int n,Sum,Ans ;

while(1){

Ans=0 ;

cin >> n ;

if(n==0){
break ;
}

vector<int> vec(n+1,0) ;

for(int i=1;i<n+1;i++){
cin >> vec.at(i) ;
}

for(int j=0;j<n;j++){
vec.at(j+1)=vec.at(j)+vec.at(j+1) ;
}

for(int k=0;k<n+1;k++){
    for(int l=k+1;l<n+1;l++){
    Sum=vec.at(l)-vec.at(k);
    Ans=max(Sum,Ans) ;
    }
}
cout << Ans << endl ;

}
}

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

inline int max(int a, int b){
	return (a>b)? a : b ;
}

int main(){
	int n, max1, max2, a[5001];

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

		for(int i=0 ; i<n ; i++){
			int sum = 0;
			for(int j=i ; j<n ; j++){
				sum += a[j];
				max1 = max( max1 , sum );
			}
		}
		cout << max1 << endl;
	}
}