Go: package main

import "fmt"

func main() {

	for true {
		var n, k int
		fmt.Scan(&n, &k)

		if n == 0 && k == 0 {
			return
		}
		
		a := make([]int, n)
		ans := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			if i == 0 {
				ans[i] = a[i]
			} else {
				ans[i] = ans[i-1] + a[i]
			}
		}
		max := 0
		for i := k; i < n; i++ {
			t := ans[i] - ans[i-k]
			if max < t {
				max = t
			}
		}
		fmt.Println(max)
	}
}

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


main() {
  while(1) {
    int n, k;
    cin >> n >> k;
    if(n == 0 && k == 0) break;
    int buf[k];
    int pb = 0;
    fill_n(buf, k, 0);
    int maxS = -INF;
    int sum = 0;
    for(int i = 0; i < n; i++) {
      sum -= buf[pb];
      cin >> buf[pb];
      sum += buf[pb];
      pb = (pb+1)%k;
      if(i+1 < k) continue;
      if(maxS == -INF || sum > maxS) maxS = sum;
    }
    cout << maxS << endl;
  }
}

C++: #include <stdio.h>
int RB[100005],ans;
int main() {int N,K,i,j=0;while (1) {scanf("%d %d",&N,&K);if (!N || N==EOF) return 0;ans=-1000000007;for (i=0,K--;i<K;i++) scanf("%d",&RB[i]),j+=RB[i];for (i=K;i<N;i++) scanf("%d",&RB[i]),j+=RB[i],(ans=(ans>j)?ans:j),j-=RB[i-K]; printf("%d\n",ans);}}

C++: #include <iostream>
using namespace std;
int main(){
  int n,m;
  int k[100001];
  while( cin >> n >> m , n+m ){
    int sum = 0;
    for(int i = 0 ; i < n ; i++ )cin >> k[i];
    for(int i = 0 ; i < m ; i++ )sum+=k[i]; 

    int mx = 0;

    for(int i = 0 ; m < n ; m++,i++){
      sum += k[m]-k[i];
      mx = max(mx,sum);
    }
    cout << mx << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a){
    int c[a],w=0;
    r(i,a)cin>>c[i];
    r(i,a-b){
      int cc=0;
      for(int j=i;j<i+b;j++)cc+=c[j];
      w=max(w,cc);
    }
    cout<<w<<endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 1000000009;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ int t, d; };

int main()
{
	int n, k; cin >> n >> k;
	vector<LL> sums(n);
	rep(i, n)
	{
		cin >> sums[i];
		if (i != 0)
			sums[i] += sums[i - 1];
	}
	LL ans = -10000000000;
	ans = *max_element(sums.begin(), sums.begin() + k);
	for (int i = 1; i + k < n; i++)
	{
		ans = max(ans, sums[i + k - 1] - sums[i - 1]);
	}
	cout << ans << endl;
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,k,sum=0,num,box[10000],ans=0;
    while(1){
    cin>>n>>k;
    if(n==0&&k==0)break;
    for(int i=0;i<n;i++){
        cin>>num;
            if(i<k){
            sum+=num;
            box[i]=num;
        }
        else if(i>=k){
            if(sum-box[0]+num>ans)ans=sum-box[0]+num;
            sum+=num-box[0];
            for(int j=0;j<k;j++){
                if(j==k-1){
                    box[j]=num;
                }
                else box[j]=box[j+1];
            }
        }
    }
    cout<<ans<<endl;
    }
}

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

int main(){
    int n,k;
    
    while(1){
        cin >> n >> k;
        int N[n],sum[n-k+1];
        if(n==0 && k==0) break;
        for(int i=0; i<n-k+1; i++){
            sum[i] = 0;
        }
        
        for(int i=0; i<n; i++){
            cin >> N[i];
        }
        for(int i=0; i<=n-k; i++){
            for(int j=0; j<k; j++){
                sum[i] += N[i+j];
            }
        }
        int max = 0;
        for(int i=0; i<n; i++){
            if(max < sum[i]){
                max = sum[i];
            }
        }
        cout << max << endl;
    }
}

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

using namespace std;

int main( void )
{
	int n, k, input[100000];
	while(cin >> n >> k, n | k) {
		int sum = 0;
		for(int i=0; i < n; ++i) {
			cin >> input[i];
			if(i < k) sum += input[i];
		}
		int i, j, ans = sum;
		i = 0; j = k-1;
		while(j < n-1) {
			sum -= input[i++];
			sum += input[++j];
			ans = max(ans, sum);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int num[100100];
int main(){
int n,m;
int ans=0;
while(1){
         for(int i=0;i<100100;i++)num[i]=0;
         cin>>n>>m;
         if(n==0&&m==0)break;
         for(int i=0;i<n;i++) cin>>num[i];
         for(int i=0;i<m-n;i++){
              int min=num[i]+num[i+1]+num[i+2];
              if(ans<min)ans=0;
         }
         count<<ans<<endl;
         ans=0;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	long long n,k;
	while(1){
		cin>>n>>k;
		if(!n && !k)break;
		vector<long long> sum;
		long long num[n];
		rep(i,n)cin>>num[i];
		rep(i,n-k+1){
			long long alt=0;
			loop(j,i,i+k/2+1){
				alt+=num[j];
				if(j!=(i+k-1-j))alt+=num[i+k-1-j];
			}
			sum.push_back(alt);
		}
		sort(sum.begin(),sum.end());
		cout<<sum[sum.size()-1]<<endl;
	}
	return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	while(1){
	int k,n,s=0,cn=0;
	cin>>k>>n;
	if(k==0 && n==0){
		break;
	}
	int dat[n+10];
	for(int i=0;i<k;i++){
		cin>>dat[i];
	}
	for(int j=0;j<k-n+1;j++){
		cn=0;
		for(int k=0;k<n;k++){
			cn+=dat[j+k];
		}
		s=max(s,cn);
	}
	cout<<s<<endl;
	}
	return 0;
}

C++: #include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<set>
#include<string>
using namespace std;
int n,k,ma;
int main(){
    for(;;){
        int num[100001]={0},all=0;
        cin>>n>>k;
        if(n==0&&k==0)break;
        for(int i=0;i<n;i++){
            cin>>num[i];
        }
        for(int i=0;i<n-k;i++){
            if(i==0){
                for(int j=0;j<k;j++){
                    all+=num[i+j];
                    ma=all;
                }
                continue;
            }
        all=all-num[i-1]+num[i+k-1];
        ma=max(ma,all);
        }
        cout<<ma<<endl;
    }
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
using namespace std;
const int INF = 1 << 30;
int main(){
	int n, k;
	for (cin >> n >> k, n) {
		vector<int> a(n);
		for (int &x : a)cin >> x;
		int pos = 0;
		int sum = 0;
		for (int i = 0; i < k; i++) {
			sum += a[i];
		}
		int max = sum;
		for (int i = 0; i < n - k; i++) {
			sum += a[i + k] - a[i];
			max = std::max(max, sum);
		}
		cout << max << endl;
	}
	return 0;
}

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

int main()
{
    int n, k, a[100000];

    while( cin >> n >> k )
    {
        if( n == 0 && k == 0 )
            break;
            
        for( int i = 0; i < n; i++ )
            cin >> a[i];
        
        int max = 0;
        for( int i = 0; i <= n - k; i++ )
        {
            int sum = 0;
            for( int j = i; j < i + k; j++ )
                sum += a[j];
            if( max < sum )
                max = sum;
        }

        cout << max << endl;
    }

    return 0;
}