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>
#include <climits>
typedef long long ll;
using namespace std;
 
int main(){
    int n,a[5001];
    int ans;
    a[0]=0;
    while(cin>>n&&n){
        ans = INT_MIN;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            a[i] += a[i-1];
        }
        for(int i=1;i<=n;i++){
            for(int j=i;j<=n;j++){
                ans = max(ans,a[j]-a[i-1]);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

int main()
{
    int n;

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

        int max = 0, max2 = -1000000;
        int sum = 0;
        int a[n];
        for( int i = 0; i < n; i++ )
        {    
            cin >> a[i];

            if( a[i] > 0 )
            {
                sum += a[i];
                if( max < sum )
                    max = sum;
            }
            else
            {
                if( sum + a[i] > 0 )
                    sum += a[i];
                else
                    sum = 0;
            }
            
            if( max2 < a[i] )           //全てが負の値だった時に、その中でも最大の値を格納。
                max2 = a[i];
        }
        if( max == 0 )
            cout << max2 << endl;
        else
            cout << max << endl;
    }
    return 0;
}

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

constexpr int INF = 1e9;

int solve (int n) {
	int ans = -INF, sum = 0;
	for (int i = 0; i < n; i++) {
		int e; cin >> e;
		sum = max(sum + e, e);
		ans = max(ans, sum);
	}
	return ans;
}

int main() {
	int n;
	while (true) {
		cin >> n;
		if (n > 0) cout << solve(n) << '\n';
		else break;
	}
	return 0;
}

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

int main(){
	int n;
	while(cin >> n,n){
		int a,dp[5001] = {},ma = 0;
		for(int i = 0;i < n;i++) {
			cin >> a;
			dp[i + 1] = max(a,dp[i] + a);
			ma = max(ma,dp[i + 1]);
		}
		cout << ma << endl;
	}
	return 0;
}

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

int main()
{
	std::uint32_t n;
	for (std::cin >> n; n != 0; std::cin >> n) {
		typedef std::vector<std::int32_t> IntVec;
		IntVec a(n);
		for (std::size_t i = 0; i < n; ++i) {
			std::cin >> a[i];
		}
		for (std::size_t i = 1; i < n; ++i) {
			a[i] = std::max(a[i], a[i] + a[i - 1]);
		}
		std::cout << *std::max_element(a.begin(), a.end()) << std::endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	for (; ;)
	{
		int n;
		cin >> n;

		if (n == 0)
		{
			break;
		}

		vector<int> a(n);
		for (int i = 0; i < n; i++)
		{
			cin >> a.at(i);
		}

		int maxv = 0;
		for (int i = 0; i <= n; i++)
		{
			
			for (int j = 0; j < n; j++)
			{
				int sum = a.at(j);
				for (int k = j + 1; k < i; k++)
				{
					sum += a.at(k);
				}
				maxv = max(maxv, sum);
			}
		}

		cout << maxv << endl;
	}
}

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

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

		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];
			cout << a[i] << endl;
		}
		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>
#include <stack>
#include <stdio.h>
#include <cmath>
#include <utility>
using namespace std;
int main()
{
    int n;
	while(cin>>n&&n){
		int a[5000]={},sum[5000]={},m=-1000000;
		for(int i=0;i<n;i++){
			cin>>a[i];
			sum[i+1]=sum[i]+a[i];
		}
		for(int i=0;i<n;i++){//start
			for(int j=i;j<n;j++){//end
				int tmp=sum[j+1]-sum[i];
				if(tmp<=0){i=j;break;}
				//printf("%d-%d:%d\n",i,j,tmp);
				m=max(m,tmp);
			}
		}
		cout<<m<<endl;
	}
    return 0;
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        int data[10000]={};
        rep(i,n) cin>>data[i];
    
    
        int maxi=-999999999;
        int dp[500][500]={};
        rep(i,n){
            for(int j=i;j<n+1;j++){
                if(i-1>=0){
                    dp[i][j]=dp[i][j-1]+data[j-1];
                    maxi=max(maxi,dp[i][j]);
                }
            }
        }
        cout<<maxi<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		long long int a[5000], sum = 0, hold = 0;
		for(int i = 0;i < n;i++){
			cin >> a[i];
		}
		hold = a[0];
		for(int i = 0;i < n;i++){
			sum += a[i];
			for(int j = i+1;j < n;j++){
				sum += a[j];
				if(hold < sum){
					hold = sum;
				}
			}
			sum = 0;
		}
		cout << hold << endl;

	}
	
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
	int z=-1,n,i,j[255],o,maxo=-100000,s[5000]={0};
	scanf("%d",&n);
	while(n!=0){
		o=0;
		z++;
		for(i=0;i<n;i++){
			scanf("%d",&s[i]);
		}
		for(i=1;i<n;i++){
			if(s[i]<s[i-1]+s[i]){
				s[i]=s[i-1]+s[i];
			}

		}
		for(i=0;i<n;i++){
			maxo=max(maxo,s[i]);
		}
		j[z]=maxo;
		maxo=-100000;
		scanf("%d",&n);
	}
	for(i=0;i<=z;i++){
		printf("%d\n",j[i]);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int,int> Pi;

const int INF=100000000;
const long long int INF_=1000000000000000000;

int main(){
	int N;
	while(cin >> N&&N){
		vector<int> A(N+1);
		REP(i,1,N+1) cin >> A[i];
		vector<int> s(N+1);
		REP(i,1,N+1) s[i]=s[i-1]+A[i];
		lli ans=-INF_;
		REP(i,0,N+1) REP(j,i+1,N+1) if(ans<s[j]-s[i]) ans=s[j]-s[i];
		cout << ans << endl;
	}
	return 0;
}