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>
#include <vector>

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    while(1) {
        int n;
        int a[5001] = {0};
        long int ans = -10000000;
        cin >> n;
        if(n == 0) break;

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

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

    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;

#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (!n) break;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int res = -1000000000;
    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = i; j < n; j++) {
	sum += a[j];
	res = max(res, sum);
      }
    }
    cout << res << endl;
  }
}

C++: #include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
long long p[5001]={0};
int main(){
while(1){
memset(p,0,sizeof(p));
long long n,i,j,t,a;
cin>>n;
if(n==0)break;
for(i=1;i<=n;i++){
cin>>a;
p[i]=p[i-1]+a;
}
t=-999999999;
for(i=1;i<=n;i++){
	for(j=0;j<i;j++){
t=max(t,p[i]-p[j]);
}
}
cout<<t<<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 = 0, 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++: #include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<stack>
#include<set>
#include<cmath>

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

#define EPS 1e-6

using namespace std;

int main(){

   int n,a;
   while(true){
   cin >> n;
   if(n==0) break;

   vector<int>v;
   int s=0;
   v.push_back(s);

   rep(i,n){
   cin >> a;
   s+=a;
   v.push_back(s);
   }

   int vmin=0; int vmax=0;
   rep(i,n){
   if(v[i]<vmin) vmin=v[i];
   if(v[i]>vmax) vmax=v[i];

   }

	cout << vmax-vmin << endl;

   }

	return 0;
}

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

int main(){
	int n;
	while(cin >> n, n){
		/*n++;
		vector<int> t(n), v(n);
		t[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> v[i];
			t[i] = max(t[i-1]+v[i], v[i]);
		}*/
		n++;
		vector<int> vec(n),dp(n);
		for(int i=1;i<n;i++)cin >> vec[i];
		//for(int i = 1;i < n;i++)cout << vec[i] << " ";
		dp[0]=0;
		for(int i=1;i<n;i++)dp[i]=max(dp[i-1]+vec[i],vec[i]);
		cout << *max_element(dp.begin()+1, dp.end()) << endl;
	}
	return 0; 
}

/*
7
-5
-1
6
4
9
-6
-7
*/

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

int main(){
  int n ,hoge ,total=0 ,max=0;
  while( true ){
    cin >> n;
    if( !n ){
      break;
    }
    for( int i=0 ; i<n ; i++ ){
      cin >> hoge;
      total += hoge;
      if( total < 0 ) total = 0;
      if( total > max ) max = total;
    }
    cout << max << endl;
    total = 0;
    max = 0;
  }
}

C++: #include <iostream>

using namespace std;

int main()
{
  while(1){
    int n;
    int a[5000];
    cin >> n;
    if(n == 0)
      break;
    else{
      for(int i = 0; i < n; i++)
	cin >> a[i];
      int ans = a[0], num;
      for(int i = 0; i < n; i++){
	num = 0;
	for(int j = i; j < n; j++){
	  num += a[j];
	  ans = (num > ans) ? num : ans;
	}
      }
      cout << ans << endl;
    }
  }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define INF=-10000000000000000
int main(void){
    int n,a,max=INF;
    while(std::cin>>n){
        if(n==0) break;
        std::vector<int> dp(n+1);
        dp[0]=INF;
        for(int i=0;i<n;i++){
            std::cin>>a;
            dp[i+1]=(a>0?dp[i]+a:a);
            max=std::max(max,dp[i+1]);
        }
        std::cout<<max<<std::endl;
    
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	while (1) {
		int d[5000], a, i, n,ans=-100001,j;
		cin >> n;
		if (n == 0) {
			break;
		}
		for (i = 0; i < n; i++) {
			cin >> d[i];
		}
		for (i = 1; i < n; i++) {
			d[i] += d[i - 1];
		}
		for (i = 0; i < n; i++) {
			for (j = 0; j < i; j++) {
				ans = max(ans, d[i] - d[j]);
			}
		}
		cout << ans << endl;
		
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
	int n, *a;
	int ans, add;
	while (1) {
		cin >> n;
		if (n == 0)
			break;
		a = new int[n];
		for (int i = 0; i < n; i++)
			cin >> a[i];
		ans = 0;
		for (int i = 0; i < n; i++) {
			add = a[i];
			for (int j = i + 1; j < n; j++) {
				add += a[j];
				ans = max(ans, add);
			}
		}
		cout << ans << endl;
		delete[] a;
	}
	return 0;
}

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

using namespace std;

bool testcase_ends() {
    size_t n;
    scanf("%zu", &n);

    if (!n) return 1;

    vector<int> a(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &a[i]);

    for (size_t i=1; i<n; ++i)
        a[i] += a[i-1];

    vector<int>::iterator min_=min_element(a.begin(), a.end());
    vector<int>::iterator max_=max_element(a.begin(), a.end());
    if (*min_ < 0 && min_ < max_) {
        printf("%d\n", *max_-*min_);
    } else {
        printf("%d\n", *max_);
    }
    return 0;
}

int main() {
    int solved=0;
    while (!testcase_ends())
        ++solved;

    return !solved;
}