Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sum := make([]int, 5001)
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			a := nextInt()
			sum[i+1] = sum[i]+a
		}
		ret := sum[1]
		for i := 0; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				ret = max(ret, sum[j]-sum[i])
			}
		}
		fmt.Println(ret)
	}
}

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

int main(){
int n,Sum,Ans ;

while(1){

Ans=0 ;

cin >> n ;

if(n==0){
break ;
}

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

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

for(int j=0;j<n;j++){
vec2.at(j+1)=vec.at(j)+vec2.at(j) ;
}

for(int k=0;k<n+1;k++){
    for(int l=k+1;l<n+1;l++){
    Sum=vec2.at(l)-vec2.at(k);
    Ans=max(Sum,Ans) ;
    }
}
cout << Ans << endl ;

}
}

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

int main()
{
    while(1){
        int n,sum=0;
        cin>>n;
        if(n==0)
            break;
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum+=a[i];
        }
        cout<<sum<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#define ll long long int
using namespace std;

int main()
{
  ll n,a;
  ll i,j;
  ll b[5005]={};

  while(1){
    priority_queue<int> pq;
    cin>>n;
    if(n==0)break;
    for(i=1;i<=n;i++){
      cin>>a;
      b[i]=b[i-1]+a;
      for(j=i;j>=0;j--)
	pq.push(b[i]-b[j]);
    }
    cout<<pq.top()<<endl;
  }
}

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

int maxsum(const vector<int>& data){
  int maxsumval=0,n=data.size();
  for(int i=0;i<n;i++){
    int sum=0;
    for(int j=0;j<n;j++){
      sum+=data[i+j];
      if(sum>maxsumval)maxsumval=sum;
    }
  }
  return maxsumval;

}
int main(){
  int n;
  while(cin>>n&&n){
    vector<int> data(n);
    for(int i=0;i<n;i++){
      cin>>data[i];
    }
    int maxsumval=maxsum(data);
    cout<<maxsumval<<endl;
  }

}

C++: #include <iostream>

int calcMaxSum(int amount_set);

int main()
{
    while (true) {
        int amount_set;
        std::cin >> amount_set;
        if(amount_set == 0) {
            break;
        }
        std::cout << calcMaxSum(amount_set) << std::endl;
    }

    return 0;
}

int calcMaxSum(int amount_set)
{
    const int MAXNUMBER = 100000;//??\????????????????????§??????

    int *data;
    data = new int[amount_set + 1];
    int *sum = new int[amount_set + 1];

    sum[0] = 0;//???????????????????????????????????´??????sum[0]??§??????

    std::cin >> data[1];//?????????????????±???
    sum[1] = data[1];//?????????????????????

    for (int number = 2; number <= amount_set; number++) {
        std::cin >> data[number];//????????????????????????
        sum[number] = sum[number - 1] + data[number];// ????????´??°
    }

    int max = -MAXNUMBER;//????????????????????¨??¨-MAXNUMBER???????????????????????§???????????????????????????????°????

    for (int number_big = 1; number_big < amount_set; number_big++) {
        for (int number_small = 0; number_small < number_big; number_small++)
            if (sum[number_big] - sum[number_small] > max) {
                max = sum[number_big] - sum[number_small];
            }
    }
    delete [] data;
    delete [] sum;

    return max;

}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n;
    while(cin>>n,n){
        vi v(n+1,0);
        rep(i,n)cin>>v[i];
        ll ans=0, temp;
        for(int i=0;i<n;i++){
            temp=0;
            for(int j=i;j<n;j++){
                temp+=v[j];
                ans=max(ans,temp);
            }
        }
        if(n==1)cout<<v[0]<<endl;
        else cout<<ans<<endl;
    }
}

C++: #include <stdio.h>

int main(){
	int n;
	int buf[5000];
	long goukei;
	long max;
	
	int i,j,k;
	
	while(1){
		goukei = 0;
		max = 0;
		scanf("%d",&n);
		if(n == 0)break;
		for(i = 0;i < n;i++){
			scanf("%d",&buf[i]);
		}
		
		for(i = 0;i < n;i++){
			for(j = 0;j < n-i;j++){
				for(k = j;k <= j+i;k++){
					goukei += buf[k];
				}
				if(goukei > max){
					max = goukei;
				}
				goukei = 0;
			}
		}
		
		printf("%d\n",max);
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

void Solution()
{
    int n;  // period or cycle or term
    int input; // every element
    
    long sum;
    long max; // the biggest value
    
    while(cin>>n, n != 0)
    {
        cin >> input; // the first number of sequence
        
        max = sum = input;
        
        for(int i = 0; i < n - 1; i++)
        {
            cin >> input;
           
            if(sum < 0) // judge based on the first number of sequence
            {
                sum = input;
            }
            else
            {
                sum += input;
            }
            
            if(sum > max)
            {
                max = sum;
            }
        }
        
        cout<<max<<endl;
    }
}

int main()
{
    Solution();
    return 0;
}

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

int main(){
        int n,a[5010];
        while(cin>>n && n){
                for(int i=0; i<n; i++) cin >> a[i];
                long max = 0;
                for(int k = 1; k<=n; k++){
                        long sum = 0;
                        for(int i=0; i<k; i++){
                                sum += a[i];
                        }
                        max = (max>sum)? max:sum;
                        for(int i=0; i<n-k; i++){
                                sum += (a[k+i]-a[i]);
                                max = (max>sum)? max:sum;
                        }
                }
                cout << max << endl;
        }

}

C++: 
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;

int main()
{
	int n;

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

		int sum = 0, input, maxer = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> input;
			sum += input;

			if (sum < 0)
				sum = 0;
			maxer = max(sum, maxer);
		}

		cout << "?????????" <<  maxer << endl;
	}


	return 0;
}

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

#define MAX 1000000000
#define MIN -10000000000

#define ll long long

using namespace std;
int main() {

        ll n,k,i,j,temp,last,maxx;
        do {
            cin>>n;
            if(n==0)break;
            vector<ll> a(n);
            vector<ll> s(n+1);
            for(i=0;i<n;i++){
                cin>>a[i];
            }
            s[0]=0;
            for(i=0;i<n;i++){
                s[i+1]=s[i]+a[i];
            }
            maxx=a[0];
            for(i=0;i<n;i++){
                for(j=i;j<=n;j++){
                    maxx=max(s[j]-s[i],maxx);
                }
            }
            cout << maxx << endl;



        }while(n!=0);

//cout << "aaa" << endl;

    return 0;
}