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 <climits>
#include <iostream>

using namespace std;

template <typename Type>
long long Maximum_Sum_Sequence(Type N[], int size)
{
	long long max = LLONG_MIN;

	for (int i = 0; i < size; i++)
	{
		long long sum = 0;

		for (int j = i; j < size; j++)
		{
			sum += N[j];

			if (sum > max) { max = sum; }
		}
	}

	return max;
}

int main()
{
	const int DATASETS = 100;

	int n[DATASETS], a[DATASETS][5000], c = 0;

	while (true)
	{
		cin >> n[c];

		if (n[c] == 0) { break; }

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

		c++;
	}

	for (int i = 0; i < c; i++)
	{
		cout << Maximum_Sum_Sequence(a[i], n[i]) << endl;
	}

	return 0;
}

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


using namespace std;

int main(){
	int n;
	int max1;
	int maxS;
	int sum=0;
	int sumS=0;
	int  raw[5000];
	int ans;
	while(cin>>n,n!=0){
		sum=0;
		maxS=0;
		sumS=0;
		cin >> raw[0];
		max1=raw[0];
		sum += raw[0];
		if(sum<0)sum=0;
		for(int i=1;i<n;i++){
			cin >> raw[i];
			if(max1<raw[i]) max1 = raw[i];
			if(raw[i]<0){
				if(sumS<sum) sumS=sum;
			}
			sum += raw[i];
			if(sum<0){
				if(maxS<sum)maxS=sum;
				sum=0;
			}
		}
		ans=max(sum,max(sumS,max1),maxS);
		cout<<ans<<endl;
	}
	return 0;
}

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

long long S[5010];

int main(){
	long long a, maximum = -1000000;
	int n;
	S[0] = 0;
	while (cin >> n, n){
		for (int i = 1; i <= n; i++){
			cin >> a;
			S[i] = S[i - 1] + a;
		}

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

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

int main(){
  int n;
  cin >> n;
  while(n!=0){
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a.at(i);

    vector<int> s(n+1);
    s.at(0) = 0;
    for(int i=1;i<n+1;i++) s.at(i) = s.at(i-1)+a.at(i-1);

    int ans=a.at(0);
    for(int i=1;i<n+1;i++){
      for(int j=0;j<i;j++){
        ans = max(s.at(i)-s.at(j),ans);
      }
    }

    cout << ans << endl;

    cin >> n;
  }
}

C++: #include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n&&n!=0)
{
int a[n];
int A=0;
int R=-100000;
for(int h=0;h<n;h++)
{
	cin>>a[h];
}
for(int i=0;i<n;i++)
{
	for(int j=0;j<n-i;j++)
	{
	//	cout << k << " ";		
		A=A+a[j];
		
	}	
	if(R<A)
	{
		R=A;
	}
//	cout<<endl;
	A=0;
	}
cout<<R<<endl;
}
return 0;
}

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

int main(){
int n,Sum,Ans ;

while(1){

cin >> n ;

if(n==0){
break ;
}

vector<int> vec(n),vec2(n+1,0) ;

for(int i=0;i<n;i++){
cin >> vec.at(i) ;
}

for(int j=0;j<n;j++){
vec2.at(j+1)=vec.at(j)+vec2.at(j) ;
}
    
Ans=vec2.at(n) ;

for(int k=0;k<n+1;k++){
    for(int l=k+1;l<n+1;l++){
    Sum=vec2.at(l)-vec2.at(k);
    Ans=max(Sum,Ans) ;
    }
}

cout << Ans << endl ;

}

}

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

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

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

int main() {
	int n, a;
	vector<int> an;
	vector<vector<int>> AN;
	while (cin >> n) {
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> a;
			an.push_back(a);
		}
		AN.push_back(an); an.clear();
	}

	for (int i = 0; i < AN.size(); i++) {
		long long int max = 0, min = INT_MAX, MAX = 0, MIN = 0 , counter = 0, negative = 0;
		for (int j = 0; j < AN[i].size(); j++) {
			if (AN[i][j] >= 0) {
				max += AN[i][j];
				if (MAX < max)MAX = max;
				counter = 1;
				negative = 1;
			}
			
			else {
				if (negative == 0) {
						if(min > abs(AN[i][j]))min=abs(AN[i][j]);
					}
				else if (counter==1){
					if (AN[i][j] + max >= 0)max += AN[i][j];
					else {
						max = 0;
						counter = 0;
					}
				}
			}
		}
		if (negative == 0)cout << -1*min << endl;
		else cout << MAX << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    vector<int> a(n, 0); //?´??????¨
    vector<int> b(n, 0); //????????¨
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int k = n - 1;
    while (a[k] < 0)
      k--;
    b[k] = a[k];
    for (int i = k - 1; i > -1; i--) {
      if (a[i] < 0)
	continue;
      else {
	int j = i + 1;
	int s = 0; //?????????????????????????????¨
	while (a[j] < 0) {
	  s += a[j];
	  j++;
	}
	cout << "s = " << s << " " << "i = " << i << " " << "j = " << j << endl;
	if (s + b[j] >= 0)
	  b[i] += s + b[j] + a[i];
	else // if (a[i] > s + b[j])
	  b[i] += a[i];
	cout << "b[" << i << "]= " << b[i] << endl;
      }
    }
    for (int i = 0; i < n; i++)
      cout << "b[" << i << "]= " << b[i] << endl;
    int max = b[0];
    for (int i = 1; i < n; i++)
      if (max < b[i])
	max = b[i];
    cout << max << endl;
  }
}

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

int main(){
	bool flag[5000] = {false};
	int n, in[5000], ans, tmp = 0;
	
	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 = 0;
					}	
					else
						tmp = 0;
				}
			}
		}
		
		cout << ans << endl;//output
		
		ans = 0;
		for(int i = 0; i < n; ++i)
			flag[i] = false;//intialize
	
	}
	return 0;
}

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

int main() {
    int num;
    while (cin >> num, num) {
        vector<int> a(num);
        cin >> a[0];
        for (int i = 1; i < num; i++) {
            cin >> a[i];
            a[i] = max(a[i - 1] + a[i], a[i]);
        }
        cout << *max_element(a.begin(), a.end()) << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int n;
int sum[5000];
int ans;

void serch(int s_i,int s_ans)
{
	if(s_i==n)
		return ;
	
	s_ans+=sum[s_i];
	
	if(ans<s_ans)
		ans=s_ans;
	
	serch(s_i+1,s_ans);
}
int main()
{
	
	for(;;)
	{
		ans=-10000000;
		
		cin >> n ;
		if(n==0)
			break;
		
		for(int i=0;i<n;i++)
		{
			cin >> sum[i] ;
		}
		
		for(int i=0;i<n;i++)
		{
			serch(i,0);
		}
		
		cout << ans << endl;
	}
}

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 = max(sum+a[i], res);
			if (sum > res)
				res = sum;
		}
		printf("%d\n", res);
	}

	return 0;
}

C++: #include<stdio.h>

int main(void)
{
  int sum;
  int n[5000];
  int a=0,i,j,x=0,k;

  while(scanf("%d",&k) != EOF){
    if(k==0)
      break;

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

    x=-10000000;
    for(i=0; i<k; i++){
      sum =0; 
      for(j=i; j<k; j++){
	sum=sum+n[j];
	if(x<sum)
	  x=sum;
      }
    }
    printf("%d\n",x);
  }

  return 0;
}