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 <algorithm>
#include <string>

using namespace std;

int n;
int a[50001];
int S[50001];


int main(){

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

  int sum = 0; S[0] = 0;
  for (int i = 0; i < n ; ++i)
  {
    sum += a[i];
    S[i + 1] = sum;
    
  }

  int max = 0;
  for (int i = 0; i < n + 1; ++i)
  {
    for (int k = 0; k < i + 1; ++k)
    {
      if(S[i] - S[k] > max) max = S[i] - S[k];
    }
  }

  cout << max << endl;

  }
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <iostream>


using namespace std;

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

		for (int i = 0; i < n; ++i)
			scanf("%d", a+i);

		int res = INT_MIN;
		int sum = 0;
		for (int i = 0; i < n; ++i)
		{
			sum = max(sum+a[i], 0);
			if (sum > res)
				res = sum;
		}
		printf("%d\n", res);
	}

	return 0;
}

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

#define INF (1 << 20)
#define EPS (1e-10)
#define EQ(a,b) (fabs((a)-(b)) < EPS)

int main(){
	int n;
	while (cin >> n && n != 0) {
		int ret = -INF;
		int a[5000];
		int memo[5000];
		for (int i = 0; i < n; ++i) cin >> a[i], memo[i] = -INF;
		for (int i = 0; i < n; ++i) {
			memo[i] = max(memo[i], a[i]);
			for (int j = i+1; j < n; ++j) {
				memo[j] = max(memo[j], memo[j-1] + a[j]);
			}
		}
		for (int i = 0; i < n; ++i) ret = max(ret, memo[i]);
		cout << ret << endl;
	}
	return 0;
}

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

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

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

int main(){
  int n,m,s,a;
  // while(cin>>n,n)
  // int i,j;
  // i=1;
  // j=++i;
  // cout << i<<j;
  // i=1;
  // j=i++;
  // cout << i<<j;
  // while(++i,i<=10)
  //   cout<<i<<endl;
  while(cin>>n,n){
    cin>>a;
    m=s=a;n--;
    while(n--){
      cin>>a;
      if(s<0)s=a;
      else s+=a;
      m=max(s,m);
    }
    cout << m<<endl;
  }
  return 0;
}

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

using namespace std;
static const int MAXV = 5000;

int main() {
  while(1) {
    int n, data[MAXV], max=0, sum=0;
    scanf("%d", &n);
    if (n==0) break;
    for(int i=0; i<n; i++) scanf("%d", &data[i]);
    //cout << data[0] <<" " << data[1] <<endl;
    for (int i=0; i<n; i++) {
      for (int j=i; j<n; j++) {
	sum+=data[j];
	if(max<sum) max=sum;
      }
      sum=0;
    }
    printf("%d", max);
  }
}

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

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

int n;
vector<int> v;

long long s[5000][5000];

int main(){
    while(cin>>n,n){
        v=vector<int>(n);
        REP(i,n)cin>>v[i];
        long long ans=-(1<<30);
        REP(i,n){
            s[i][i]=v[i];
            ans=max(s[i][i],ans);
            for(int j=i+1; j<n; j++){
                s[i][j]=s[i][j-1]+v[j];
                ans=max(s[i][j],ans);
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include <iostream>
int main(){
	int n, v[5000], m;
	while(std::cin >> n, n){
		for(int i=0;i<n;i++)std::cin >> v[i];

		m = v[0];
		for(int i=0;i<n;i++)
			for(int j=i,k=v[i];j<n;j++,k+=v[j])
				if(k>m)m=k;

		std::cout << m << '\n';
	}	
}

C++: #include <bits/stdc++.h>

using namespace std;

int main() {

    int n;

    while(cin >> n, n) {

        int num[n];
        int dp[n + 1][n + 1];

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

        memset(dp, 0, sizeof(dp));

        for(int i = 1; i <= n; ++i) {
            for(int j = i; j <= n; ++j) {
                dp[i][j] = dp[i][j - 1] + num[j - 1];
                if(dp[i][0] < dp[i][j]) {
                    dp[i][0] = dp[i][j];
                }
            }
            if(dp[i][0] < dp[i - 1][0]) {
                dp[i][0] = dp[i - 1][0];
            }
        }

        cout << dp[n][0] << 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[3000];
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-2]);
			}
		}
		cout<< ans <<endl;
	}
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        
        int data[1000];
        
        rep(i,n) cin>>data[i];
        
        ll maxi=-999999999999;
        
        for(int i=0;i<n;i++){
            ll sum[1000]={};
            sum[i]=data[i];
            maxi=max(maxi,sum[i]);
            
            for(int j=i+1;j<n;j++){
                sum[j]=sum[j-1]+data[j];
                maxi=max(maxi,sum[j]);
            }

        }
        
        
        cout<<maxi<<endl;
    }
}

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

int main(){
	int n;
	int a;
	int sum;
	int sum2;
	int sum3;
	long int max;
	cin >> n;
	while(n){
		cin >> sum;
		cin >> sum2;
		sum += sum2;
		max = sum;
		for(int i=0;i<n-2;i++){
			cin >> sum3;
			sum += sum3;
			sum2 += sum3;
			if(sum < sum2){
				sum = sum2;
			}
			if(sum > max){
				max = sum;
			}
			sum2 = sum3;
		}
		cout << max << endl;
		cin >> n;
	}
	return 0;
}