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 <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>

using namespace std;

int main()
{
	int n;
	while(cin>>n,n){
		vector<long long> dp(n);
		long long res;
		cin>>dp[0];
		res=dp[0];

		for(int i=1;i<n;i++){
			long long a;
			cin>>a;
			dp[i]=max(dp[i-1]+a,a);
			res=max(res,dp[i]);
		}
		cout<<res<<endl;
	}


	return 0;
}

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

int main() {
  int x,n,k;
  int sum[100000],a[5000];
  while(cin >> n) {
    for(int i=0;i<n;i++) {
      cin >> x;
      a[i] = x;
    }
    for(int j=0;j<n;j++) {
      for(int i=j+1;j<n;i++) {
        for(int m=0;m<i-j;m++) {
          sum[k] += a[j+m];
        }
        k++;
      }
    }
    cout << *max_element(sum,sum+k) << endl;
  }
}

C++: #include <iostream>
#include <climits>
typedef long long ll;
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;
}

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

int main()
{
    int n;

    while( cin >> n )
    {
        if( n == 0 )
            break;

        int max = 0, max2 = -1000000;
        int sum = 0;
        int a[n];
        for( int i = 0; i < n; i++ )
        {    
            cin >> a[i];

            if( a[i] > 0 )
            {
                sum += a[i];
                if( max < sum )
                    max = sum;
            }
            else
            {
                if( sum + a[i] > 0 )
                    sum += a[i];
                else
                    sum = 0;
            }
            
            if( max2 < a[i] )           //全てが負の値だった時に、その中でも最大の値を格納。
                max2 = a[i];
        }
        if( max == 0 )
            cout << max2 << endl;
        else
            cout << max << endl;
    }
    return 0;
}

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

constexpr int INF = 1e9;

int solve (int n) {
	int ans = -INF, sum = 0;
	for (int i = 0; i < n; i++) {
		int e; cin >> e;
		sum = max(sum + e, e);
		ans = max(ans, sum);
	}
	return ans;
}

int main() {
	int n;
	while (true) {
		cin >> n;
		if (n > 0) cout << solve(n) << '\n';
		else break;
	}
	return 0;
}

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

int main(){
	int n;
	while(cin >> n,n){
		int a,dp[5001] = {},ma = 0;
		for(int i = 0;i < n;i++) {
			cin >> a;
			dp[i + 1] = max(a,dp[i] + a);
			ma = max(ma,dp[i + 1]);
		}
		cout << ma << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>

int main()
{
	std::uint32_t n;
	for (std::cin >> n; n != 0; std::cin >> n) {
		typedef std::vector<std::int32_t> IntVec;
		IntVec a(n);
		for (std::size_t i = 0; i < n; ++i) {
			std::cin >> a[i];
		}
		for (std::size_t i = 1; i < n; ++i) {
			a[i] = std::max(a[i], a[i] + a[i - 1]);
		}
		std::cout << *std::max_element(a.begin(), a.end()) << std::endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	for (; ;)
	{
		int n;
		cin >> n;

		if (n == 0)
		{
			break;
		}

		vector<int> a(n);
		for (int i = 0; i < n; i++)
		{
			cin >> a.at(i);
		}

		int maxv = 0;
		for (int i = 0; i <= n; i++)
		{
			
			for (int j = 0; j < n; j++)
			{
				int sum = a.at(j);
				for (int k = j + 1; k < i; k++)
				{
					sum += a.at(k);
				}
				maxv = max(maxv, sum);
			}
		}

		cout << maxv << endl;
	}
}

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

int main(){
	int n;
	cin >> n;
	while(n != 0){	
		cout << n << endl;

		int a[n];
		int sum[n][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				sum[i][j] = 0;
			}
		}

		for(int i = 0; i < n; i++){
			cin >> a[i];
			cout << a[i] << endl;
		}
		int maximum = 0;
		

		for(int i = 0; i < n; i++){
			sum[i][0] = a[i];
			for(int j = 0; j < n - i; j++){
				sum[i][j+1] = sum[i][j] + a [i+j+1];
				maximum = max(maximum, sum[i][j]);
			}
		}
		cout << maximum << endl;
		cin >> n;
	}

	return 0;
}

C++: #include <iostream>
#include <stack>
#include <stdio.h>
#include <cmath>
#include <utility>
using namespace std;
int main()
{
    int n;
	while(cin>>n&&n){
		int a[5000]={},sum[5000]={},m=-1000000;
		for(int i=0;i<n;i++){
			cin>>a[i];
			sum[i+1]=sum[i]+a[i];
		}
		for(int i=0;i<n;i++){//start
			for(int j=i;j<n;j++){//end
				int tmp=sum[j+1]-sum[i];
				if(tmp<=0){i=j;break;}
				//printf("%d-%d:%d\n",i,j,tmp);
				m=max(m,tmp);
			}
		}
		cout<<m<<endl;
	}
    return 0;
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        int data[10000]={};
        rep(i,n) cin>>data[i];
    
    
        int maxi=-999999999;
        int dp[500][500]={};
        rep(i,n){
            for(int j=i;j<n+1;j++){
                if(i-1>=0){
                    dp[i][j]=dp[i][j-1]+data[j-1];
                    maxi=max(maxi,dp[i][j]);
                }
            }
        }
        cout<<maxi<<endl;
    }
    return 0;
}

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

using namespace std;
int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		long long int a[5000], sum = 0, hold = 0;
		for(int i = 0;i < n;i++){
			cin >> a[i];
		}
		hold = a[0];
		for(int i = 0;i < n;i++){
			sum += a[i];
			for(int j = i+1;j < n;j++){
				sum += a[j];
				if(hold < sum){
					hold = sum;
				}
			}
			sum = 0;
		}
		cout << hold << endl;

	}
	
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
	int z=-1,n,i,j[255],o,maxo=-100000,s[5000]={0};
	scanf("%d",&n);
	while(n!=0){
		o=0;
		z++;
		for(i=0;i<n;i++){
			scanf("%d",&s[i]);
		}
		for(i=1;i<n;i++){
			if(s[i]<s[i-1]+s[i]){
				s[i]=s[i-1]+s[i];
			}

		}
		for(i=0;i<n;i++){
			maxo=max(maxo,s[i]);
		}
		j[z]=maxo;
		maxo=-100000;
		scanf("%d",&n);
	}
	for(i=0;i<=z;i++){
		printf("%d\n",j[i]);
	}
	return 0;
}