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 <algorithm>
#include <vector>

template <typename Iterator>
auto findMaximumSum (Iterator begin , Iterator end) -> long long
{
    auto res = * begin ++;
    auto tmp = res;
    for (auto ite = begin; ite != end; ++ ite)
    {
        tmp += * ite;
        res = std::max (res , tmp);
    }
    return res;
}

auto main () -> int
{
    int n;
    while (std::cin >> n && n)
    {
        std::vector <long long> a (n);
        for (auto i = 0; i < n; ++ i)
        {
            std::cin >> a [i];
        }
        auto ans = -5000000000LL;
        auto last = a.end () - 1;
        for (auto ite = a.begin (); ite != last; ++ ite)
        {
            auto tmp = findMaximumSum (ite , a.end ());
            ans = std::max (ans , tmp);
        }
        std::cout << ans << std::endl;
    }
}

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

int main()
{
	int n;
	while(cin>>n){
		if(n==0) break;
		int a[n], S[n], sum=0;
		for(int i=0;i<n;++i){
			cin>>a[i];
			sum+=a[i];
			S[i]=sum;
		}

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

		cout<<max<<endl;
	}

	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

int n;
int a[10000];
long long int ans = -(1 << 50);

while(true){

cin > n;

if(n == 0) break;

for(int i = 0; i < n; i++){

cin >> a[i];

}

long long int sum;

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

cout << ans << endl;

}

return 0;

}

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

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

int main() 
{
    int n;
    while (scanf("%d", &n)&&n!=0) {
        long long int a[n];
        for (int i=0; i<n; i++) scanf("%lld", &a[i]);
        long long int dp[n];
        dp[0] = a[0];
        long long int res = -100000 * 5000 - 1;
        for (int i=1; i<n; i++) {
            dp[i] = max(a[i], dp[i-1]+a[i]);
            res = max(res, dp[i]);
        }
        printf("%lld\n", res);
    }
}

C++: #include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>

using namespace std;


long sumarray(long *array, int idx1, int idx2);


int main(){
  int n;
  long Max, ibuf;
  long *List;

  //ifstream ifs("input.txt"); // for debug

  cin >> n;
  while(1){

    // allocate and set value //////////////////////////////
    List = new long[n];
    for(int i=0; i<n; i++) cin >> List[i];

    // solve part //////////////////////////////////////////
    Max = 0;
    for(int l=1; l<=n; l++){
      ibuf = sumarray(List, 0, l);
      if(ibuf > Max) Max = ibuf;
      for(int i=0; i<n-l; i++){
	ibuf += List[i+l] - List[i];
	if(ibuf > Max) Max = ibuf;
      }
    }

    // deallocate //////////////////////////////////////////
    delete List;

    // output //////////////////////////////////////////////
    cout << Max;

    // for next loop //////////////////////////////////////
    cin >> n;
    if(n == 0) break;
    else cout << endl;

  }
  return 0;
}


long sumarray(long *array, int idx1, int idx2){ // array[idx1] + ... + array[idx2-1]
  int ret = 0;
  for(int i=idx1; i<idx2; i++){
    ret += array[i];
  }
  return ret;
}

C++: #include <iostream>
#include <cstdlib>
#include <climits>
using namespace std;
const static int L_MAX = 5001;

int main() {
  while( 1 ) {
    int n;
    cin >> n;
    if( !n ) { return EXIT_SUCCESS; }

    int seq[ L_MAX ];
    int sum[ L_MAX ];
    int maxv = INT_MIN;
    int minvInSum = 0;
    seq[ 0 ] = 0;
    sum[ 0 ] = 0;

    for( int i = 1; i <= n; i++ ) {
      cin >> seq[ i ];
      sum[ i ] = sum[ i - 1 ] + seq[ i ];
      minvInSum = min( minvInSum, sum[ i ] );
      maxv = max( maxv, sum[ i ] - minvInSum );
    }
    cout << maxv << endl;
  }
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		vi array(n+1);
		array[0] = 0;
		reep(i, 1, n+1){
			scanf("%d", &array[i]);
			array[i] += array[i-1];
		}

		int ans = INT_MIN;
		rep(i, n){
			reep(j, i+1, n+1)
				ans = max(ans, array[j]-array[i]);
		}

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

	return 0;
}

C++: #include<iostream>
using namesapce 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 <iostream>
using namespace std;

int main() {
	int n;
    while(1){
        cin>>n;
        if(!n)break;

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

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

int64_t a[5000];
int64_t dp[2][5000];

int64_t solve(int n){
  int64_t summax=INT64_MIN;
  for(int i=0;i<n;i++){
    summax = (summax < a[i])?a[i]:summax;
  }

  for(int i=1;i<n;i++){
    for(int j=0;j<n-i;j++){
      dp[i%2][j] = dp[(i-1)%2][j] + a[i+j];

      summax = (summax < dp[i%2][j])?dp[i%2][j]:summax;
    }
  }
  return summax;
}

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

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

    cout << solve(n) << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int a[5000];
	int left[5000], right[5000];
	int n;
	
	while (true) {
		cin >> n;
		if (n==0) break;
		
		bool existsPos = false;
		for (int i=0; i<n; i++) {
			cin >> a[i];
			if (a[i] > 0) existsPos = true;
		}
		
		int maximum;
		
		if (existsPos) {
			int left_max = a[0];
			int left_max_pos = 0;
			left[0] = a[0];
			for (int i=1; i<n; i++) {
				left[i] = left[i-1] + a[i];
				if (left[i] > left_max) {
					left_max = left[i]; left_max_pos = i;
				}
			}
			int right_max = a[n-1];
			int right_max_pos = n-1;
			right[n-1] = a[n-1];
			for (int i=n-2; i>=0; i--) {
				right[i] = right[i+1] + a[i];
				if (right[i] > right_max) {
					right_max = right[i]; right_max_pos = i;
				}
			}
			
			maximum = 0;
			for (int i = right_max_pos; i <= left_max_pos; i++) maximum += a[i];
		}
		else {
			maximum = -100000;
			for (int i=0; i<n; i++) {
				if (a[i] > maximum) maximum = a[i];
			}
		}
		
		cout << maximum << endl;
	}
		
	return 0;
}

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

int main()
{
	int n;
	while(cin>>n){
		if(n==0) break;
		int a[n], S[n], sum=0;
		for(int i=0;i<n;++i){
			cin>>a[i];
			sum+=a[i];
			S[i]=sum;
		}

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

		cout<<max<<endl;
	}

	return 0;