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>
#include <algorithm>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		int num[5001];
		for(int i = 0; i < n; i++){
			cin>>num[i];
		}
		
		int dp[5001];
		dp[0]=num[0];
		int maxNum=max(0,dp[0]);
		for(int i = 1; i < n; i++){
			dp[i]=max(num[i],dp[i-1]+num[i]);
			maxNum=max(maxNum,dp[i]);
		}
		cout<<maxNum<<endl;
		
	}

	return 0;
}

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

using namespace std;
int length=0;
int* sums;

int main(){
  string str="";
  while(1){
  cin>>length;
  if(length==0)break;
  sums=new int[length+1];
  sums[0]=0;
  int s=0;
  for(int i=0;i<length;i++){
    int v=0;
    cin>>v;
    s+=v;
    sums[i+1]=s;
  }
  int max=INT_MIN;
  for(int i=0;i<length+1;i++){
    for(int j=i;j<length+1;j++){
      int diff=sums[j]-sums[i];
      if(diff>max){
        max=diff;
      }
    }
  }
  cout<<max;
  }
  return 0;
}

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

typedef complex<double> P;

int main(){
	int n;
	while(cin >> n && n){
		int ans = 0;
		int tot = 0;
		for(int i = 0 ; i < n ; i++){
			if( tot < 0 ) tot = 0;
			int x;
			cin >> x;
			tot += x;
			ans = max(ans,tot);
		}
		cout << ans << endl;
	}
}

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

using namespace std;
int main(void)
{
	int n,sum,log;
	while(scanf("%d",&n))
	{
		if(n == 0) break;
		int a[5001] = {0};
		for(int i = 0;i < n;i++)
		{
			scanf("%d",&a[i]);
		}
		sum = 0;
		for(int i = 0;i < n;i++)
		{
			log = 0;
			for(int j = i;j < n;j++)
			{
				log += a[j];
				if(sum < log)
				{
					sum = log;
				}
				else
				{
				}
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a[5000],saidai=-100000;
	while(cin>>n&&n!=0){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;n>i;i++){
			int kazu=0;
			for(int x=0;x<=i+1;x++){
				kazu=a[i]+a[x+1];
				cout<<kazu<<endl;
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
		cout<<saidai<<endl;
	}
}

C++: #include<stdio.h>

int main()
{
	int n;
	while(true)
	{
		scanf("%d",&n);
		if(n==0){return 0;}
		
		if( n >= 1 && n <= 5000){
		int a[5000]={0},max=0;
		for(int x=0;x<n;x++)
		{
			scanf("%d",&a[x]);

			for(int y=0;y<=x;y++)
			{
				if(y!=x)
				{
					a[y]+=a[x];
				}
				if(max<a[y])
				{
					max=a[y];
				}
			}
		}
		printf("%d\n",max);
		}
	}
}

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

int main(void){
	int l[5000];
	int n;
	while(cin>>n,n){
		for(int i = 0 ; i < n ; i++)cin>>l[i];
		int res = -1000000;
		for(int i = 0 ; i < n ; i ++){
			int sum = 0;
			res = max(l[i],res);
			for(int j = i ; j < n ; j ++){
				sum += l[j];
				res = max(sum,res);
			}
		}
		cout<<res<<endl;
	}
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

  template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n){
    if(n == 0) break;
    vector<int> a(5005,0);
    int ans =0,res= 0;
    rep(i,n){
      cin >> a[i];
      ans +=a[i];
    }
    rep(i,n){
      vector<int> kt(5005,0);
      for(int j = i;j<=n;++j){
        kt[j+1] += kt[j]+a[j];
      }
      ans = max(ans,*max_element(all(kt)));
    }
    cout << ans << 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++){//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 <cstdio>
#include <algorithm>
#include <functional>
#include <stack>
#include <cmath>
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define llong long long

int main() {
  while(1){
    int n;
    scanf("%d",&n);
    if(n == 0) break;
    int a[n];
    REP(i,n) scanf("%d",a+i);
    int maxseq = a[0];
    int sum = 0;
    REP(i,n) {
      sum = max(sum+a[i], a[i]);
      if(maxseq < sum) maxseq = sum;
    }
    if(maxseq < sum) maxseq = sum;
    printf("%d\n",maxseq);
  }
  return 0;
}