Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var infty = 100000 * 2
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	scanner.Scan()
	return strconv.Atoi(scanner.Text())
}

func findMaximumSubarray(arr []int) int {
	currentMaxSum, maxSumContainsTail := -infty, -infty

	for j := range arr {
		if arr[j] > maxSumContainsTail+arr[j] {
			maxSumContainsTail = arr[j]
		} else {
			maxSumContainsTail += arr[j]
		}
		if currentMaxSum < maxSumContainsTail {
			currentMaxSum = maxSumContainsTail
		}

		// fmt.Println(arr[j], currentMaxSum, maxSumContainsTail)
	}
	return currentMaxSum
}

func main() {
	scanner.Split(bufio.ScanWords)
	for {
		size, _ := nextInt()
		if size == 0 {
			break
		}

		arr := make([]int, size)
		for i := range arr {
			n, _ := nextInt()
			arr[i] = n
		}

		maximumSum := findMaximumSubarray(arr)
		fmt.Println(maximumSum)
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int,int> Pi;

const int INF=100000000;
const long long int INF_=1000000000000000000;

int main(){
	int N;
	while(cin >> N&&N){
		vector<int> A(N);
		REP(i,0,N) cin >> A[i];
		vector<int> s(N);
		s[0]=A[0];
		REP(i,1,N) s[i]=s[i-1]+A[i];
		lli ans=0;
		REP(i,0,N) REP(j,i+1,N) if(ans<s[j]-s[i]) ans=s[j]-s[i];
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
int n;
int a[5001];
while(1){
	cin>>n;
	if(n==0){
		break;
	}
	for (int kkk=1;kkk<=n;kkk++){
		a[kkk]=0;
	}
	for (int kk=1;kk<=n;kk++){
		cin>>a[kk];
		
	}
	int high=a[1],sum=0;
	for(int i=1;i<=n;i++){
		sum=sum+a[i];
		if(sum>=high){
			high=sum;
		}
		if(sum<=0){
			sum=0;
		
	}}
cout<<high<<endl;

}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	vector<int> v(5000);
	int n , sum=0 , max=-2000000000;
	while(cin>>n,n){
		sum=0;
		max=-2000000000;
		for(int i=0;i<n;++i){
			cin >> v[i];
		}
		for(int i=n;i>=0;--i){
			for(int j=i;j<n;++j){
			sum+=v[j];
			if(sum>max) max=sum;
			}
			sum=0;
		}
		cout << max << endl;
	}
	return 0; 
}

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

int main(){
  int n;
  cin >> n;
  while(n!=0){
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a.at(i);

    vector<int> s(n+1);
    s.at(0) = 0;
    for(int i=1;i<n+1;i++) s.at(i) = s.at(i-1)+a.at(i-1);

    int ans=0;
    for(int i=1;i<=n;i++){
      for(int j=0;j<i;j++){
        ans = max(s.at(i)-s.at(j),ans);
      }
    }

    cout << ans << endl;

    cin >> n;
  }
}

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[1000];
int main(){
	int N;
	int ans = 0;
	while(cin>>N&&N){
		int index=0;
		ans = INT_MIN;
		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 <stdio.h>

int main(void)
{
  while(1){
    int n;
    scanf("%d", &n);
    if(n==0){
      break;
    }

    int a[5000];
    int max;

    int i,j;
    for(i=0; i<n; ++i){
      scanf("%d", &a[i]);
      int sum = 0;
      for(j=i; j>=0; --j){
        sum += a[j];
        if((i==0 && j==0) || sum>max){
          max = sum;
        }
      }
    }

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

  return 0;
}

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

int main(){
int n,m=0;
int a[5001];
int sum;
int big;
while(cin>>n){
for(int i=0;i<n;i++)cin>>a[i];
big=a[0];
for(int i=0;i<n-1;i++){
if(a[i+1]>big)big=a[i+1];
if((a[i]>=0&&a[i+1]>=0)||(a[i]<=0&&a[i+1]<=0)){
a[i]+=a[i+1];
for(int j=i+1;j<n-1;j++)a[j]=a[j+1];
i--;
n--;}}

for(int i=1;i<n+1;i++){
for(int j=0;j<n-i+1;j++){
sum=0;
for(int k=0;k<i;k++){
sum+=a[j+k];}
if(sum>big){big=sum;}}}
cout<<big<<endl;}}

C++: #include <iostream>
using namespace std;
int n,a[5000];
int main(){
	int i,j,t,s;
	while(cin >> n && n){
		s = 0;
		t = -1000000;
		for(i=0;i<n;i++){
			cin >> a[i];
		}
		for(i=0;i<n;i++){
			s += a[i];
			if(t < s) t = s;
				for(j=i+1;j<n;j++){
					s += a[j];
					if(t < s) t = s;
				}
			s = 0;
		}
		cout << t << endl;
	}
	return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

int main() {

  int n;
  loop {
    cin >> n;
    if (!cin) break;
    if (!n) break;

    int ac = 0;
    vi xs;
    rep (_, n) {
      int x; cin >> x;
      ac = max(x, ac+x);
      xs.push_back(ac);
    }

    int mx = -INF;
    for (int x:xs) mx = max(x,mx);
    cout << mx << endl;

  }

  return 0;
}

C++: include <cstdio>
#include <algorithm>

using namespace std;

int N,K[5001],T;

int main()
{
        scanf("%d",&N);
        if (N == 0) return 0;

        T = 0;

        for (int i=1;i<=N;i++){
                scanf("%d",K+i);
        }

        for (int i=1;i<=N;i++) {
                K[i] += K[i-1];
        }

        for (int i=0;i<=N;i++) {
                for (int j=i;j<=N;j++) {
                        T = max(T,K[j]-K[i]);
                }
        }

        printf("%d\n",T);

        main(); 
}

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

using namespace std;

int main() {
  int n;
  vector<int> datas;
  vector<int> sums;

  while (cin >> n, n != 0) {
    int input;
    for (int n_i = 0; n_i < n; n_i++) {
      cin >> input;
      datas.push_back(input);
    }
    for (int data_i = 0; data_i < n-1; data_i++) {
      sums.push_back(datas[data_i]+datas[data_i+1]);
    }

    int max = -1;
    for (auto sum_i = sums.begin(); sum_i != sums.end(); sum_i++)
      if (max < *sum_i)
        max = *sum_i;
    cout << max << endl;
  }

  return 0;
}