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

int main(){
    while (1){
	int n;
	int input[5001];
	int max1;
	cin >> n;
	if (n == 0) break;

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

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

C++: #include <stdio.h>
int main()
{
	int n,a[5000];
	while(scanf("%d",&n)!=EOF){
		int max=-10001;
		if(n==0)
			break;
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				if(max<sum)
					max=sum;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<memory>
#include<array>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
  int a[5000];
  int n;
  
  while( cin >> n )
    {
      int mv = -200000;
      
      if ( n == 0 )
        break;

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

      unique_ptr<int[][5000]> c(new int[n][5000]);
      
      for ( int i = 0; i < n; ++i )
        {
          for ( int j = 0; j <= i; ++j )
            {
              if ( i == j )
                {
                  c[i][j] = a[i];
                }
              else
                {
                  c[i][j] = c[i - 1][j] + a[i];
                }
              mv = max( mv, c[i][j] );
            }
        }

      cout << mv << endl;
      
    }
  
  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;
        /*cin >> t;
        s[0]=t;max = t;min=t;*/
        s[0] = 0;
        long int max = 0;

        for(int i=0;i<n;i++){
            cin >> t;
            s[i+1] = s[i]+t;
            for(int j=0;j<i;j++)
            {
                if((s[i+1]-s[j])>max) max = s[i+1]-s[j];
            }
        }
        cout << max << endl;

    }

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <math.h>
#include <functional>
#include <algorithm>

typedef long long Int;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
using namespace std;

Int aa[10000];
Int dp[10000];

int main(){
	int n;
	while (cin >> n, n){

		REP(i, n){
			cin >> aa[i];
		}

		Int max_i = -999999999;
		dp[0] = max(dp[0], aa[0]);
		max_i = max(max_i, dp[0]);

		for (int i = 1; i < n; ++i){
			dp[i] = max(aa[i], dp[i - 1] + aa[i]);
			max_i = max(max_i, dp[i]);
		}
		cout << max_i << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;
int n,a[5008];
int b[5008];

int solve(){
  int res= -100001;
  for(int i=0;i<=n;i++){
    for(int j=n;j>i;j--){
      res=max(res,b[j]-b[i]);
    }
  }
  return res;
}

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

    b[0]=0;
    for(int i=1;i<=n;i++){
      b[i]=a[i]+b[i-1];
    }

    printf("%d\n",solve());

  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<cfloat>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<functional>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
const int mod = 1e9+7;
const int INFINT = INT_MAX/2;
typedef long long ll;
typedef unsigned long long ull;

int main(){
    int n;
    cin >> n;
    while(n!=0){
        int a[n];
        REP(i, n){
            cin >> a[i];
        }
        int maxSum = a[0];
        int res = -INFINT;
        for (int i=1;i<n;i++){
            if(maxSum + a[i] < a[i]){
                maxSum = a[i];
            }else{
                maxSum += a[i];
            }
            res = max(res, maxSum);
        }
        cout << res << endl;
        cin >> n;
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 999999
#define EPS 1.0e-10

using namespace std;

typedef long long ll;

int n;

int main()
{
	while (cin >> n) {
		if (n == 0)return 0;
		ll d[5250];
		
		d[0] = 0;
		int a;
		for (int i = 1; i <= n; i++) {
			cin >> a;
			d[i] = d[i - 1] + a;
		}
		ll max = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < i; j++) {
				if (d[i] - d[j] > max)max = d[i] - d[j];
			}
		}
		cout << max << endl;
	}

}

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	int a[5000];
	while (cin >> n&&n != 0) {
		int sum3 = -100000;
		for (int i = 0; i<n; i++)
			cin >> a[i];
		for (int i = 0; i<n; i++) {
			int sum = -10001;
			int sum2 = -10001;
			if(a[i] < 0) goto yo;
			for (int j = 0; j <= i; j++) {
				if (a[j]<0||(j<=1&&a[j-1]<0&&(a[j-1]+a[j])<0)) goto stop;;
				sum2 = 0;
				for (int z = j; z <= i; z++) {
					sum2 += a[z];
					if (sum < sum2) {
						sum = sum2; 
					}
				}
			stop:;
			}
		yo:;
			if (sum < a[i]) sum = a[i];
			if (sum3<sum) sum3 = sum;
		}
		cout << sum3 << endl;
	}
}

C++: 


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b)          for(i=a;i<b;i++)
#define repr(i,a,b)         for(i=a;i>=b;i--)

#define LL                  long long
#define ull                 unsigned long long int
#define scl(n)              scanf("%lld", &n)
#define scf(n)              scanf("%lf", &n)
#define sci(n)              scanf("%d", &n)
#define scii(n,m)           scanf("%d %d",&n,&m)
#define sciii(n,m,p)        scanf("%d %d %d",&n,&m,&p)
#define scs(n)              scanf("%s", n)
#define pfi(n)              printf("%d\n",n)
#define pfl(n)              printf("%I64d ",n)
#define pfs(s)              printf("%s\n",s)

#define MOD                 1000000007
#define MODP                99999999999973LL
#define pb                  push_back
#define ff                  first
#define ss                  second
#define mp                  make_pair
#define pp                  pair<int,int>
#define memo(a,b)           memset(a,b,sizeof(a))
#define INF                 1e9
#define EPS                 1e-8
#define Pi                  acos(-1.0)

#define N 100005


int main()
{

    int n;


    while(cin>>n && n)
    {

        LL arr[5000];

        for(int i=0;i<n;i++)
            scl(arr[i]);


        LL sum=0;
        LL res=LONG_LONG_MIN;


        for(int i=0;i<n;i++)
        {
            sum+=arr[i];
            
            res=max(res,arr[i]);
            res=max(res,sum);

            if(sum<=0)
                sum=0;
        }
       // cout<<"sss"<<endl;
       cout<<res<<endl;

    }

    return 0;
}

/* int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction