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<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;
		int num[n];
		rep(i,n)cin>>num[i];
		rep(i,n-k+1){
			long long alt=0;
			loop(j,i,i+k){
				alt+=num[j];
			}
			sum.push_back(alt);
		}
		sort(sum.begin(),sum.end());
		cout<<sum[sum.size()-1]<<endl;
	}
	return 0;
}

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

int main(){
  int serchn,numn;
  int gh = 0;
  vector<int> outp;
  for(int a = 0;;a++){
    cin >> numn >> serchn;
    if(numn == 0 && serchn == 0){
      break;
    }
    outp.resize(a+1,0);
    outp[a] = 0;
    gh = 0;
    vector<int> num(numn,0);
    for(int n = 0;n<numn;n++){
      cin >> num[n];
    }
    for(int n = 0;n<serchn;n++){
      outp[a] += num[n];
    }
    gh = outp[a];
    int b = serchn;
    for(int a = 0;b<numn;a++){
      gh += num[b];
      gh -= num[a];
      if(gh > outp[a]){
        outp[a] = gh;
      }
      b += 1;
    }
  }
  for(int b = 0;b<outp.size();b++){
    cout << outp[b] << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin>>vec.at(i);
    }
    vector<int> rsw(n);
    rsw.at(0)=0;
    for(int i=1;i<n;i++){
        rsw.at(i) = rsw.at(i-1) + vec.at(i-1);
    }
    int ans =0;
    for(int i =k;i<n;i++){
        if(ans < rsw.at(i) - rsw.at(i-k)){
            ans = rsw.at(i) - rsw.at(i-k);
        }
    }
    cout << ans << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
  const char* dlm = "";
  for(const auto& x:v) os << exchange(dlm, " ") << x;
  return os;
}
int32_t main(){
  vector<int32_t> a,s;
  size_t n,k; cin>>n>>k;
  while(n!=0||k!=0){
    a.resize(n);
    for(auto&& x:a) cin>>x;
    s.resize(n+1); s[0]=0;
    for(size_t i=1; i<n+1; ++i) s[i]=s[i-1]+a[i-1];
    int32_t ret=s[k]-s[0];
    for(size_t i=1; i<n-k; ++i) ret=max(ret,s[i+k]-s[i]);
    cout<<ret<<'\n';
    cin>>n>>k;
  }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  int gomi;
  cin >> gomi >> gomi;
  int mx = 0;
  int sum = 0;
  int left = 0;
  int right = k;
  for(int i = left; i < right; i++) {
    sum += a[i];
  }
  mx = sum;
  while(right < n) {
    left++;
    right++;
    sum = sum + a[right - 1] - a[left - 1];
    mx = max(sum, mx);
  }
  cout << mx << endl;
  return 0;
}

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

int main(){
  int numn,lisn,num;
  vector<int> outp;
  int outn = 1;
  for(int l = 0;;l++){
    cin >> numn >> lisn;
    if(numn == 0 && lisn == 0)break;
    outp.resize(l+1,0);
    vector<int> lists(numn,0);
    for(int n = 0;n<numn;n++){
      cin >> num;
      lists[n] = num;
    }
    for(int k = 0;k<numn-2;k++){
      outn = lists[k] + lists[k + 1] + lists[k + 2];
      if(outp[l] < outn){
        outp[l] = outn;
      }
    }
  }
  for(int q = 0;q<outp.size();q++){
    cout << outp[q] << " ";
  }
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	while (1) {
		int a[100000];
		int n, k, sum = 0, ans = -999999;

		memset(a, 0, sizeof(a));
		cin >> n >> k;
		if (n == 0 && k == 0) break;

		REP(i, n) {
			cin >> a[i];
			sum += a[i];
			if (i >= k) sum -= a[i-k];
			ans = max(ans, sum);
		}

		cout << ans << endl;
	}
	return 0;
}

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

int main(){

  int n,k,i,j;

  while(1){

  int a[100003]={0};
  int max=0,sum[100003]={0};

    scanf("%d %d",&n,&k);

    if(n==0 && k==0){
      break;
    }

    for(i=0;i<n;i++){
      scanf("%d",&a[i]);
    }

    for(i=0;i<n;i++){
      if(i+k<=n){
      for(j=i;j<i+k;j++){
	sum[i]+=a[j];
      }
      }
      if(max<sum[i]){
	max=sum[i];
      }
      }
  
    printf("%d\n",max);

  }

  return 0;

}

C++: #include <cstdio>
int a[200000];
int main() {
    int n, k;
    while (scanf("%d %d",&n,&k)&&n!=0) {
        for (int i=0; i<n; i++) scanf("%d",&a[i]);
        int max=0;
        for (int i=0; i<k; i++) max+=a[i];
        int tmp=max;
        for (int i=0; i<n-k; i++) {
            tmp=tmp-a[i]+a[i+k];
            if (tmp>max) max=tmp;
        }
        printf("%d\n",max);
    }
    return 0;
}

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

using namespace std ;

int main()
{
	int n ;
	while( cin >> n ,n )
	{
		int m ;
		cin >> m ;
		int num[ 2 ] ;
		num[ 1 ] = 0 ;
		int ans = 0 ,cnt = 0 ;
		for( int i = 0 ; i < n ; i++ )
		{
			cin >> num[ 0 ] ;
			if( i % m )
			{
				cnt += num[ 0 ] ;
			}
			else
			{
				cnt += num[ 0 ] - num[ 1 ] ;
				num[ 1 ] = num[ 0 ] ;
				ans = max( ans ,cnt ) ;
			}
		}
		cout << ans << endl ;
	}
	return 0 ;
}

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

int main(){
  int serchn,numn;
  int gh = 0;
  vector<int> outp;
  for(int a = 0;;a++){
    cin >> numn >> serchn;
    if(numn == 0 && serchn == 0)break;
    gh = 0;
    outp.resize(a+1,0);
    vector<int> num(numn);
    for(int n = 0;n<serchn - 1;n++){
      cin >> num[n];
      gh += num[n];
    }
    for(int n = 0;n<numn - serchn + 1;n++){
      cin >> num[n+2];
      gh += num[n+2];
      if(gh > outp[a])outp[a] = gh;
      gh += (-1) * num[n];
    }
  }
  for(int b = 0;b<outp.size();b++){
    cout << outp[b] << endl;
  }
  return 0;
}

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

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

C++: #include <iostream>
#include <vector>
#include <array>
#include <set>
#include <string>
#include <numeric>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < n; i++)



int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    for(;;) {
        int n, k;
        std::cin >> n >> k;
        if (n == 0 && k == 0) break;
        std::vector<int> num(n);
        rep(i, n) std::cin >> num.at(i);

        int sum = std::accumulate(num.begin(),num.begin()+k,0);
        rep(i,n-k) sum = std::max(sum,sum-num.at(i)+num.at(k+i));

        std::cout << sum << "\n";
    }

    return 0;
}

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

long long int num[100100];

int main(){
    long long int n,m;
    long long int sum=0;
    long long int ans=0;
    while(1){
        cin>>n>>m;
        if(n==0&&m==0)break;
        for(int i=0;i<100100;i++){
            num[i]=0;
           // if(num[i+1]==0)break;
        }
        for(int i=0;i<n;i++){
            cin>>num[i];
            if(i<m)sum+=num[i];
        }
        for(int i=1;i<n;i++){
            sum=sum-num[i-1]+num[i];
            if(ans<sum)ans=sum;
        }
        cout<<ans<<endl;
        ans=0;
        sum=0;
        }
    return 0;
}