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 <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>


using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long  int N,a[56789],dp=0,res=0;
int main()
{
    cout << fixed << setprecision(18);
    cin>>N;
    while(N!=0){
        dp=-INF;
        res=-INF;
        for(long long int i = 1; i <= N; i++){
            cin>>a[i];
            dp=max(a[i],dp+a[i]);
            res=max(dp,res);
        }
        cout<<res<<endl;
        cin>>N;
    }
    
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;

int main()
{
  int n,a;
  int i,j;
  int b[5005]={};

  while(1){
    priority_queue<int> pq;
    cin>>n;
    if(n==0)break;
    for(i=1;i<=n;i++){
      cin>>a;
      b[i]=b[i-1]+a;
      for(j=i;j>=0;j--)
	pq.push(b[i]-b[j]);
    }
    cout<<pq.top()<<endl;
  }
}

C++: #include<bits/stdc++.h>
#define INF LLONG_MAX-1
using namespace std;
typedef long long ll;

ll a[100001];
int main(){
	ll n;
	ll cnt = 0;
	scanf("%lld", &n);
	for (ll i = 0; i < n; i++){
		scanf("%lld", &a[i]);
		cnt += a[i];
	}
	ll Max = cnt;
	ll w = 0;
	for (ll i = 0; i < n; i++){
		cnt -= a[i];
		if (Max < cnt) {
			w = i;
			Max = cnt;
		}
	}
	cnt = Max;
	for (ll i = n - 1; i > w; i--){
		cnt -= a[i];
		Max = max(Max, cnt);
	}
	printf("%lld\n", Max);
	return 0;
}

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

int main() {
  int n;
  while(scanf("%d", &n) ,n) {
    vector<int> v;
    int t;
    long long maxsum = -10000000;

    for(int i=0; i<n; ++i) {
      scanf("%d", &t);
      v.push_back(t);
    }

    for(int i=0; i<n; ++i) {
      long long tmp = 0;
      for(int j=i; j<n; ++j) {
        tmp += v[j];
        maxsum = max( maxsum, tmp );
      }
    }
    printf("%lld\n", maxsum);
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int n, num[5010];

int main() {
	cin >> n;
	while (n != 0) {
		int sum = 0;
		int maxsum = 0;
		for (int i = 0; i < n; i++) {
			cin >> num[i];
			sum += num[i];
			if (sum < 0) sum = 0;
			if (sum > maxsum) maxsum = sum;
		}
		cout << maxsum << endl;

		cin >> n;
	}

	return 0;
}

/*@@@@@@@@@@@@@@@@@@@@@@@@@*/
/*@                       @*/
/*@ debug output erased ? @*/
/*@                       @*/
/*@@@@@@@@@@@@@@@@@@@@@@@@@*/

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

int main(){
  int n;
  int a[5000],sum,ans;

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

}

C++: #include <stdio.h>

int
main(void)
{
	char line[80];
	int a[5000];
	int n;

	while (fgets(line, sizeof line, stdin)) {
		if (sscanf(line, "%d", &n) == 1) {
			if (n == 0) {
				break;
			}
			
			for (int i = 0; i < n; i++) {
				if (fgets(line, sizeof line, stdin) == NULL) {
					return 1;
				}
				if (sscanf(line, "%d", &(a[i])) != 1) {
					return 1;
				}
			}
			
			int m1 = -100001;
			for (int i = 0; i < n; i++) {
				int s = 0;
				int m0 = -100001;
				for (int j = i; j < n; j++) {
					s += a[j];
					if (m0 < s) {
						m0 = s;
					}
				}
				if (m1 < m0) {
					m1 = m0;
				}
			}
			printf("%d\n", m1);
		}
	}

	return 0;
}

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

int main() {
int n,b;
int a[5001];
while(1){
	cin>>n;
	if(n==0){
		break;
	}
	for (int kkk=1;kkk<=n;kkk++){
		a[kkk]=0;
	}
	for (int kk=1;kk<=n;kk++){
		cin>>a[kk];
		
	}
	int high=a[1];
	for (int k=1;k<=n;k++){
		for(int l=k;l<=n;l++){
			int sum=0;
			for(int m=k;m<=l;m++){
				sum=sum+a[m];
				if(sum>=high){
		high=sum;
			}
		}
	}
	
	}
cout<<high<<endl;
}
	return 0;
}

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 = -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);
	}
}