Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sum := make([]int, 5001)
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			a := nextInt()
			sum[i+1] = sum[i]+a
		}
		ret := sum[1]
		for i := 0; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				ret = max(ret, sum[j]-sum[i])
			}
		}
		fmt.Println(ret)
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        vector<ll> v(n),rui(n);
        rep(i,0,n){
            cin>>v[i];
            if(i==0)rui[0]=v[0];
            else rui[i]=rui[i-1]+v[i];
        }
    
    ll ans=-100000000000000000;
    rep(i,0,n-1){
        rep(j,i+1,n){
           ans=max(ans,rui[j]-rui[i]);
        }
    }
    rep(i,0,n){
        ans=max(ans,rui[i]);
    }
    cout<<ans<<endl;
    }
    
  
    return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;

char s[10000];

int main()
{
	while(1)
	{
		int n;
		scanf("%d",&n);
		if(n == 0)
		{
			break;
		}
		int maxw = 0;
		int ms = 0;
		int now = 0;
		for(int i = 0; i < n; i++)
		{
			int w;
			scanf("%d",&w);
			now += w;
			maxw = max(maxw,now - ms);
			ms = min(ms,now);
		}
		printf("%d\n",maxw);
	}
	return 0;
}

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

int a[5001] = {0};
int main() {
  int n;
  while(cin >> n) {
  if(n == 0) break;
  for(int i = 1; i <= n; i++) {
    cin >> a[i];
  }

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

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 < 0 ) {
				sum = 0 ;
				p = i + 1 ;	
			}
			if ( sum > ans ) {
				ans = sum ;	
				q = i ;
			}
		}
		printf ( "%d\n" , ans ) ;
	}
	return 0 ;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

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

int a[5000];
int dp[5000];

int main(){
	ios::sync_with_stdio(false);

	int n;
	int smax;

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

		REP(i, n)	scanf("%d", &a[i]);

		dp[0]=a[0];
		smax =a[0];

		FOR(i, 1, n){
			dp[i]=max(dp[i-1]+a[i], a[i]);
		}

		REP(i, n){
				smax=max(dp[i], smax);
		}

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

C++: #include<stdio.h>

int main(){

	int i,j,n;
	long item[5000],sum,Max;

	while(scanf("%d",&n)!=EOF){
		if(n==0) break;
		Max=0;
		sum=0;

		for(i=0;i<n;i++){
			scanf("%ld",&item[i]);
			for(j=i;i<n;j++){
				sum+=item[j];
				if(Max<sum) Max=sum;
				
			}
					
		}
		printf("%ld\n",Max);


	}



	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main()
{
    int n,t,mx;
    while(cin >> n, n)
    {
        mx = -(1<<30);
        int dt[5000]={0};
        for(int i=0; i<n; i++)
        {
            cin >> t;
            for(int j=0; j<=i; j++)
            {
                dt[j]+=t;
                mx=max(mx,dt[j]);
            }
        }
        cout << mx << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
using namespace std;
long int maxsum(long int x,vector<long int> a){
	
	vector<long int> s(x+1,0);
	long 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(){
	
	long int n;
	while(cin>>n,n!=0){
		
		vector<long int> a(n+1,0);
		
		for(long int i=1;i<=n;i++)
			cin>>a[i];
		
		cout<<maxsum(n,a)<<endl;
	}
	
 	
}

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

using namespace std;

int main()
{
	int n;

	while (scanf("%d", &n), n) {
		int s[5001] = {};

		for (int i = 1; i <= n; ++i) {
			int a; scanf("%d", &a);
			s[i] = a + s[i - 1];
		}

        int ma = -100000;

		for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
			ma = max(ma, s[i] - s[j - 1]);
		}

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

C++: #include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
#define N 5001
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
    int s[N];
    int n;
    while(cin >> n &&n)
    {
        memset(s,0,sizeof(int)*N);
        int t;
        int max = 0;
        int min = 0;
        for(int i=0;i<n;i++){
            cin >>t;
            s[i+1] = s[i]+t;
            if(max<s[i+1])max = s[i+1];
            if(min>s[i+1])min = s[i+1];
        }
        cout << max -min << endl;

    }

    return 0;
}

C++: #include<iostream>
#include<climits>
using namespace std;
 
int main(){
    int n,a[5001];
    int ans;
    a[0]=0;
    while(cin>>n&&n){
        ans = INT_MIN;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            a[i] += a[i-1];
        }
        for(int i=1;i<=n;i++){
            for(int j=i;j<=n;j++){
                ans = max(ans,a[j]-a[i-1]);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}