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;
  while (cin >> n) {
    if (n == 0)
      break;
    vector<int> a(n, 0); //?´??????¨
    vector<int> b(n, 0); //????????¨
    int s = 0; //?????????????????????????????¨
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      b[i] = a[i];
    }
    int k = n - 1;
    while (a[k] < 0)
      k--;
    for (int i = k - 1; i > -1; i--) {
      if (a[i] < 0)
	continue;
      else {
	int j = i;
	while (a[j] < 0) {
	  s += a[j];
	  j++;
	}
	if (s + b[j] >= 0)
	  b[i] += s + b[j + 1];
	else if (a[i] > s + b[j + 1])
	  b[i] += a[i];
      }
    }
    for (int i = 0; i < n; i++)
      cout << b[i] << endl;
    sort(b.begin(), b.end());
    cout << b[n - 1] << endl;
  }
}

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

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

    mx=0; sum=0;
    for(int i = 0; i < n; i++) {
      sum=0;
      for(int j = i; j < n; j++) {
	sum+=a[j];
	mx=max(mx, sum);
      }
    }
    cout<<mx<<endl;
  }

  return 0;
}

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

int main(){
	int n,a[5000],s,ans;
	
	while(1){
		cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i] ;
	}
		if(n==0){
			break;
		}
	ans=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=n-i;j++){
			s=0;
			if((a[j]<=0)||(a[j+i-1]<=0)){
				goto A;
			}
			for(int k=j;k<j+i;k++){
				s+=a[k];
			}
			if(ans<s){
				ans=s;
			}
				A:;
		}
	}
	cout << ans << "\n" ;
	}
return 0;
}

C++: #include <stdio.h>
#define N 5000

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

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

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

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

    int m = b[0];
    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;
    }

    m = a[0] = b[0];
    for(int i=1; i<=c; ++i){
        a[i] = a[i-1] < 0 ? b[i] : a[i-1] + b[i];
        if(m < a[i]){
            m = a[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 <stdio.h>

int main()
{
	int n, x, p;
	
	while(scanf("%d", &n) != 0){
		int a[n];

		for(int i = 0; i < n; i++){
			scanf("%d", &a[i]);
		}

		x = a[0];

		for(int i = 1; i <= n; i++){
			for(int j = 0; j < n-i+1; j++){
				p = 0;

				for(int k = 0; k < i; k++){
					p += a[j+k];
				}

				if(x < p) x = p;
			}
		}

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

	return 0;
}

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

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <iostream>
#include <climits>

using namespace std;

int main()
{
	int n;
	int a[5000];
	while (true)
	{
		scanf("%d", &n);
		if (n == 0)
			break;

		for (int i = 0; i < n; ++i)
			scanf("%d", a+i);

		int res = -100000;
		int sum = 0;
		for (int i = 0; i < n; ++i)
		{
			if (sum < 0)
				sum = 0;
			sum += a[i];
			if (sum > res)
				res = sum;
		}
		printf("%d\n", res);
	}

	return 0;
}

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

int main(){
	int a[10000],b[10000],n,s,m,p,M;
	while(cin>>n,n){
		m=INT_MIN;p=0;M=INT_MIN;
		for(int i=0;i<n;i++){
			cin>>a[i];
			M=max(M,a[i]);
			if(a[i]>=0)p=1;
		}
		if(p==0)m=M; else
		for(int i=1;i<=n;i++){
			for(int j=0;j<n-i+1;j++){
				if(a[j]<0||a[j+i-1]<0)continue;
				s=0;
				for(int k=0;k<i;k++){
					s+=a[j+k];
				}
				m=max(m,s);
			}
		}
		cout<<m<<endl;
	}
}

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

int n,s[5000+10];

int bigger(int n){
    int M=-100000;
    for(int p=1;p<n;p++){
        if(s[p]>M) M=s[p];
        for(int q=0;q<p-1;q++){
            if(s[p]-s[q]>M) M=s[p]-s[q];
        }
    }
    return M;
}

int main(){
    int n;
    while(cin){
        cin >> n;
        if(n==0) break;
        int a[5000+10];
        for(int i=0;i<n;i++){
            cin >> a[i];
            if(i==0) s[i]=a[i];
            else s[i]=s[i-1]+a[i];
        }
        cout << bigger(n) << endl;
    }
}

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

using namespace std;

int main()
{
	while(true)
	{
		int length;
		cin >> length;
		if(length == 0)
			break;

		auto numbers = vector<int>(length);
		for(auto& i : numbers)
			cin >> i;

		int max = -2000001;
		for(int i = 0; i < length; i++)
		{
			int current = 0;
			for(int j = i; j < length; j++)
			{
				current += numbers[j];
				if(max < current)
					max = current;
			}
		}

		cout << max << endl;
	}

	return 0;
}

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

int main()
{
  long n, a, res, t;
  
  while (cin >> n, n){
    res = -100000000;
    t = 0;
    for(int i = 0; i < n; i++){
      cin >> a;
      t = max(t + a, a);
      res = max(res, t);
    }
    cout << res << endl;
  }
}

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

int main(){
	bool flag[5000] = {false};
	int n, in[5000];
	long long ans, tmp = 0ll;
	
	while(true){
		cin >> n;
		if(n == 0)
			break;

		for(int i = 0; i < n; ++i){
			cin >> in[i];
			if(in[i] > 0)
				flag[i] = true;
		}//input

		for(int i = 0; i < n; ++i){
			for(int j = i + 1; j < n; ++j){
				if(flag[i] && flag[j]){
					for(int k = i; k <= j; ++k)
						tmp += in[k];
					if(tmp > ans){
						ans = tmp; 
						tmp = 0ll;
					}	
					else
						tmp = 0ll;
				}
			}
		}
		
		cout << ans << endl;//output
		
		ans = 0ll;
		for(int i = 0; i < n; ++i)
			flag[i] = false;//intialize
	
	}
	return 0;
}

C++: #include <stdio.h>

int main(){
	int n;
	int buf[5000];
	long goukei;
	long max;
	
	int i,j;
	
	while(1){
		goukei = 0;
		max = -20000;
		scanf("%d",&n);
		if(n == 0)break;
		for(i = 0;i < n;i++){
			scanf("%d",&buf[i]);
		}
		
		for(i = 0;i < n;i++){
			goukei = 0;
			for(j = i;j < n;j++){
				goukei += buf[j];
				if(goukei > max){
					max = goukei;
				}
			}
		}
		
		printf("%d\n",max);
	}
	
	return 0;
}

C++: #include<iostream>
#include<cstring>
#define N 5001
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
    int n;
    while(cin >> n &&n)
    {
        if(n==0)break;
        long int s[N];
        //memset(s,0,sizeof(int)*N);
        int t;
        long int max = 0;
        long int min = 0;
        for(int i=0;i<n;i++){
            cin >>t;
            s[i+1] = s[i]+t;
            if(max<s[i+1])max = s[i+1];
            if(min>s[i+1])min = s[i+1];
        }
        cout << max -min << endl;

    }

    return 0;
}