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"bits/stdc++.h"
#define INF LLONG_MAX-1
using namespace std;
typedef long long ll;
??
ll a[100001];
int main(){
	ll n;
	ll cnt = 0;
	scanf("%lld", &n);
	for (ll i = 0; i < n; i++){
		scanf("%lld", &a[i]);
		cnt += a[i];
	}
	ll Max = cnt;
	ll w = 0;
	for (ll i = 0; i < n; i++){
		cnt -= a[i];
		if (Max < cnt) {
			w = i;
			Max = cnt;
		}
	}
	cnt = Max;
	for (ll i = n - 1; i > w; i--){
		cnt -= a[i];
		Max = max(Max, cnt);
	}
	printf("%lld\n", Max);
	return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

int main() {
  int n;

  while(cin >> n, n) {
    VI a(n);
    REP(i, n) cin >> a[i];

    int ans = -1000000;
    REP(i, n) {
      int sum = 0;
      FOR(j, i, n) {
	sum += a[j];
	ans = max(sum, ans);
      }
    }

    cout << ans << endl;
  }
}

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

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

int n;
vector<int> v;

int s[5000][5000];

int main(){
    while(cin>>n,n){
        v=vector<int>(n);
        REP(i,n)cin>>v[i];
        int ans=-(1<<15);
        REP(i,n){
            s[i][i]=v[i];
            ans=max(s[i][i],ans);
            for(int j=i+1; j<n; j++){
                s[i][j]=s[i][j-1]+v[j];
                ans=max(s[i][j],ans);
            }
        }
        cout<<ans<<endl;
    }
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

  template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n){
    if(n == 0) break;
    vector<int> a(n+1,0);
    int ans =0,res= 0;
    rep(i,n){
      cin >> a[i];
      ans +=a[i];
    }
    rep(i,n){
      vector<int> kt(n+1,0);
      for(int j = i;j<n;++j){
        kt[j] += kt[j-1]+a[j-1];
      }
      ans = max(ans,*max_element(all(kt)));
    }
    cout << ans << endl;
  }
  return 0;
}

C++: //
#include <iostream>
using namespace std;
int main()
{
  int n;
  while(true){
    int a[5000] = {0};
  cin >> n;
  if (n == 0 ) break;
  for (int i = 0; i < n;i++)
    cin >> a[i];
  int sum_max = a[0];
  int sum = 0;
  for (int i = 0; i <n;i++){
    for (int j = i; j < n; j++){
      sum += a[j];    if(sum > sum_max) sum_max = sum;
    }
    int sum = 0;
  }

  }
  cout << sum_max;
    

  }
}

C++: #include <stdio.h>

int seqsum(int n){
	int a = 0;
	int b[5000];
	int c = 0;
	int s = 0;
	scanf("%d", &a);
	b[0] = s = a;

	for(int i=1; i<n; ++i){
		scanf("%d", &a);
		if(s * a >= 0){
			b[c] += a;
		}else{
			b[++c] = s = a;
		}
	}

	int m = b[0] < 0 ? 0 : b[0];
	int sum = m;
	for(int i=1; i<=c; ++i){
		if(sum < 0 && m < b[i]){
			sum = m = b[i];
		}else{
			sum += b[i];
			if(m < sum){
				m = sum;
			}
		}
	}
	return m;
}

int main(void){
	int n = 0;
	while(true){
		scanf("%d", &n);
		if(n == 0){ break;}
		printf("%d\n", seqsum(n));
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	while(1){
		int n ; cin >> n ; if(!n) break;
		int* a=new int[n];
		for(int i=0;i<n;i++) cin >> a[i];
		int MAX=a[0];
		for(int i=0;i<n;i++){
			int temp=0;
			for(int j=i;j<n;j++){
				temp+=a[j];
				if(temp>MAX) MAX=temp;
			};
		};
		cout << MAX << '\n' ;
		delete[] a;
	};
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;





int main()
{
	int n;
	long long a[5000];
	long long b[5000];//i???????????§??????
	long long m, M;
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		for (int i = 0; i < n; i++) {
			if (i == 0) b[i] = a[i];
			else b[i] = b[i - 1] + a[i];
		}
		for (int i = 0; i < n; i++) {
			if (i == 0) {
				m = min({ (long long)0,b[0] });
				M = max({ (long long)0,b[0] });
			}
			else {
				if (b[i] - m > M) {
					M = b[i] - m;
				}
				if (b[i] < m) {
					m = b[i];
				}
			}
		}
		if (M == 0 && b[0] < 0) {
			for (int i = 0; i < n; i++) {
				if (i == 0) M = b[i];
				else {
					if (b[i] > M) M = b[i];
				}
			}
		}
		cout << M << endl;
	}

}