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 <cstring>
using namespace std;

int main(){
    long long int n, ans, sum;
    long long int a[5001];
    
    while(cin >> n){
        if(n == 0){
            break;
        }
        
        memset(a, 0, sizeof(a));
        
        for(int i = 0;i < n;i++){
            cin >> a[i];
        }
        
        ans = a[0];
            
        for(int i = 0;i < n;i++){
            sum = 0;
                
            for(int j = i;j < n;j++){
                sum += a[j];
                ans = max(sum, ans);
            }
        }
        
        cout << ans << endl;
    }

    return 0;
}

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

int main()
{
	int n,t,mx;
	while(cin >> n, n)
	{
		mx = 0;
		int dt[5000]={0};
		for(int i=0; i<n; i++)
		{
			cin >> t;
			for(int j=0; j<=i; j++)
			{
				dt[j]+=t;
				if(j!=i)mx=max(mx,dt[j]);
			}
		}
		cout << mx << endl;
	}
}

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

int main(){
while(1){
int n;
cin>>n;
if(n==0)break;
vector<int> sum(n+1,0);
for(int i=1;i<=n;i++){
	int a;
	cin>>a;
	sum[i]=sum[i-1]+a;
}
int ans=sum[1];
for(int i=0;i<=n;i++){
	for(int j=i+1;j<=n;j++){
	ans=max(ans,sum[j]-sum[i]);
	}
}
cout<<ans<<endl;
}

return 0;
}

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

int main(){
	int n;
	cin >> n;
	while(n != 0){	

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

		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		int maximum = 0;
		

		for(int i = 0; i < n; i++){
			sum[i][0] = a[i];
			for(int j = 1; j < n - i; j++){
				sum[i][j] = sum[i][j-1] + a[i+j];
				maximum = max(maximum, sum[i][j]);
			}
		}

		cout << maximum << endl;
		cin >> n;
	}

	return 0;
}

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

int main(){
	vector<int> nums;
	int n;
	while( cin >> n, n ){
		nums.clear();
		nums.resize(n);
		for( int i=0; i<n; i++ )
			cin >> nums[i];
		int max=-50000000;
		for( int i=0; i<n; i++ ){
			int sum=0;
			for( int j=i; j<n; j++ ){
				sum += nums[j];
				if( max < sum )		max = sum;
			}
		}
		cout << max << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n;
        cin>>n;
        if(n==0){
            return 0;
        }
        vector<int> a(n);
        for(int i=0;i<n;i++){
            cin>>a.at(i);
        }
        vector<int> b(n+1);
        b.at(0)=0;
        for(int i=1;i<=n;i++){
            b.at(i)=b.at(i-1)+a.at(i-1);
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            for(int j=0;j<i;j++){
                ans=max(ans,b.at(i)-b.at(j));
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include <iostream>

int maxSum(int *a, int n) {
	int sum, max = a[0];
	for (int num = 1; num <= n; ++num) {
		for (int i = 0; i < n - num + 1; ++i) {
			sum = 0;
			for (int j = 0; j < num; ++j) {
				sum += a[i + j];
			}
			if (sum > max) { max = sum; }
		}
	}
	return max;
}

int main() {
	int n;
	int *a;
	for (;;) {
		std::cin >> n;
		if (n <= 0) { break; }
		a = new int[n];
		for (int i = 0; i < n; ++i) {
			std::cin >> a[i];
		}
		std::cout << maxSum(a, n) << '\n';
		delete [] a;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){
	int n;
	int a[5000]={0};
	while(cin >> n){
		int max = 0;
		if(n == 0) break;
		for(int i=0;i<n;i++){
			cin >> a[i];
		}
		for(int i=0;i<n;i++){
			int sum = 0;
			for(int j=0;i+j<n;j++){
				sum += a[i+j];
				if(max < sum) max = sum;
			}
		}
		cout << max << "\n";
	}
	return 0;
}

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

int main(){

  int n,a[10000],ans,c;

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

    ans = a[0];

    for(int i=0;i<n;i++){
      c = 0;
      for(int j=i;j<n;j++){
	c += a[j];
	ans = max(ans,c);
      }
    }

    cout << ans << endl;

  }
}

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

C++: #include<iostream>
#include<vector>
int main()
{
	while (!std::cin.eof())
	{
		int n;
		std::cin >> n;
		if (n == 0)
		{
			break;
		}
		std::vector<int>a;
		int max = -100001;
		bool is_all_minus = true;
		for (int i = 0; i < n; i++)
		{
			int foo;
			std::cin >> foo;
			if (foo < 0 && max < foo)
			{
				max = foo;
			}
			is_all_minus &= foo < 0;
			if (i == 0 || a.back() * foo < 0 || a.back() < 0 && foo == 0 || a.back() == 0 && foo < 0)
			{
				a.push_back(foo);
			}
			else
			{
				a.back() += foo;
			}
		}
		if (!is_all_minus)
		{
			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 << std::endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	long int n, m[5000] = { 0 }, max = -2147483647, temp = 0;
	while (cin>> n && n!=0){
		for (int i = 0; i < n; i++){
			cin >> m[i];
		}
		for (int i = 0; i < n; i++){
			temp = m[i];
			for (int l = i + 1; l < n; l++){
				temp += m[l];
				if (max < temp){
					max = temp;
				}
			}temp = 0;
		}
		cout << max << endl;
		max = -2147483647;
	}
	return 0;
}

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

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		vector<int> a(n);
		for(int i=0; i<n; i++){
			cin >> a[i];
		}
		
		int ans=0, sum=0;
		for(int i=0; i<n; i++){
			sum += a[i];
			if(sum<0) sum=0;
			ans = max(ans, sum);
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define MAX 1000000000
#define MIN -10000000000

#define ll long long

using namespace std;
int main() {

        ll n,k,i,j,temp,last,maxx;
        do {
            cin>>n;
            if(n==0)break;
            vector<ll> a(n);
            vector<ll> s(n+1);
            for(i=0;i<n;i++){
                cin>>a[i];
            }
            s[0]=0;
            for(i=0;i<n;i++){
                s[i+1]=s[i]+a[i];
            }
            maxx=-100000;
            for(i=0;i<n;i++){
                for(j=i;j<=n;j++){
                    maxx=max(s[j]-s[i],maxx);
                }
            }
            cout << maxx << endl;



        }while(n!=0);

//cout << "aaa" << endl;

    return 0;
}