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


int main() {
    int n;
    std::cin >> n;
    while (n != 0) {
        std::vector vec(n+1, 0);
        int x;
        for (int i = 1; i <= n; ++i) {
            std::cin >> x;
            vec[i] = x;
        }
        std::vector<int> sum;
        sum.assign(n+1, 0);
        sum[1] = vec[1];
        for (int i = 1; i < n; i++) {
            sum[i+1] = sum[i] + vec[i+1];
        }
        int ans = -1000000000;
        for (int l = 1; l <= n; ++l) {
            for (int r = l; r <= n; ++r) {
                ans = std::max(ans, sum[r] - sum[l-1]);
            }
        }
        std::cout << ans << std::endl;
        std::cin >> n;
    }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n, sum, ans, a[5001];
  while(1){
    cin >> n;
    if(n == 0) 
      break;
    ans = -100000;
    for(int i = 0; i < n; i++)
      cin >> a[i];
    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;
  }
}

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

int main(){
        int n,a[5010];
        while(cin >> n && n){
                int buf,j=0;
                for(int i=0; i<n; i++){
                        cin >> buf;
                        if(i>0 && a[j]*buf>=0) a[j] += buf;
                        else a[++j] = buf;
                }
                long max = 0;
                for(int i=0; i<j; i++){
                        for(int k=i; k<=j; k++){
                                long sum = 0;
                                for(int l=i; l<=k; l++){
                                        sum += a[l];
                                }
                                max = (max > sum)? max:sum;
                        }
                }
                cout << max << endl;
        }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
long long dp[6000],n,a[6000],i,maxm;
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=1;i<=n;i++)cin>>a[i];
    dp[1]=maxm=a[1];
    for(int i=2;i<=n;i++){
      if(dp[i-1]>=0)dp[i]=dp[i-1]+a[i];
      else dp[i]=a[i];
       
      maxm=max(dp[i],maxm);
    }
    cout<<maxm<<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 = 0;
    for(ll i = 0; i < n; i++){
      ans = max(ans, b[i]);
    }
    cout << ans << '\n';
    
  }

}

C++: #include<iostream>
#include<vector>
using namespace std;
int main() {
	int a,i,j,k,n;
	long long max, sum;
	vector<int> s;
	while (cin >> n) {
		if (n == 0)break;
		s.clear();
		max = 0;
		for (i = 0; i < n; i++) {
			cin >> a;
			s.push_back(a);
		}
		for (j = 0; j < n; j++) {
			sum = 0;
			for (k = j; k < n; k++) {
				sum += s[k];
				if (sum > max)max = sum;
			}
		}
		cout << max << endl;
	}
	return 0;
}

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

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

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

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

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

	return 0;
}

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

int main(){
    int n;
    while(cin>>n && n!=0){
        int* A=new int[n];
        int* S=new int[n+1];
        S[0]=0;
        for(int i=0;i<n;++i){
            cin>>A[i];
            S[i+1]=A[i]+S[i];
        }

        int maxsum=0;
        for(int i=0;i<n;++i){
            for(int j=i+1;j<n+1;++j){
                maxsum=(S[j]-S[i]>maxsum?S[j]-S[i]:maxsum);
            }
        }

        cout<<maxsum<<"\n";
        delete[] A;
        delete[] S;
    }
}

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

int do_stuff(int n)
{
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }

    int max_so_far = 0;
    int max_ending_here = 0;

    for (int i = 0; i < n; ++i) {
        int curr = a[i];
        max_ending_here = max(max_ending_here + curr, 0);
        max_so_far = max(max_so_far, max_ending_here);
    }

    if (max_so_far == 0) {
        max_so_far = *max_element(a.begin(), a.end());
    }
    return max_so_far;
}

int main(int argc, char* argv[])
{
    //freopen("input.txt", "r", stdin);
    int n;
    scanf("%d", &n);
    while (n != 0) {
        int ans = do_stuff(n);
        printf("%d\n", ans);
        scanf("%d", &n);
    }
    return 0;
}

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

vector<int> num;
int dp[5000];

void init(){
  for(int i = 0; i < 5000; i++){
    dp[i] = 0;
  }
  num.clear();
}

int main(void){
  while(true){
    int maximum = 0, n;
    cin >> n;
    if(!n)  break;
    init();
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      num.push_back(tmp);
    }
    for(int i = 0; i < n; i++){
      dp[i] = max(dp[i-1] + num[i], num[i]);
    }
    
    for(int i = 0; i < n; i++){
      if(dp[i] > maximum) maximum = dp[i];
    }

    cout << maximum << 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++;
        cout << answer[l-1] << endl;
    }
    return 0;
}