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<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n;
    while(cin>>n,n){
        vi v(n+1,0);
        rep(i,n)cin>>v[i];
        ll ans=0, temp;
        
        for(int i=0;i<n;i++){
            temp=0;
            for(int j=i;j<n;j++){
                temp+=v[j];
                ans=max(ans,temp);
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include <stdio.h>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
	int n,i,num[5000];
	long long int sum[5001];
	while(1){
		sum[0] = 0;
		scanf("%d",&n);
		if(!n) break;
		for(i = 0;i < n;i++){
			scanf("%d",&num[i]);
			sum[i + 1] = sum[i] + num[i];
		}
		sort(sum,sum + n + 1,greater<long long>());
		printf("%lld\n",sum[0] - sum[n]);
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define REP(i,n) rep(i,0,n);
const int MIN_INT = -9999999;

int main(int argc, char *argv[]) {
	int dataN;
	while (EOF != fscanf(stdin, "%d", &dataN)) {
		if (dataN == 0) break;
		const int c_N = dataN;
		int tmp, sums[c_N], max_v=MIN_INT;
		memset(sums, 0, sizeof(sums));
		for (int i = 0; i < c_N; i++) {
			fscanf(stdin, "%d", &tmp);
			sums[i] += tmp;
			max_v = max(max_v, sums[i]);
			for (int j = 0; j < i; j++) {
				sums[j] += tmp;
				max_v = max(max_v, sums[j]);
			}
		}
		printf("%d\n", max_v);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    int n = 0;
    while (cin>>n && n != 0) {
        int a[5001] = {};
        int max = -1000000;
        for (int i = 0; i < n; i++) {
            cin>>a[i];
            if (a[i] >= 0) {
                int temp = 0;
                for (int s = i; s >= 0; s--) {
                    temp += a[s];
                    if (temp > max) max = temp;
                    if (temp < 0) break;
                }
            }
        }
        cout<<max<<endl;
    }
}

C++: #include <cassert>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>

int solve(std::istream& in, int n)
{
    std::vector<int> all(n);
    std::vector<int> koho;
    int temp = 0;
    for(int i = 0; i < n; ++i) {
        in >> all[i];
        if(temp && all[i] < 0){
            koho.push_back(temp);
            temp = 0;
        }else
        if(all[i] > 0){
            temp += all[i];
        }
    }
    koho.push_back(temp);
    if(koho.empty()) return *std::min_element(all.begin(), all.end());
    return *std::max_element(koho.begin(), koho.end());
}
int main()
{
    int n;
    std::cin >> n;
    while(n){
        std::cout << solve(std::cin, n) << std::endl;
        std::cin >> n;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>

using namespace std;


int sumarray(int *array, int idx1, int idx2);


int main(){
  int n, Max, ibuf;
  int *List;

  ifstream ifs("input.txt");

  while(ifs >> n){
    if(n == 0) break; // at end condition

    List = new int[n];  // allocate List

    for(int i=0; i<n; i++){
      ifs >> List[i];
      //cout << List[i] << " "; // for debug
    }

    //cout << endl; // for debug

    Max = 0;
    for(int l=1; l<=n; l++){
      for(int i=0; i<=n-l; i++){
	ibuf = sumarray(List, i, i+l);
	if(ibuf > Max) Max = ibuf;
	//cout << ibuf << endl; // for debug
      }
    }

    cout << Max << endl;

    delete List; // deallocate List
  }

}


int sumarray(int *array, int idx1, int idx2){ // sum array[idx1] ~ array[idx2-1]
  int ret = 0;
  for(int i=idx1; i<idx2; i++){
    ret += array[i];
  }
  return ret;
}

C++: /* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

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

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

signed main()
{
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n, n){
    vi a(n);
    int ans = -99999999;
    REP(i, n) cin >> a[i];
    REP(i, n){
      int sum = 0;
      REPS(j, i, n){
        sum += a[j];
        ans = max(ans, sum);
      }
    }
    print(ans);
  }

  return (0);
}

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

int main()
{
    int n;
    while(cin >> n &&n!=0)
    {
        if(n==0)break;
        long int s[N];
        //memset(s,0,sizeof(int)*N);
        int t;
        long int max = -N*100000;
        long 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<bits//stdc++.h>
using namespace std;
int main(){
	int n;
	int a[5000];
	while(cin>>n&&n!=0){
		int sum3=0;
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++){
			int sum=0;
			int sum2=0;
			for(int j=0;j<=i;j++){
				sum2=0;
				for(int z=j;z<=i;z++){
					sum2+=a[z];
					if(sum<sum2) sum=sum2;
				}
			}
			if(sum3<sum) sum3=sum;
		}
		cout<<sum3<<endl;
	}
}