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 <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <complex>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const double PI = 3.141592653589793238462643383279502884L;
const int LARGE_PRIME = 1000000007;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i,a,cont,next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i,a,b,s) repfn(i,a,i<b,i+s)
#define repab(i,a,b) repby(i,a,b,1)
#define rep(i,b) repab(i,0,b)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  for (;;) {
    int n;
    vi v;

    cin >> n;
    if (!n)
      break;

    while (n--) {
      int tmp;
      cin >> tmp;
      v.pb(tmp);
    }

    vi w(v);
    w.pb(0);
    int prev = 0;
    int accm = -LARGE_PRIME;
    for (int j = 0; j < sz(v); j++) {
      for (int i = 0; i < sz(v); i++) {
        w[i] = max(w[i], v[i] + w[i+1]);
        accm = max(accm, w[i]);
      }
    }
    cout << accm << endl;
  }
  return 0;
}

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

int main(){
	bool flag[5000] = {false};
	int n, in[5000];
	long long ans, tmp = 0ll;
	
	while(true){
		cin >> n;
		if(n == 0)
			break;

		for(int i = 0; i < n; ++i){
			cin >> in[i];
			if(in[i] > 0)
				flag[i] = true;
		}//input

		for(int i = 0; i < n; ++i){
			for(int j = i; j < n; ++j){
				if(flag[i] && flag[j]){
					for(int k = i; k <= j; ++k)
						tmp += in[k];
					if(tmp > ans){
						ans = tmp; 
						tmp = 0ll;
					}	
					else
						tmp = 0ll;
				}
			}
		}
		
		cout << ans << endl;//output
		
		ans = 0ll;
		for(int i = 0; i < n; ++i)
			flag[i] = false;//intialize
	
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	while ( true )
	{
		int n;cin>>n;
		if(n==0)
			break;
		vector<int> a(n);
		for ( int i=0; i<n; i++ )
			cin>>a[i];
		long long ans=-10000000000ll;
		for ( int i=0; i<n; i++ )
		{
			long long t=0;
			for ( int j=i; j<n; j++ )
				t += a[j],
				ans = max(t,ans);
		}
		cout<<ans<<endl;
	}
}

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

int main(){

	int n;
	long long m, a[5001];

	a[0] = 0;
	while(cin >> n, n != 0){
		for(int i=1; i<=n; i++){
			cin >> a[i];
			a[i] += a[i-1];
		}

		m = 0;
		for(int i=0; i<=n; i++){
			for(int j=0; j<=n; j++){
				m = max(m, a[j] - a[i]);
			}
		}
		cout << m << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
	int time,code;
	vector<int> line;
	long max;
	long doll=0;
	vector<int>::iterator he,he2;
	while(true){
		cin>>time;
		if(time!=0){
			line.clear();
		}else {
			break;
		}
		for(int i=0;i<time;++i){
			cin>>code;
			line.push_back(code);
		}
		max=line[0];
		for(he=line.begin();he!=line.end();++he){
			for(he2=he;he2!=line.end();++he2){
				doll+=*he2;
				if(doll>max){
					max=doll;
				}
			}
			doll=0;
		}
		cout<<max<<endl;
	}
	return 0;
}

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

int main() {
	int n;
	vector<int> r;
	while (true)
	{
		scanf("%d", &n);
		if (n==0)break;
		int max=0,now=0,in=0;
		for (int i=0; i<n; i++)
		{
			cin >> in;
			now += in;
			if (now < 0) now=0;
			if (now > max) max=now;
		}
		r.push_back(max);
	}
	for (int i=0; i<r.size(); i++)
	{
		cout << r[i] << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        int stage[1000] = {0};
        for(int i = 1;i <= n; i++){
            scanf("%d",&stage[i]);
        }
        int dp[1000]={0};
        dp[1] = stage[1];
        dp[2] = max(stage[2],dp[1]+stage[2]);
        int x = 0;
        int ans=dp[2];
        for(int i = 2;i <= n; i++){
            x = max(stage[i+1],stage[i+1]+dp[i]);
            if(x > ans)ans = x;
            dp[i+1] = x;
        }
        printf("%d\n",ans);
    }
    return 0;
}

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



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

		vector<int> s = vector<int>(1, 0);
		bool f = true;
		for (int i = 0; i < n; i++)
		{
			if (a[i] >= 0)
			{
				if (!f)
					f = true;
				s[0] += a[i];
			}
			else if(s[0] > a[i])
			{
				if (f)
				{
					s.push_back(s[0]);
					f = false;
				}
				s[0] += a[i];
			}
			else
			{
				s[0] = 0;
			}

		}
		for (int i = 1; i < s.size(); i++)
		{
			if (s[i] > s[0])
				s[0] = s[i];
		}
		cout << s[0] << endl;
	}

	return 0;
}

C++: #include <stdio.h>

int ans ;
int sum ;
int n ;
int p ;
int q ;
int num[5010] ;

int main()
{
	while ( scanf ( "%d" , &n ) == 1 && n ) {
		for ( int i = 0 ; i < n ; i++ ) {
			scanf ( "%d" , &num[i] ) ;
		}
		ans = -2147483647 ;
		sum = 0 ;
		for ( int i = 0 ; i < n ; i++ ) {
			sum += num[i] ;
			if ( sum > ans ) {
				ans = sum ;	
				q = i ;
			}
			if ( sum < 0 ) {
				sum = 0 ;
				p = i + 1 ;	
			}
		}
		printf ( "%d\n" , ans ) ;
	}
	return 0 ;
}

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

int main(){
  int n, a;
  long long int max_, tmp;
  while(cin >> n){
    max_=0; tmp=0; tmp=0;
    for(int i=0; i<n; i++){
      cin >> a;
      tmp = max(0,tmp+a);
      max_ = max(tmp,max_);
    }
    cout << max_ << endl;
  }
  return 0;
}