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 <cmath>
#include <vector>
using namespace std;
int main(){
  

  int dataSets;

  while(true){
    vector<int> a;
    cin >> dataSets;
    if(dataSets==0){break;}
    for(int i=0;i<dataSets;i++){
      int tmpa;
      cin >> tmpa;
      a.push_back(tmpa);

    }

    int tmax=0;
    // i?????§????????§?????????????????????
    vector<int> tmpMax(dataSets + 1,0);
    tmpMax[0] = 0;
    for(int i=1;i<dataSets+1;i++){
      tmpMax[i] += tmpMax[i-1] + a[i-1];
    }

    for(int i=0;i<dataSets;i++){
      for(int j=i+1;j<dataSets+1;j++){
	tmax = max(tmax, tmpMax[j]-tmpMax[i]);
      }
    }
    
    // for(int i=0;i<dataSets+1;i++){
      // for(int j=i;j<dataSets;j++){
	// tmax = max(tmax, tmpMax[j+1] - tmpMax[i]);
      // }
    // }
    
    cout << tmax << endl;
    
  }

  return 0;

}

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

int main(){
  int n;
  int list[5000];

  while(cin>>n){
    int temp=0;
    int max=0;
    for(int i=0; i<n; i++){
      cin >> list[i];
    }
    for(int i=0; i<n; i++){
      temp += list[i];
      if( temp<=0 ){
        temp=0;
      }
      if(max<temp){
        max=temp;
      }
    }

    cout << "output: " << max << endl;
  }

  return 0;
}

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


int main()
{
	int max;
	int currentSum;
	int loop;
	int a[5005];

	while (cin >> loop, loop) {
		// O(n)
		for (int i = 0; i<loop; i++) {
			cin >> a[i];
		}

		// O(n^2)
		max = a[0], currentSum = 0;
		for (int j = 0; j<loop; j++) {
			for (int k = j; k<loop; k++) {
				currentSum += a[k];
				if (currentSum > max)
					max = currentSum;
			}
			currentSum = 0;
		}
		cout << max << endl;
	}
	return 0;
}

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

int main(){
int n,m=0;
int a[5001];
int sum;
int big=0;
while(cin>>n){
big=0;
for(int i=0;i<n;i++)cin>>a[i];

for(int i=0;i<n-1;i++){
if(a[i]>=0&&a[i+1]>=0){
a[i]+=a[i+1];
for(int j=i+1;j<n-1;j++)a[j]=a[j+1];
i--;
n--;}}

for(int i=0;i<n;i++)cout<<a[i]<<endl;

for(int i=1;i<n+1;i++){
for(int j=0;j<n-i;j++){
sum=0;
for(int k=0;k<i;k++){
sum+=a[j+k];}
if(sum>big){big=sum;}}}
cout<<big<<endl;}}

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

int main(){
  int n;
  int a[5000];
  while(cin >> n && n>0){
    for(int i=0;i<n;i++)
      cin >> a[i];
    long long sum=0,tmp=0,ma=-100000;
    int m=-100000;
    bool flg=true;
    for(int i=0;i<n;i++){
      if(flg) m=max(m,a[i]);
      if(a[i]>0){
	flg=false;
	sum+=a[i];
	continue;
      }
      ma=ma>sum?ma:sum;
      for(tmp=sum;i<n && a[i]<=0;i++){
	tmp+=a[i];
      }i--;
      if(tmp>0)
	sum=tmp;
      else
	sum=0;
    }
    ma=ma>sum?ma:sum;

    cout << (flg?m:ma) << endl;
  }
}

C++: #include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
  // ifstream cin("../test.txt");
  int n;
  while (true) {
    cin >> n;
    if (!n) break;
    vector<int> a(n);
    vector<int> sub_sum(n); // a[0] + ... + a[i]
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sub_sum[0] = a[0];
    long long max_sum = -100000000000;
    for (int i = 1; i < n; i++) {
      sub_sum[i] = sub_sum[i-1] + a[i];
      max_sum = max(max_sum, sub_sum[i]);
    }
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < i; j++) {
        max_sum = max(max_sum, sub_sum[i] - sub_sum[j]);
      }
    }
    cout << max_sum << endl;
  }
}

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

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

C++: #include <algorithm>
#include <iostream>
#include <limits>
using namespace std;
int main() {
  int n;
  while (cin >> n && n) {
    int m = numeric_limits<int>::min();
    int s = 0;
    while (n--) {
      int k;
      cin >> k;
      s += k;
      m = max(m, s);
      if (s < 0) s = 0;
    }
    cout << m << endl;
  }
}

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

using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int gcd(int a, int b){
   int tmp;
   while(a%b==0){
      tmp=a%b;
      a=b;
      b=tmp;
   }
}

int lcm(int a,int b){
   return a*b/gcd(a,b);
}

bool prime_number(int n){
   if(n < 2){
      return false;
   }
   else if(n == 2){
      return true;
   }
   if(n % 2 == 0){
      return false;
   }
   for(int i=3;i<=n/i;i+=2){
      if(n % i == 0) return false;
      return true;
   }
}

int main(){
   int n,a, sum,ans;
   VI s;
   while(1){
      cin >> n;
      s=VI(n);
      if(!n) break;
      REP(i,n){
         cin >> s[i];
      }
      ans=s[0];
      REP(i,n){
         sum=s[i];
         if(sum>ans) ans=sum;
         FOR(j,i+1,n){
            sum+=s[j];
            if(sum>ans) ans=sum;
         }
      }
      cout << ans << endl;
   }
   return 0;
}