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 <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[5000];//??????????????¨????????????.
int main(){
	int N;
	int ans = 0;
	while(cin>>N&&N){
		int index=0;
		ans = INT_MIN;//????????§??????????????¨????????????.
		FOR(i,0,N){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,0,N){
			FOR(j,i,N){
				ans = max(ans,sum[j]-sum[i-1]);
			}
		}
		cout<< ans <<endl;
	}
}

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

int main() {
	int n;

	while (cin >> n) {
		if (n == 0) break;
		vector<int> array(n);
		for (int i = 0; i < n; i++) {
			cin >> array.at(i);
		}

		long max = array.at(0);
		for (int j = 0; j < n; j++) {
			long total = 0;
			for (int k = 0; k < n - j; k++) {
				total += array.at(j + k);
				if (total > max) max = total;
			}
		}

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

C++: /**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0022&lang=jp
 */
#include <stdio.h>

int getsign(int d){
	return d >= 0 ? 1 : -1;
}

int seqsum(int n){
	int a[5000];
	int b[5000];
	int c = 0;
	int s = 0;

	scanf("%d", a);
	b[0] = a[0];
	s = getsign(a[0]);

	for(int i=1; i<n; ++i){
		scanf("%d", a+i);
		if(s == getsign(a[i])){
			b[c] += a[i];
		}else{
			b[++c] = a[i];
			s = getsign(a[i]);
		}
	}

	int m = b[0];
	int sum = m;
	if(c == 0){
		if(m >= 0){ return m; }
		m = a[0];
		for(int i=1; i<n; ++i){
			if(m < a[i]){
				m = a[i];
			}
		}
		return m;
	}
	for(int i=1; i<=c; ++i){
		if(m < sum + b[i]){
			sum += b[i];
			m = sum;
		}else if(m < b[i]){
			sum = m = b[i];
		}else{
			sum += b[i];
		}
	}

	return m;
}

int main(void){
	int n = 0;
	while(true){
		scanf("%d", &n);
		if(n == 0){ break;}
		printf("%d\n", seqsum(n));
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int main() {
	for(int n; cin >> n && n;) {
		vector<int> arr(n);
		vector<int> cur(n);
		rep(i,n) cin >> arr[i];
		if(arr[0] > 0) cur[0] = arr[0];
		for(int i = 1; i < n; i++)
			cur[i] = max(arr[i], cur[i - 1] + arr[i]);
		cout << *max_element(all(cur)) << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
using namespace std;

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0) break;
		vector<int> a(n);
		rep(i,0,n) cin>>a[i];
		int MAX=0;
		rep(i,0,n){
			int sum=0;
			rep(j,i,n){
				sum+=a[j];
				MAX=max(MAX,sum);
			}
		}
		o(MAX);
	}
}

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

int main(){
        int n,a[5010];
        while(cin>>n && n){
                for(int i=0; i<n; i++) cin >> a[i];
                long max = 0;
                for(int k = 0; k < n; k++){
                        long sum = 0;
                        for(int i=0; i<n-k; i++){
                                sum += a[i];
                                max = (max>sum)? max:sum;
                        }
                        for(int i=0; i<=k; i++){
                                sum += (a[n-k+i]-a[i]);
                                max = (max>sum)? max:sum;
                        }
                }
                cout << max << endl;
        }

}

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

int main()
{
    int n;
    int MAX=-500000000;
    vector<int> vt;
    while(1){
        cin >> n;
        if(n==0){
            break;
        }
        int a;
        int A=0;
        for(int i=0 ; i<n ; i++){
            cin >> a;
            A+=a;
        }
        vt.push_back(A);
    }
    vector<int>::iterator it = vt.begin();
    while(it!=vt.end()){
        if(MAX<*it){
            MAX=*it;
        }
        it++;
    }
    cout << MAX << endl;
    return 0;
}

C++: #include <iostream>

using namespace std;

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

int main (void) {
    int n, i, j;
    while (1) {
        cin >> n;
        if (n == 0) break;
        int a[n];
        for (i = 0; i < n; i++) {
            cin >> a[i];
        }
        int sum = 0, s;
        for (i = 0; i < n; i++) {
            s = 0;
            for (j = i; j < n; j++) {
                s += a[j];
                if (i != j) sum = max(sum, s);
            }
        }
        cout << sum << endl;
    }
    return 0;
}

C++:  
 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 
 using namespace std;
 
 int arr[5000+5];
 int result[5000+5];
  
 int main()
 {
   int n;
   int count=0;
   while(cin>>n&&(n!=0))
   {
     int sum=0;
     int max=0;
     for(int i=0;i<n;i++)
     {
       cin>>arr[i];
       if((sum+arr[i])>0)
       { 
         sum=sum+arr[i];
         if(sum>max) max=sum;
       }        
       else sum=0;
     }       
     result[count++]=max;              
   }
   for(int i=0;i<count;i++) cout<<result[i]<<endl;
   //while(1);      
   return 0;    
 }

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

int main(){
  int i,j,n,tmp,ans,a[5000];

  while(scanf("%d",&n) && n){
    for(i=0;i<n;i++)scanf("%d",&a[i]);
    
    ans = a[0];
    for(i=0;i<n;i++){
      tmp = a[i];
      for(j=i+1;j<n;j++){
	tmp += a[j];
	ans = max(tmp,ans);
      }
    }
    printf("%d\n",ans);
  }
}