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>
using namespace std;

int main(){
	int n, m, a[5001], sum , max;

	while(1){
		max = 0;
		cin >> n;
		if(n==0) break;
		
		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];
				if(max<sum) max = sum;
			}
		}
		cout << max << endl;
	}
	return 0;
}

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

vector<int> num;

int main(void){
  while(true){
    int maximum = 0, n;
    cin >> n;
    if(!n)  break;
    num.clear();
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      num.push_back(tmp);
    }
    for(int i = 0; i < num.size(); i++){
      int sum = num[i];
      for(int j = i + 1; j < num.size(); j++){
        sum += num[j];
        if(sum > maximum) maximuma = sum;
      }
    }
    cout << maximum << endl;
  }
  return 0;
}

C++: #include<cstdio>
int main(){int n,i,j,s,m,a[5000];while(scanf("%d",&n)&&n){for(i=0;i<n;i++)scanf("%d",&a[i]);m=-500000001;for(i=0;i<n;i++,s=0)for(j=i;j<n;)if((s+=a[j++])>m)m=s;printf("%d\n",m);}}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

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

typedef long long ll;

int main()
{
	int n, T[5001], dp[5001];
	while(cin >> n, n)
	{
		for(int i = 0; i < n; i++)
		{
			cin >> T[i];
		}

		memset(dp, -1, sizeof(dp));

		dp[0] = T[0];

		for(int i = 1; i < n; i++)
		{
			dp[i] = max(dp[i-1] + T[i], T[i]);
		}

		int res = -10000000;
		
		for(int i = 0; i < n; i++)
		{
			res = max(res, dp[i]);
		}

		cout << res << endl;
	}
}

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


int main()
{
    for (int n; cin >> n && n;) {
        vector<int> sequence(n);
        int sum = 0;
        int min = 0;
        int min_buffer = 0;
        int max = numeric_limits<int>::min();
        for (int x, i = 0; i < n && cin >> x; i++) {
            sum += x;
            if (sum < min)
                min_buffer = sum;
            if (sum > max) {
                max = sum;
                min = min_buffer;
            }
        }
        cout << max - min << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <stack>

using namespace std;

stack<int> s;
int ac;

int main(void) {
    while(~scanf("%d", &ac)) {
        if(ac == 0) {
            cout << s.top() << endl;
            s.pop();
        } else {
            s.push(ac);
        }
    }
    return 0;
}

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

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

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=0;j<n-i-1;j++)
	{
	for(int k=i;k<=j;k++)
	{
		A=A+a[k];
		
	}	
	if(R<A)
	{
		R=A;
	}
	A=0;
	}
}
cout<<R<<endl;
}
return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	int ans;
	while (cin >> n&&n) {
		vector<int> p(n);
		for (int i = 0; i < n; i++) {
			cin >> p[i];
		}
		ans = p[0];
		for (int i = 0; i < n; i++) {
			int num = 0;
			for (int j = i; j < n; j++) {
				num += p[j];
				ans = max(ans, num);
			}
		}
		cout << ans << endl;
	}
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[5001];
int main(){
	int N,ans;
	while(cin>>N&&N){
		ans = INT_MIN;
		rep(i,N){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		rep(i,N){
			FOR(j,i,N){
				ans = max(ans,sum[j]-sum[i-1]);
			}
		}
		cout<< ans <<endl;
	}
}

C++: #include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
  

  int dataSets;

  while(true){
    vector<int> a;
    cin >> dataSets;
    if(dataSets==0){break;}
    for(int i=0;i<dataSets;i++){
      int tmpa;
      cin >> tmpa;
      a.push_back(tmpa);

    }

    int tmax=0;
    // i?????§????????§?????????????????????
    vector<int> tmpMax(dataSets + 1,0);
    tmpMax[0] = 0;
    for(int i=1;i<dataSets+1;i++){
      tmpMax[i] += tmpMax[i-1] + a[i-1];
    }

    for(int i=0;i<dataSets+1;i++){
      for(int j=i;j<dataSets;j++){
	tmax = max(tmax, tmpMax[j+1] - tmpMax[i]);
      }
    }
    
    cout << tmax << endl;
    
  }

  return 0;

}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

int n, a[5000], s, r;

int main() {
	while (true) {
		scanf("%d",&n);
		if (n==0) break;
		r = -1001001001;
		rep(i,n) scanf("%d",&a[i]);
		rep(i,n) {
			s = 0;
			for (int j = i; j < n; ++j) {
				s += a[j];
				r = max(r, s);
			}
		}
		printf("%d\n",r);
	}
}

C++: #include <iostream>

using namespace std;

int main(){
  int n;
  while(true){
    cin>>n;
    if(!n)break;
    int seq[n];
    for(int i=0;i<n;i++)
      cin>>seq[i];
    int max = 0;
    for(int i=0;i<n;i++){
      for(int j=i;j<n;j++){
	int sum = 0;
	for(int k=i;k<=j;k++)
	  sum+=seq[k];
	if(sum>max)max = sum;
      }
    }
    cout << max << endl;
  }
  return 0;
}