Go: package main

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

var infty = 100000 * 2
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	scanner.Scan()
	return strconv.Atoi(scanner.Text())
}

func findMaximumSubarray(arr []int) int {
	currentMaxSum, maxSumContainsTail := -infty, -infty

	for j := range arr {
		if arr[j] > maxSumContainsTail+arr[j] {
			maxSumContainsTail = arr[j]
		} else {
			maxSumContainsTail += arr[j]
		}
		if currentMaxSum < maxSumContainsTail {
			currentMaxSum = maxSumContainsTail
		}

		// fmt.Println(arr[j], currentMaxSum, maxSumContainsTail)
	}
	return currentMaxSum
}

func main() {
	scanner.Split(bufio.ScanWords)
	for {
		size, _ := nextInt()
		if size == 0 {
			break
		}

		arr := make([]int, size)
		for i := range arr {
			n, _ := nextInt()
			arr[i] = n
		}

		maximumSum := findMaximumSubarray(arr)
		fmt.Println(maximumSum)
	}
}

C++: #include<cstdio>
#include<iostream>

#define MAX 5000

using namespace std;

int main(void){

	int n,a[5000];
	int wa,max;

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

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;

ll ara[10000];
int main()
{
    ll n;
    while(scanf("%lld", &n))
    {
        if(n==0) break;
        for(ll i=1; i<=n; i++){
            scanf("%lld", &ara[i]);
        }

        ll p = 0;
        for(ll i = 1; i <= n; i++){
            ll s = 0;
            for(ll j = i; j <= n; j++){
                s += ara[j];
                p = max(p,s);
            }
        }
        printf("%lld\n", p);
    }

    return 0;
}

C++: #include <stdio.h>
main(){
  int i,n,j,sum,big=-3000000,a[n];
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
      sum=0;
      for(j=i;j<n;j++){
	sum+=a[j];
	if(sum>big){
	  big=sum;
	}
      }
    }
    printf("%d\n",big);
  }
  return 0;
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(ll s : (x)) cin >> s
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
// template <typename T = long long> inline T IN() {
//     T x;
//     cin >> x;
//     return (x);
// }
// inline void CIN() {}
// template <class Head, class... Tail>
// inline void CIN(Head &&head, Tail &&... tail) {
//     cin >> head;
//     CIN(move(tail)...);
// } CIN(__VA_ARGS__) CIN(__VA_ARGS__) CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
// typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int n;
V a;
VL s;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        cin >> n;
        if(n == 0) return 0;
        a.resize(n);
        s.resize(n + 1);
        REP(i, n) cin >> a[i];
        s[0] = 0;
        REP(i, n) { s[i + 1] += s[i] + a[i]; }
        ll ans = -LINF;
        REP(i, n + 1) REP(j, i) { ans = max(ans, s[i] - s[j]); }
        cout << ans << "\n";
        a.clear();
        s.clear();
    }
}

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

inline int max(int a, int b){
	return (a>b)? a : b ;
}

int main(){
	int n, max1, max2, sum, a[5001];

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

		for(int i=0 ; i<n ; i++){
			max2 = max( max2+a[i] , 0 );
			max1 = max( max2 , max1 );
		}
		cout << max1 << endl;
	}
}

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

int main(){
	int N;
	while(cin >> N && N > 0){
		int a[N];
		REP(i,N){
			cin >> a[i];
		}

		int maximum = a[0];
        REP(i,N){
            int sum = 0;
            for(int j = i; j < N; j++){
					sum += a[j];
                    maximum = max(sum,maximum);
            }
		}
		cout << maximum << endl;
	}
}

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

using namespace std;

int s[5001];

int main()
{
    int n;

    while (scanf("%d", &n), n) {
        memset(s, 0, sizeof(s));

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

        int ma = INT_MIN;

        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++: #pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    while(true){
        int n; cin>>n;
        if(n == 0) return 0;
        vector<int> a(n);
        for(int i=0; i<n; i++) cin>>a[i];

        vector<int> dp(n, 0);
        dp[0] = a[0];
        for(int i=1; i<n; i++){
            dp[i] = max(a[i], dp[i-1] + a[i]);
        }

        cout << *max_element(all(dp)) << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>

#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 LLONG_MAX
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 5005

int main(){


    ll n;
    while(cin >> n,n){
        vector<ll> arr(ARRAY_MAX,0);
        REP(i,n){
            cin >> arr[i+1];
        }
        arr[0] = 0;
        REP(i,n){
            arr[i+1] += arr[i];
        }

        ll maxi = -INF;
        for(int i = n;i >= 0;i--){
            for(int j = 0;j < i;j++){
                maxi = max(maxi,arr[i]-arr[j]);
            }
        }
        cout << maxi << endl;
    }

    return 0;
}