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 <iostream>

using namespace std;
using llong = long long;

llong A[5000];
llong P[5001];
int main(){
  int n;
  while(cin >> n&&n>0){
    for(int i=0;i<n;++i){
      cin >> A[i];
    }

    for(int i=1;i<=n;++i){
      P[i] = P[i-1] + A[i-1];
    }

    llong maxsum = -1000000000000;
    for(int i=0;i<n;++i){
      for(int j=i+1;j<=n;++j){
        if(P[j]-P[i]>maxsum){
          maxsum = P[j] - P[i];
        }
      }
    }
    cout << maxsum << endl;
  }
  return 0;
}

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

using namespace std;

int main() {

    int n;

    while(cin >> n, n) {

        int num[n], sum, maxSum = -100000;

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

        for(int i = 0; i < n; ++i) {
            sum = 0;
            for(int j = i; j < n; ++j) {
                sum += num[j];
                maxSum = max(maxSum, sum);
            }
        }

        cout << maxSum << endl;

    }

}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a[10000],best,count;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		cin>>a[i];
	best=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=n-i;j++){
			count=0;
			for(int k=0;k<=i;k++)
				count+=a[j+k];
			best=max(count,best);
		}
	}
	cout<<best<<endl;
	}
    return 0;
}

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

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 = 0;
		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 namespace std;
int main(){
  int n,math[5010],most,bell;
  while(1){
    cin >> n;
    if(n==0){
      break;
    }

    most=0;

    for(int i=0;i<n;i++){
      cin >> math[i];
    }
    for(int i=0;i<n;i++){
      bell=0;
      for(int j=i;j<n;j++){
	bell+=math[j];
	if(most<bell){
	  most=bell;
	}
      }
    }
    cout << most << endl;
  }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<iomanip>
#include<map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
int dx[8] = { 1,0,-1,0,1,1,-1,-1 };
int dy[8] = { 0,1,0,-1,1,-1,1,-1 };


int main() {

	int n;

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

		vector<int> a(n);

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

		vector <int> s(n + 1, 0);

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

		int maxi = -INF;

		for (int i = n; i > 0; i--) {
			for (int j = i - 1; j >= 0; j--) {
				maxi = max(maxi, s[i] - s[j]);
			}
		}

		cout << maxi << endl;
	}


		return 0;
	}

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

int a[5000],n;
int main(){
    while(cin>>n,n){
        for(int i=0;i<n;i++)cin>>a[i];
        int ma=0;
        for(int i=0;i<n;i++){
            int cur=0;
            for(int j=i;j<n;j++){
                cur+=a[j];
                ma=max(ma,cur);
            }
        }
        cout<<ma<<endl;
    }
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int num[5000];

int main() {
	int N;
	while(scanf("%d", &N), N) {
		memset(num, 0, sizeof(num));
		int ans = 0;
		rep(i, N) {
			scanf("%d", &num[i]);
			ans += num[i];
		}
		rep(i, N) {
			int sum = 0;
			FOR(j, i, N) {
				sum += num[j];
				ans = max(ans, sum);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

using namespace std;

int main() {
	int n;
	while (cin >> n && n != 0) {
		vector<int> num(n);
		for (int i=0; i<n; i++) {
			cin >> num[i];
		}
		int m=0,sum=0;
		for (int i=0; i<n; i++) {
			sum=num[i];
			for (int j=i+1; j<n; i++) {
				sum += num[j];
				m = max(m, sum);
			}
		}
		cout << m << endl;
	}
	return 0;
}

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

int main(){
  int n, num, a, maxx;

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

    num = 0;

    for(int i=0;i<n;i++){
      cin >> a;
      num += a;
      if(i == 0) maxx = a;
      if(num<0) num = 0;
      maxx = max(maxx,num);
    }
    cout << maxx << endl;
  }

  return 0;
}

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

int main(){
	int n;
	int a;
	int result;
	cin >> n;
	while(n){
		for(int i=0;i<n;i++){
			cin >> a;
			result += a;
		}
		cin >> n;
	}
	return 0;
}

C++: #define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
using namespace std;

int main(){
        int N;
        while(cin >> N && N > 0){
                int a[N];
                REP(i,N){
                        cin >> a[i];
                }

                int maximum = 0;
                REP(i,N){
                        int maximum_i = 0;
                        REP(j,N-i){
                                int sum = 0;
                                REP(k,i+1){
                                        sum += a[j+k];
                                }
                        maximum_i = max(sum,maximum_i);
                        }
                maximum = max(maximum_i,maximum);
                }
                cout << maximum << endl;

        }
}

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

int main(){
	const int nmax = 5001;
	int n;
	int nums[nmax];
	while(cin >> n){
		if(n == 0) break;
		int a;
		for(int i = 1;i <= n; i++){
			cin >> a;
			nums[i] = a;
		}
		int total_max = -INT_MAX;
		for(int i = 1; i <= n; i++){
			int total = 0;
			for(int j = i; j <= n; j++){
				total += nums[j];
				total_max = max(total_max, total);
			}
		}
		cout << total_max << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>

int main(void)
{
    int n;
    int num[5001];
    int sum;
    int max;
    
    while (scanf("%d", &n)){
        if (n == 0) break;
        memset(num, 0, 5001);
        max = 0;
        sum = 0;
        for (int i = 0; i < n; i++){
            scanf("%d", &num[i]);
        }
        
        for (int i = 0; i < n; i++){
            sum = 0;
            for (int j = i; j < n; j++){
                sum += num[j];
                if (max < sum) max = sum;
            }
        }
        
        printf("%d\n", max);
    }
}

C++: #include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n&&n!=0)
{
int a[n];
int A=0;
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;
}