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<cstring>
#include<algorithm>
#include<queue>
#include<cstdio>
#include<string>
#include<math.h>
typedef long long LL;
using namespace std;
int main()
{
  //  freopen("test.txt", "r", stdin);
  //  freopen("testout.txt", "w", stdout);
    int n=0;
    LL x,max_sum,cur_sum;
    while(~scanf("%d",&n)&&n)
    {
        x=0;
        cur_sum=0;
        max_sum=-99999999;
        while(n--)
        {
            cin>>x;
            cur_sum+=x;
            if(max_sum<cur_sum)
                max_sum=cur_sum;
            if(cur_sum<0)
                cur_sum=0;
        }
        cout<<max_sum<<endl;
    }
    return 0;
}

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

int main()
{
	int n;while(cin>>n,n){
	int a[5000];
	rep(i,n)cin>>a[i];
	int ans=-10000000,sum;
	rep(i,n)
	{
		sum=0;
		for(int j=i;j<n;j++)
		{
			sum+=a[j];
			ans=max(ans,sum);
		}
	}
	cout<<ans<<endl;}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	long int n, m[5000] = { 0 }, max = 0, temp = 0;
	int out;
	
	while (cin>> n && n!=0){
		for (int i = 0; i < n; i++){
			cin >> m[i];
		}
		for (int i = 0; i < n; i++){
			temp = m[i];
			for (int l = i + 1; l < n; l++){
				temp += m[l];
				if (max < temp){
					max = temp;
				}
			}temp = 0;
		}
		cout << max << endl;
		max = 0;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n, sum[5001] = {};
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      int a;
      cin >> a;
      sum[i + 1] = sum[i] + a;
    }
    int ret = sum[1];
    for(int i = 0; i <= n; i++){
      for(int j = i + 1; j <= n; j++){
        ret = max( ret, sum[j] - sum[i]);
      }
    }
    cout << ret << endl;
  }
}

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

using namespace std;
int dp[5001];

void solve()
{
	int n;
	while(cin >> n, n)
	{
		for(int i = 0; i < 5001; ++i)
		{
			dp[i] = -999999999;
		}
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		int Max = -999999999;
		dp[0] = Vec[0];
		int sum = Vec[0];
		for(int i = 1; i < n; ++i)
		{
			if(sum + Vec[i] < Vec[i])
			{
				dp[i] = Vec[i];
				sum = Vec[i];
			}
			else
			{
				dp[i] = sum + Vec[i];
				sum += Vec[i];
			}
			if(dp[i] < dp[i - 1])
			{
				dp[i] = dp[i - 1];
			}
		}
		cout << dp[n - 1] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

int main(){
	int n,p,m;
	int number[5000];
	int sum=0,max=0;

	scanf("%d",&n);

	while(n != 0){
		memset(number,'\0',sizeof(number));
		for(int i=0;i<n;i++){
			cin >> p;
			number[i] = p;
		}

		for(int i=0;i<n;i++){
			m = n;
			while(0 < m){
				for(int j=m-1;j>=i;j--){
					sum += number[j];
				}
				m--;
				if(sum > max){
					max = sum;
				}
				sum = 0;
			}
			m=n;
		}
		cout << max << endl;

		sum = max = 0;
		scanf("%d",&n);
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
    ll n;
    cin >> n;
    while(n!=0){
        vector<ll> vec(n);
        for(ll i=0;i<n;i++){
            cin >> vec.at(i);
        }
        vector<ll> rsw(n+1);
        rsw.at(0) = 0;
        for(int i=1;i<n+1;i++){
            rsw.at(i) = rsw.at(i-1) + vec.at(i-1);
        }
        ll ans = vec.at(0);
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                if(ans < rsw.at(j+1)-rsw.at(i)){
                    ans = rsw.at(j+1) - rsw.at(i);
                }
            }
        }
        cout << ans << endl;
        cin >> n;

    }
}

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

int main(){
    int n;
    cin>>n;
    while(n!=0){
        vector<int> a(n);
        for(int i=0;i<n;i++) cin>>a[i];
        vector<int> S(n+1);
        for(int i=0;i<=n;i++){
            S[i] = S[i-1] + a[i-1];
        }

        int ans =0;
        int sum =0;

        for(int i=n;i>0;i--){
            for(int j=0;j<n;j++){
                int tmp=S[i] - S[j];
                if(ans<tmp){
                    ans = tmp;
                }
            }
        }
        cout<<ans<<endl;
        cin>>n;
    }
    return 0;
}

C++: #ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

int main()
{
	int N;
	while (cin >> N, N)
	{
		vector<long long int>data;
		data.resize(N + 1);
		data[0] = 0;
		for (size_t i = 1; i <= N; i++)
		{
			cin >> data[i];
			data[i] += data[i - 1];
		}
		long long int ans = INT_MIN;
		for (size_t i = 0; i < N + 1; i++)
		{
			for (size_t j = i+1; j < N + 1; j++)
			{
				ans = max(ans, data[j] - data[i]);
			}
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	while (1) {
		int n, i, j, a[5000], maxa = -100001, c;
		cin >> n;
		if (n == 0) {
			break;
		}
		for (i = 0; i < n; i++) {
			cin >> a[i];
		}
		for (i = 0; i < n; i++) {
			c = 0;
			for (j = i; j < n; j++) {
				c+= a[j];
				maxa = max(maxa, c);
			}
		}
		cout << maxa << endl;
	}
	return 0;
}

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

int main()
{

	int n, num;
	vector< int > a;

	while( 1 ) {

		int Max = -100000;

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

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

		for( int i = 1; i < n - 1; i++ ) {
		
			a.at( i - 1 ) + a.at( i ) > a.at( i ) ? a.at( i ) = a.at( i - 1 ) + a.at( i ) : a.at( i ) = a.at( i );

			if ( a.at( i ) > Max ) {
				Max = a.at( i );
			}
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}