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 main() {

  long long int n = 0;

  while( cin >> n, n) {

    long long int max_ = -10000000;

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

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

  return 0;

}

C++: #include <iostream>
#include <climits>
int main()
{
  while (1) {
    int n;
    std::cin >> n;
    if (n == 0) break;
    int max = -INT_MAX;
    int a[n];
    for (int i = 0;i < n; i++) {
      std::cin >> a[i];
    }
    for (int i  = 0; i < n; i++) {
      if (a[i] < 0) continue;
      int temp = a[i];
      for (int j = i + 1; j < n; j++) {
        temp += a[j];
        if (temp > max) max = temp;
      }
    }
    std::cout << max << std::endl;
  }
}

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

int a[5005];
int dp[5005];
int n;

int main(){



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

        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        long long p = 0;
        for(int i=0;i<n;i++){
            long long k = a[i];
            for(int j=i+1;j<n;j++){
                k = k + a[j];
                p =max(p,k);
            }
        }

        cout<<p<<"\n";

    }

}

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]);
		int vmax = *max_element(all(cur));
		cout << (vmax == 0 ? *max_element(all(arr)) : vmax) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        int plus[5000] = {0}, max = -1000000, input;
        rep(i,n){
            cin >> input;
            plus[i]+= input;
            plus[i+1] = plus[i];
            if(max < plus[i]){
                max = plus[i];
            }
        }
        rep(i,n){
            rep(j,i-1){
                if(max < plus[i] - plus[j]){
                    max = plus[i] - plus[j];
                }
            }
        }
        cout << max << endl;
    }
}

C++: /*
	0022:Maximum Sum Sequence
*/
#include	<iostream>
#include	<algorithm>

using namespace std;

int main(void) {
	int n, S[5000] = { 0 }, numsMax = 0;
	while(1) {
		cin >> n;
		if(n == 0) { break; }
		for(int i = 0; i < n; i++) {
			cin >> S[i];
		}
		numsMax = 0;
		for(int i = 0; i < n; i++) {
			int preSum = 0;
			for(int j = i; j < n; j++) {
				preSum += S[j];
				numsMax = max(preSum, numsMax);
			}
		}
		cout << numsMax << endl;
	}
}

C++: #include <cstdio>
#include <algorithm>
#define INF 1e+18
#define MAX_SIZE 1 << 17
using namespace std;

typedef long long ll;

int n,k;
ll v[100000];
ll segMax[2][2 * MAX_SIZE - 1],segAdd[2][2 * MAX_SIZE - 1];

void add(int num,int a,int b,ll x,int k = 0,int l = 0,int r = n){
	if(b <= l || r <= a) return;
	if(a <= l && r <= b){
		segAdd[num][k] += x;
		return;
	}
	add(num,a,b,x,k * 2 + 1,l,(l + r) / 2);
	add(num,a,b,x,k * 2 + 2,(l + r) / 2,r);
	segMax[num][k] = max(segMax[num][k * 2 + 1] + segAdd[num][k * 2 + 1],segMax[num][k * 2 + 2] + segAdd[num][k * 2 + 2]);
}

ll get(int num,int a,int b,int k = 0,int l = 0,int r = n){
	if(b <= l || r <= a) return -INF;
	if(a <= l && r <= b) return segAdd[num][k] + segMax[num][k];
	return max(get(num,a,b,k * 2 + 1,l,(l + r) / 2),get(num,a,b,k * 2 + 2,(l + r) / 2,r)) + segAdd[num][k];
}

void init(){
	int t = 1;
	while(t < n + 1) t *= 2;
	for(int i = 0;i < t * 2 - 1;i++){
		segMax[0][i] = -INF;
		segMax[1][i] = -INF;
	}
	segMax[0][t - 1] = 0;
	for(int i = 0;i < n;i++) segMax[0][i + t] = segMax[0][i + t - 1] + v[i];
	ll ma = -INF;
	for(int i = n;i >= 0;i--) {
		ma = max(ma,segMax[0][i + t - 1]);
		segMax[1][i + t - 1] = ma - segMax[0][i + t - 1];
	}
	for(int i = t - 2;i >= 0;i--) {
		segMax[0][i] = max(segMax[0][i * 2 + 1],segMax[0][i * 2 + 2]);
		segMax[1][i] = max(segMax[1][i * 2 + 1],segMax[1][i * 2 + 2]);
	}
	n = t;
}

int main(){
	scanf("%d %d",&n,&k);
	for(int i = 0;i < n;i++) scanf("%lld",&v[i]);
	init();
	for(int i = 0;i < k - 1;i++){
		
	}
	printf("%lld\n",get(1,0,n));
	return 0;
}

C++: #include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (((ll)1<<31)-1)
#define eps LDBL_EPSILON
#define moder (1000000007)
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
#define ggr getchar();getchar();return 0;
using namespace std;
int n,a[5010],b[5010];
signed main(){
	while(true){
		cin>>n;
		if(!n)break;
		rep(i,n){
			cin>>a[i];
			if(i)a[i]+=a[i-1];
		}
		rep(i,n){
			if(i)b[i]=min(b[i-1],a[i]);
			else b[i]=min((ll)0,a[i]);
		}
		int ans=-INF;
		rep(i,n){
			ans=max(ans,a[i]-b[i-1]);
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n;
    while(cin>>n,n){
        vi v(n+1,0);
        rep(i,n)cin>>v[i];
        ll ans=v[0], temp;
        for(int i=0;i<n;i++){
            temp=v[i];
            for(int j=i+1;j<n;j++){
                temp+=v[j];
                ans=max(ans,temp);
            }
        }
        cout<<ans<<endl;
    }
}