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 <stdio.h>
#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <vector>
#define PB push_back
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using	namespace std;
int n,tmp;
void solve(){
	while(cin >> n  && n!= 0){
		vector <int> data ;
		REP(i,n){
			cin >> tmp;
			data.PB(tmp);
		}
		int sofar =0 ,end = 0;
		REP(i,n){
			end = max(end+data[i],0);
			sofar = max(end,sofar);
		}
		cout << sofar <<endl;


	}

}

int main(){
	solve();

}

C++: 
#include<stdio.h>
#include <iostream>
#include<bits/stdc++.h> 

using namespace std;
int length=0;
int* sums;

int main(){
  string str="";
  while(1){
  cin>>length;
  if(length==0)break;
  sums=new int[length+1];
  sums[0]=0;
  int s=0;
  for(int i=0;i<length;i++){
    int v=0;
    cin>>v;
    s+=v;
    sums[i+1]=s;
  }
  int max=INT_MIN;
  for(int i=0;i<length+1;i++){
    for(int j=i;j<length+1;j++){
      int diff=sums[j]-sums[i];
      if(diff>max){
        max=diff;
      }
    }
  }
  cout<<max;
  cout<<" ";
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <math.h>

using namespace std;

int main(void){
    int n,an[5100],max,sum;
    
    while (1)
    {
        cin>>n;
        if(n==0){break;}
        max=-100000;
        sum=0;
        for (int i=0; i<n; i++){cin>>an[i];}
        for(int i=0;i<n;i++)
        {
            if(max<an[i]){max=an[i];}
            sum=an[i];
            for (int j=i+1; j<n; j++)
            {
                sum += an[j];
                if (max<sum) {max=sum;}
            }
            sum=0;
        }
        cout<<max<<endl;
    }
        return 0;
}

C++: #include <bits/stdc++.h>
#ifdef dbg
#include "./printer.hpp"
#else
#define dump(x) void(0)
#endif

#define MOD 1000000007
using namespace std;
#define ll long long
inline long  toInt(string s) {long  v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int main(){
  ll n;
  while(cin >> n && n){
    vector<ll> a(n);
    for(ll i = 0; i < n; i++){
      cin >> a[i];
    }
    vector<ll> b(n);
    b[0] = a[0];
    for(ll i = 1; i < n; i++){
      b[i] = max(b[i-1] + a[i], a[i]);
    }

    ll ans = -MOD;
    for(ll i = 0; i < n; i++){
      ans = max(ans, b[i]);
    }
    cout << ans << '\n';
    
  }

}

C++: #include <cassert>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>

int solve(std::istream& in, int n)
{
    std::vector<int> all(n);
    std::vector<int> koho;
    int temp = 0;
    int max = 0;
    for(int i = 0; i < n; ++i) {
        in >> all[i];
        if(temp && all[i] < 0){
            koho.push_back(temp);
            if(temp + all[i] < 0){
                temp = 0;
            }else{
                temp += all[i];
            }
        }else
        if(all[i] > 0){
            temp += all[i];
        }
    }
    koho.push_back(temp);
    if(koho.empty()) return *std::min_element(all.begin(), all.end());
    return *std::max_element(koho.begin(), koho.end());
}
int main()
{
    int n;
    std::cin >> n;
    while(n){
        std::cout << solve(std::cin, n) << std::endl;
        std::cin >> n;
    }
    return 0;
}

C++: #include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<stack>
#include<set>
#include<cmath>

#define REP(i,s,e) for(int i=int(s);i<int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)

#define EPS 1e-6

using namespace std;

int main(){

   int n,a;
   while(true){


   cin >> n;
   if(n==0) break;

   vector<int>v;
   int s=0;
   v.push_back(s);

   rep(i,n){
   cin >> a;
   s+=a;
   v.push_back(s);
   }

   int vmin=0; int vmax=0;
   rep(i,n+1){
   if(v[i]<vmin) vmin=v[i];
   if(v[i]>vmax) vmax=v[i];
   }

	cout << vmax-vmin << endl;
	v.clear();

   }

	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
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, MAX = 0 , counter = 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;
			}
			else {
				if (counter==1){
					if (AN[i][j] + max >= 0)max += AN[i][j];
					else {
						max = 0;
						counter = 0;
					}
				}
			}
		}
		cout << MAX << endl;
	}
	
	return 0;
}

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

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;

int main (void){
  
    int number;
    int max;
    int answer[5010] = {0};
    int l = 0;
    while(cin >> number,number)
    {
        int a[5010] = {0};
        vector<int>tempmax(5010,0);
        vector<int>tempmax2(5010,0);
        REP(i,number)
        cin >> a[i];
        for(int i = number;i>=0;i--)
            for(int j = 0; j<i;j++)
            {
                tempmax[i] +=a[j];
            }
        for(int k = 0;k<number;k++)
            for(int m = k;m<number;m++)
            {
                if(k == m)
                    tempmax2[k] = a[k];
                else if(tempmax2[k]+a[m] >= tempmax2[k])
                    tempmax2[k]+= a[m];
                else
                    break;
            }
        sort(tempmax.begin(),tempmax.end(),greater<int>());
        sort(tempmax2.begin(),tempmax2.end(),greater<int>());
        if(tempmax[0]>tempmax2[0])
            answer[l] = tempmax[0];
        else
            answer[l] = tempmax2[0];
        l++;
    }
    REP(i,l)
    cout << answer[i] << endl;
    return 0;
}