Go: package main

import (
        "fmt"
)

func main() {
        for {
                var n int
                _, err := fmt.Scanf("%d", &n)
                if err != nil || n == 0 {
                        break
                }

                var sum [5001]int

                for i := 1; i <= n; i++ {
                        fmt.Scanf("%d", &(sum[i]))
                        if i > 1 {
                                sum[i] += sum[i-1]
                        }
                }

                max_sum := sum[1]
                for i := 1; i <= n; i++ {
                        for j := 0; j < i; j++ {
                                if max_sum < sum[i] - sum[j] {
                                        max_sum = sum[i] - sum[j]
                                }
                        }
                }
                fmt.Printf("%d\n", max_sum)
        }
}

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

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

C++: #include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n&&n!=0)
{
int a[n];
int A=0;
int R=-100000;
for(int h=0;h<n;h++)
{
	cin>>a[h];
}
for(int i=0;i<n;i++)
{
	for(int j=0;j<n-i-1;j++)
	{
	for(int k=i;k<=j;k++)
	{
		A=A+a[k];
		
	}	
	if(R<A)
	{
		R=A;
	}
	A=0;
	}
}
cout<<R<<endl;
}
return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	int ans;
	while (cin >> n&&n) {
		vector<int> p(n);
		for (int i = 0; i < n; i++) {
			cin >> p[i];
		}
		ans = p[0];
		for (int i = 0; i < n; i++) {
			int num = 0;
			for (int j = i; j < n; j++) {
				num += p[j];
				ans = max(ans, num);
			}
		}
		cout << ans << 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,ans;
	while(cin>>N&&N){
		ans = INT_MIN;
		rep(i,N){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		rep(i,N){
			FOR(j,i,N){
				ans = max(ans,sum[j]-sum[i-1]);
			}
		}
		cout<< ans <<endl;
	}
}

C++: #include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
  

  int dataSets;

  while(true){
    vector<int> a;
    cin >> dataSets;
    if(dataSets==0){break;}
    for(int i=0;i<dataSets;i++){
      int tmpa;
      cin >> tmpa;
      a.push_back(tmpa);

    }

    int tmax=0;
    // i?????§????????§?????????????????????
    vector<int> tmpMax(dataSets + 1,0);
    tmpMax[0] = 0;
    for(int i=1;i<dataSets+1;i++){
      tmpMax[i] += tmpMax[i-1] + a[i-1];
    }

    for(int i=0;i<dataSets+1;i++){
      for(int j=i;j<dataSets;j++){
	tmax = max(tmax, tmpMax[j+1] - tmpMax[i]);
      }
    }
    
    cout << tmax << endl;
    
  }

  return 0;

}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

int n, a[5000], s, r;

int main() {
	while (true) {
		scanf("%d",&n);
		if (n==0) break;
		r = -1001001001;
		rep(i,n) scanf("%d",&a[i]);
		rep(i,n) {
			s = 0;
			for (int j = i; j < n; ++j) {
				s += a[j];
				r = max(r, s);
			}
		}
		printf("%d\n",r);
	}
}

C++: #include <iostream>

using namespace std;

int main(){
  int n;
  while(true){
    cin>>n;
    if(!n)break;
    int seq[n];
    for(int i=0;i<n;i++)
      cin>>seq[i];
    int max = 0;
    for(int i=0;i<n;i++){
      for(int j=i;j<n;j++){
	int sum = 0;
	for(int k=i;k<=j;k++)
	  sum+=seq[k];
	if(sum>max)max = sum;
      }
    }
    cout << max << endl;
  }
  return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <deque>
#include <numeric>
#include <vector>

using namespace std;

template <typename C>
vector<int> compact(const C& container) {
  vector<int> compacten;
  int sign = 1;
  int acc = 0;
  for (auto n : container) {
    if (n == 0) { continue; }
    if (sign * n > 0) {
      acc += n;
    } else {
      compacten.push_back(acc);
      acc = n;
      sign *= -1;
    }
  }
  compacten.push_back(acc);
  return compacten;
}

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

    deque<int> seq;
    for (int i = 0; i < n; ++i) {
      int x;
      scanf("%d", &x);
      seq.push_back(x);
    }
    int max_elem;
    if ((max_elem = *max_element(seq.begin(), seq.end())) <= 0) {
      printf("%d\n", max_elem);
      continue;
    }
    while (seq.size() != 0 && seq.front() <= 0) { seq.pop_front(); }
    while (seq.size() != 0 && seq.back() <= 0) { seq.pop_back(); }

    auto compacten_seq = compact(seq);
    vector<int> partial_sums = { compacten_seq.back() };
    for (int i = compacten_seq.size() - 1; i > 0; i -= 2) {
      int s = partial_sums.back() + compacten_seq[i - 1];
      partial_sums.push_back(compacten_seq[i - 2] + (s < 0 ? 0 : s));
    }
    printf("%d\n", *max_element(partial_sums.begin(), partial_sums.end()));
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
using namespace std;
int maxsum(int x,vector<int> a){
	
	vector<int> s(x+1,0);
	int max;
	for(int i=1;i<=x;i++){
		if(s[i-1]<0)
			s[i]=a[i];
		else
			s[i]=s[i-1]+a[i];
	}
	max = *max_element(s.begin(),s.end());
	return max;
	
}

int main(){
	
	int n;
	while(cin>>n,n!=0){
		
		vector<int> a(n+1,0);
		
		for(int i=1;i<=n;i++)
			cin>>a[i];
		
		cout<<maxsum(n,a)<<endl;
	}
	
 	
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>

using namespace std;

int main()
{
	int n;
	while(cin>>n,n){
		vector<long long> dp(n);
		long long res;
		cin>>dp[0];
		res=dp[0];

		for(int i=1;i<n;i++){
			long long a;
			cin>>a;
			dp[i]=max(dp[i-1]+a,a);
			res=max(res,dp[i]);
		}
		cout<<res<<endl;
	}


	return 0;
}

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

int main() {
  int x,n,k;
  int sum[100000],a[5000];
  while(cin >> n) {
    for(int i=0;i<n;i++) {
      cin >> x;
      a[i] = x;
    }
    for(int j=0;j<n;j++) {
      for(int i=j+1;j<n;i++) {
        for(int m=0;m<i-j;m++) {
          sum[k] += a[j+m];
        }
        k++;
      }
    }
    cout << *max_element(sum,sum+k) << endl;
  }
}