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>

using namespace std;

int main()
{
	int num;

	while( cin >> num ) {
		if (num == 0 )
			break;

		long int tmpsum = 0;
		long int currnum;
		long int maxnum = -999999999;
		for( int i = 0; i < num; i++ ) {
			cin >> currnum;

			if( currnum + tmpsum > maxnum ) {
				maxnum = currnum + tmpsum;
			}
			
			if( currnum + tmpsum > 0 )
				tmpsum += currnum;
			else
				tmpsum = 0;
		}
		cout << maxnum << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
  while(1){
    int n;
    scanf("%d", &n);
    if(n==0){
      break;
    }

    int a[5000];
    int max;

    int i,j,k;
    for(i=0; i<n; ++i){
      scanf("%d", &a[i]);
      int sum = 0;
      for(j=i; j>=0; --j){
        sum += a[j];
      }
      if((i==0 && j==0) || sum>max){
        max = sum;
      }
    }

    printf("%d\n", max);
  }

  return 0;
}

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

using namespace std;

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

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

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

C++: #include <iostream>
using namespace std;
int main(){
	int n,a[5001],s,m;
	while(1){
		cin>>n;
		if(!n)break;
		for(int i=0;i<n;i++)cin>>a[i];
		m=-10000000;
		for(int i=0;i<n;i++){
			s=0;
			for(int j=i;j>=0;j--){
				s+=a[j];
				if(s>m)m=s;
			}
		}
		cout<<m<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int gets(int d){
	return d >= 0 ? 1 : -1;
}

int seqsum(int n){
	int a[5000];
	int b[5000];
	int c = 0;
	int s = 0;

	scanf("%d", a);
	b[0] = a[0];
	s = gets(a[0]);

	for(int i=1; i<n; ++i){
		scanf("%d", a+i);
		if(s == gets(a[i])){
			b[c] += a[i];
		}else{
			b[++c] = a[i];
			s = gets(a[i]);
		}
	}

	int m = b[0];
	int sum = m;
	if(c == 0){
		if(m >= 0){ return m; }
		m = a[0];
		for(int i=1; i<n; ++i){
			if(m < a[i]){
				m = a[i];
			}
		}
		return m;
	}
	for(int i=1; i<=c; ++i){
		if(m < sum + b[i]){
			sum += b[i];
			m = sum;
		}else if(m < b[i]){
			sum = m = b[i];
		}else{
			sum += b[i];
		}
	}

	return m;
}

int main(void){
	int n = 0;
	while(true){
		scanf("%d", &n);
		if(n == 0){ break;}
		printf("%d\n", seqsum(n));
	}
	return 0;
}

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

int main()
{
    for (int n; cin >> n && n;) {
        vector<int> sequence(n);
        int sum = 0;
        int max_val = numeric_limits<int>::min();
        for (int x, i = 0; i < n && cin >> x; i++) {
            if (sum < 0)
                sum = x;
            else
                sum += x;
            max_val = max(max_val, sum);
        }
        cout << max_val << endl;
    }

    return 0;
}

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

int main()
{
	int n=1, count = 0;
	int a[10000];
	while (n != 0) {
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0, max = -10000;
		for (int ai = 0; ai < n - 1; ai++) {
			sum = 0;
			for (int bi = ai; bi < n; bi++) {
				sum = sum + a[bi];
				if (sum > max) {
					max = sum;
				}
			}
		}
		if (n != 0)
			cout << max << endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    vector<int> a,b;
    for(int i=0,j; i<n; i++){
      cin >>j;
      a.push_back(j);
      if(i != 0) a[i]+=a[i-1];
    }
    b.push_back(0);
    for(int i=1; i<n; i++) b.push_back(min(b[i-1],a[i]));
    int ans = a[0];
    for(int i=1; i<n; i++) ans = max(ans,a[i]-b[i-1]);
    cout <<ans<<endl;
  }
  return 0;
}

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;
  }
}