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----------------------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>
//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
//const------------------------------------------------------------------------------------------------------------------------
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;

//global-----------------------------------------------------------------------------------------------------------------------
LL a, b, n, ans = 0;
vector<LL> ar;
vector<LL> sum_ar;
//#define DEBUG
//function--------------------------------------------------------------------------------------------------------------------

int main() {
	while ( scanf( "%lld", &n ) && n ) {
		sum_ar.PB( 0 );
		ans = 0;
		rep( i, n ) {
			scanf( "%lld", &a );
			ar.PB( a );
			sum_ar.PB( sum_ar[ i ] + a );
		}
		rep( i, n ) {
			FOR( j, i, n + 1 ) {
#ifdef DEBUG
				debug(i)
				debug(j)
#endif
				ans = max( ans, sum_ar[ j ] - sum_ar[ i ] );
			}
		}
		printf( "%lld\n", ans );
		sum_ar = vector<LL>();
	}
	return 0;
}

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

int main(){
	int n;
	int a;
	int sum;
	int sum2;
	int max;
	cin >> n;
	while(n){
		cin >> sum;
		max = 0;
		for(int i=0;i<n-1;i++){
			cin >> sum2;
			if(sum < sum2){
				sum = sum2;
			}else{
				sum += sum2;
			}
			if(sum > max){
				max = sum;
			}
		}
		cout << max << endl;
		cin >> n;
	}
	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];

    int min_e=*min_element(a.begin(), a.end());
    int max_e=*max_element(a.begin(), a.end());
    if (max_e < 0) {
        printf("%d\n", max_e);
    } else if (min_e < 0) {
        printf("%d\n", max_e-min_e);
    } else {
        printf("%d\n", max_e);
    }
    return 0;
}

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

    return !solved;
}

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

int main(){
	int n, m, a[5001], sum , max;

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

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

vector<int> num;

int main(void){
  while(true){
    int maximum = 0, n;
    cin >> n;
    if(!n)  break;
    num.clear();
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      num.push_back(tmp);
    }
    for(int i = 0; i < num.size(); i++){
      int sum = num[i];
      for(int j = i + 1; j < num.size(); j++){
        sum += num[j];
        if(sum > maximum) maximuma = sum;
      }
    }
    cout << maximum << endl;
  }
  return 0;
}

C++: #include<cstdio>
int main(){int n,i,j,s,m,a[5000];while(scanf("%d",&n)&&n){for(i=0;i<n;i++)scanf("%d",&a[i]);m=-500000001;for(i=0;i<n;i++,s=0)for(j=i;j<n;)if((s+=a[j++])>m)m=s;printf("%d\n",m);}}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int n, T[5001], dp[5001];
	while(cin >> n, n)
	{
		for(int i = 0; i < n; i++)
		{
			cin >> T[i];
		}

		memset(dp, -1, sizeof(dp));

		dp[0] = T[0];

		for(int i = 1; i < n; i++)
		{
			dp[i] = max(dp[i-1] + T[i], T[i]);
		}

		int res = -10000000;
		
		for(int i = 0; i < n; i++)
		{
			res = max(res, dp[i]);
		}

		cout << res << endl;
	}
}

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


int main()
{
    for (int n; cin >> n && n;) {
        vector<int> sequence(n);
        int sum = 0;
        int min = 0;
        int min_buffer = 0;
        int max = numeric_limits<int>::min();
        for (int x, i = 0; i < n && cin >> x; i++) {
            sum += x;
            if (sum < min)
                min_buffer = sum;
            if (sum > max) {
                max = sum;
                min = min_buffer;
            }
        }
        cout << max - min << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <stack>

using namespace std;

stack<int> s;
int ac;

int main(void) {
    while(~scanf("%d", &ac)) {
        if(ac == 0) {
            cout << s.top() << endl;
            s.pop();
        } else {
            s.push(ac);
        }
    }
    return 0;
}