Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

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

int main(){
	int n, sum, result;
	while(cin >> n){
		if(n == 0) break;
		vector<int> array;
		for(int i=0; i<n; i++){
			int t;
			cin >> t;
			array.push_back(t);
		}
		result = array[0];
		for(int i=0; i<n; i++){
			sum = 0;
			for(int j=i; j<n; j++){
				sum += array[j];
				result = max(result, sum);
			}
		}
		cout << result << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
while (1){
long n,dset[5000],temp=0,MINEdset[5000],max=-1100000,h[5000],b=0;
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
                temp=temp+dset[j];
                MINEdset[j]=temp;
        }
        for (int j=i;j<n;j++){
                if (max<MINEdset[j]){
                        max=MINEdset[j];
                }
        }
        h[b]=max;
        max=-1100000;
        b++;
        temp=0;
}
max=-1100000;
for (int i=0;i<=b;i++){
        if (max<h[i]){
                max=h[i];
        }
}
cout<<max<<endl;
}
return 0;
}

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

using namespace std;

#define int long long
#define pii pair<int,int>

const int MaxN=100*1000+10;
int arr[MaxN];
int ps[MaxN];

int findRightSticky(int s,int e){
	int mx=arr[e];
	int ind=e;
	for (int i=s;i<=e;++i)
		if (mx<ps[e]-ps[i-1]){
			mx=ps[e]-ps[i-1];
			ind=i;
		}
	return ind;
}

int findLeftSticky(int s,int e){
	int mx=arr[s];
	int ind=s;
	for (int i=s;i<=e;++i)
		if (mx<ps[i]-ps[s-1]){
			mx=ps[i]-ps[s-1];
			ind=i;
		}
	return ind;
}

pair<int,int> findMaxSubarray(int s,int e){
	if (s==e)
		return make_pair(s,s);
	int mid=(s+e)/2;
	pii mxsubleft=findMaxSubarray(s,mid);
	pii mxsubright=findMaxSubarray(mid+1,e);
	int mxstickyleft=findRightSticky(s,mid);
	int mxstickyright=findLeftSticky(mid+1,e);
	int totalmx=max(ps[mxstickyright]-ps[mxstickyleft-1],max(ps[mxsubleft.second]-ps[mxsubleft.first-1],ps[mxsubright.second]-ps[mxsubright.first-1]));
	if (totalmx==ps[mxsubleft.second]-ps[mxsubleft.first-1])
		return mxsubleft;
	else if (totalmx==ps[mxsubright.second]-ps[mxsubright.first-1])
		return mxsubright;
	else
		return make_pair(mxstickyleft,mxstickyright);
}

int32_t main(){
	int n;
	cin >> n;
	while(n){
		for (int i=1;i<=n;++i){
			cin >> arr[i];
			ps[i]=ps[i-1]+arr[i];
		}
		pii prd=findMaxSubarray(1,n);
		cout << ps[prd.second]-ps[prd.first-1] << endl;
		cin >> n;
	}
	// cout << prd.first-1 << " " << prd.second-1 << endl;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <numeric>	// require accumulate
#include <climits>

using namespace std;

int main()
{
	string str = "";
	int n;

	while (1){
		getline (cin, str );
		stringstream ssn(str);
		ssn >> n;

		if (n == 0){
			break;
		} // end if

		vector <int> a(n + 1, 0 );
		vector <int> sum (n + 1, 0 );
		int i,j;

		for (i = 1; i <= n; ++i){
			getline (cin, str );
			stringstream ss(str);
			ss >> a[i];
		} // end for

		for (i = 1; i <= n; ++i){
			sum[i] = accumulate (a.begin(), a.begin() + i + 1, 0 );
		} // end for

		int maxn = INT_MIN;
		for (i = 1; i <= n; ++i){
			for (j = i; j <= n; ++j){
				 maxn = max (maxn , sum[j] - sum[i - 1] );
			} // end for
		} // end for

		cout << maxn << endl;			

	} // end while

	return 0;
}

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

template <typename Iterator>
auto findMaximumSum (Iterator begin , Iterator end) -> long long
{
    long long res = * begin;
    auto tmp = res;
    for (auto ite = begin + 1; ite != end; ++ ite)
    {
        tmp += * ite;
        res = std::max (res , tmp);
    }
    return res;
}

auto main () -> int
{
    int n;
    while (std::cin >> n && n)
    {
        std::vector <int> a (n);
        for (auto && elem : a)
        {
            std::cin >> elem;
        }
        long long ans = a [0];
        for (auto ite = a.begin (); ite != a.end (); ++ ite)
        {
            auto tmp = findMaximumSum (ite , a.end ());
            ans = std::max (ans , tmp);
        }
        std::cout << ans << std::endl;
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<int>in(n);
    rep(i,n)cin>>in[i];
    int max=0;
    rep(i,n){
      int sum=0;
      loop(j,i,n){
	sum+=in[j];
	if(max<sum)max=sum;
      }
    }
    cout<<max<<endl;
  }


}

C++: #include<stdio.h>
int main(void)
{
	int a[5000],i,j,sum=0,max[5000]={-10001},c=0,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++){
			for(j=i;j<n;j++){
				sum = sum + a[j];
				if(max[c] < sum)
					max[c] = sum;
			}
			sum = 0;
		}
		c++;
	}
	for(i=0;i<c;i++){
		printf("%d\n",max[i]);
	}
	return 0;
}

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

int main(){
	long long int n;
	
	while(cin>>n,n){
		long long int max=0;
		long long int sum[n];
		long long int t;
		int i;
		for(i=0;i<n;i++)cin>>sum[i];
		for(i=t=0;i<n;i++){
			if(t<0)t=sum[i];else t+=sum[i];
			if(max<t)max=t;
		}
		cout<<max<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <climits>
#include <utility>

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

ll INF = 1LL << 63;
double EPS = 1e-9;
// BEGIN //////////////////////////////////////////////////////////////


int main() {
	while (true) {
		int N = nextInt();
		if (N == 0) break;
		ll score = nextll();
		ll score_max = -INF;
		REP(i, N - 1) {
			ll d = nextll();
			score = max(score + d, d);
			score_max = max(score, score_max);
		}
		PRINT(score_max);
	}

	return 0;
}

// END   //////////////////////////////////////////////////////////////

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
#include <cmath>
#define mp make_pair
#define pii pair<int,int> 
#define ff first
#define ss second

using namespace std;

int n;
int list[10000],dp[10000];
int hasil;

int main()
{
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
		break;
		hasil=-1000000;
		dp[0]=0;
		for(int a=1;a<=n;a++)
		{
			scanf("%d",&list[a]);
		}
		for(int a=1;a<=n;a++)
		{
			if(dp[a-1]>=0)
			{
				dp[a]=dp[a-1]+list[a];
			}
			else
			{
				dp[a]=list[a];
			}
			hasil=max(hasil,dp[a]);
		}
		/*for(int a=0;a<=n;a++)
		{
			printf("%d ",dp[a]);
		}*/
		printf("%d\n",hasil);
	}
	return 0;
}