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<vector>
int main()
{
	while (!std::cin.eof())
	{
		int n;
		std::cin >> n;
		if (n == 0)
		{
			break;
		}
		std::vector<int>a;
		for (int i = 0; i < n; i++)
		{
			int foo;
			std::cin >> foo;
			if (i == 0 || a.back() * foo < 0)
			{
				a.push_back(foo);
			}
			else
			{
				a.back() += foo;
			}
		}
		int max = -100001;
		if (a.size() == 1)
		{
			max = a[0];
		}
		else
		{
			int begin = a[0] > 0 ? 0 : 1;
			int temp_max = a[begin];
			try
			{
				for (int i = begin;;)
				{
					if (a.at(i + 1) + a.at(i + 2) > 0)
					{
						temp_max += a[i + 1] + a[i + 2];
						i += 2;
					}
					else
					{
						if (max < temp_max)
						{
							max = temp_max;
						}
						temp_max = a[i + 2];
						i += 2;
					}
				}
			}
			catch (std::out_of_range)
			{
				if (max == -100001)
				{
					max = temp_max;
				}
			}
		}
		std::cout << max << std::endl;
	}
	return 0;
}

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

int main(void)
{
	vector<int> numbers;
	int count, tmp, ans[5000], Max;

	while (cin >> count) {
		if (count == 0) break;
		for (int i = 0; i < 5000; i++) ans[i] = 0;
		Max = -100000;
		for (int i = 0; i < count; i++) {
			cin >> tmp;
			for (int j = 0; j <= i; j++) {
				ans[j] += tmp;
				if (Max < ans[j]) Max = ans[j];
			}
		}
		cout << Max << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main( void )
{
  int n,prev,d[5001],ret;
  while( 1 ){
    cin >> n;
    if( n==0 ) break;
    cin >> d[0];
    ret = d[0];
    for( int i=1; i<n; i++ ){
      cin >> d[i];
      for( int j=0; j<i; j++ ) d[j] += d[i];
      ret = max( *max_element( d, d+i ), ret );
    }
    cout << ret << endl;
  }
  return 0;
}

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

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

C++: #include<iostream>

using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		int a[n];
		int max=0;
		for(int i=0;i<n;i++){
			a[i]=0;
			int input;
			cin>>input;
			for(int j=0;j<=i;j++){
				a[j]+=input;
				if(max<a[j])max=a[j];
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

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

using namespace std;

int debug = 0;

int main(void){
	int n, m, i, j, k;
	int tmp, max;
	vector<int> intv;

	while(cin >> n){
		if(n == 0){
			break;
		}else{
			//ÇÝÝ
			for(i=0;i<n;i++){
				cin >> m;
				intv.push_back(m);
				//if(debug) cout << "int[" << i << "] =" << intv[i] << endl; 
			}

			//vfð¸ç·
			tmp=0;
			for(i=1;i<intv.size();i++){
				if(intv[tmp] > 0){
					if(intv[i] > 0){ //¯Èç
						intv[tmp] += intv[i];
						intv[i] = 0;
					}else{ //ÙÈç
						tmp = i;
					}
				}else if(intv[tmp] < 0){
					if(intv[i] < 0){
						intv[tmp] += intv[i];
						intv[i] = 0;
					}else{
						tmp = i;
					}
				}
			}
			/*
			if(debug){
				for(i=0;i<intv.size();i++){
					cout << intv[i] <<endl;
				}
				cout << "----------------------" << endl;
			}
			*/
			intv.erase( remove(intv.begin(), intv.end(), 0), intv.end());
			/*
			if(debug){
				for(i=0;i<intv.size();i++){
					cout << intv[i] <<endl;
				}
			}
			*/

			max = 0;
			int vsize = intv.size();
			for(i=1;i<=vsize;i+=2){//i:Â
				//if(debug) cout << "number =" << i << endl;
				for(j=0;j<=vsize-1-i+1;j++){ //j:JnÊu
					tmp = 0;
					for(k=0;k<i;k++){
						tmp += intv[j+k];
					}
					//if(debug) cout << "tmp ==" << tmp << endl;
					if(max <= tmp){
						max = tmp;
					}
				}
			}
			cout << max << endl;
			intv.clear();
		}
	}
	return 0;
}

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

using namespace std;

int main() {
  int n;
  vector<int> datas;
  vector<int> sums;

  while (cin >> n, n != 0) {
    int input;
    for (int n_i = 0; n_i < n; n_i++) {
      cin >> input;
      datas.push_back(input);
    }
    for (int data_i = 0; data_i < n-1; data_i++) {
      sums.push_back(datas[data_i]+datas[data_i+1]);
    }

    int max = *sums.begin();
    for (auto sum_i = sums.begin(); sum_i != sums.end(); sum_i++)
      if (max < *sum_i)
        max = *sum_i;
    cout << max << endl;
  }

  return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int n;

	while(cin >> n, n) {
		vi num(n);

		REP(i, n) {
			cin >> num[i];
		}

		int ans = INT_MIN;
		FOR(i, 0, n-1) {
			int sum = 0;
			FOR(j, i, n-1) {
				sum += num[j];
				ans = max(sum, ans);
			}
		}

		cout << ans << endl;
	}

	return 0;
}

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

int main(){
	int n;
	while(cin >> n, n){
		n++;
		vector<int> t(n), v(n);
		t[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> v[i];
			t[i] = max(t[i-1]+v[i], v[i]);
		}
		cout << *max_element(t.begin()+1, t.end()) << endl;
	}
	return 0; 
}

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

using namespace std;

int main(){
	int n,sumax,temp;
	int num[5001];
	
	while(scanf("%d",&n)){
		if(n==0)
		break;
		for(int i=0;i<n;i++){
			scanf("%d",&num[i]);
		}
		sumax = -100000;
		for(int i=0;i<n;i++){
			temp = 0;
			for(int j=i;j<n;j++){
				temp+=num[j];
				if(temp>sumax)
				sumax=temp;
			}
		}
		printf("%d\n",sumax);
	}
}

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

int main(){
	int n;
	while(cin >> n, n){
		n++;
		vector<int> t(n), v(n);
		t[0] = v[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> v[i];
			t[i] = max(t[i-1]+v[i], v[i]);
		}
		cout << *max_element(t.begin(), t.end()) << endl;
	}
	return 0; 
}

/*
7
-5
-1
6
4
9
-6
-7
*/