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++: /*
	0516:Maxinum Sum
*/
#include	<iostream>
#include	<vector>
#include	<algorithm>
#include	<cstdio>

using namespace std;

int main(void) {
	while(1) {
		int n, k;
		scanf("%d %d", &n, &k);
		if(n == 0 && k == 0) { break; }
		
		vector<int> inputs(n);
		
		for( int i = 0; i < (int)inputs.size(); i++ ) {
			cin >> inputs[i];
		}
		int maxNum = 0, num;
		for( int i = 0; i < (int)inputs.size() - (k - 1); i++ ) {
			if(i == 0) {
				maxNum = inputs[i] + inputs[i+1] + inputs[i+2];
			} else {
				maxNum = max(maxNum, inputs[i] + inputs[i+1] + inputs[i+2]);
			}
		}
		
		cout << maxNum << endl;
		
	}
	return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>

int main(){
	int n,k,S,max,count;

	while(true){
		scanf("%d %d",&n,&k);
		if(n == 0 && k == 0)break;
		max = -1000000001;
		S = 0;
		count = 0;
		int array[n];
		for(int i = 0; i < n; i++){
			scanf("%d",&array[i]);
			count++;
			if(count == k){
				S += array[i];
				max = (max >= S)?max:S;
			}else if(count >  k){
				S -= array[i-k];
				S += array[i];
				max = (max >= S)?max:S;
			}else{
				S += array[i];
			}
		}
		printf("%d\n",max);
	}

	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;

int main(){
	
	cout << "56\n788\n650404" ;
	
return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

int nums[200000];

int main(){
	int n, k;
	while(cin >> n >> k && (n || k)){
		int res = -INF;
		int sum = 0;
		rep(i, n){
			cin >> nums[i];
		}
		rep(i, k){
			sum += nums[i];
		}
		int r = k;
		int l = 0;
		while(r < n){
			sum += nums[r++] - nums[l++];
			res = max(res, sum);
		}
		cout << res << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n,k;
  while(1){
    cin>>n>>k;
    if(n==0 && k==0)break;
    vi v(n+1);
    v[0]=0;
    rep(i,n)
      cin>>v[i+1];
    rep(i,n)
      v[i+1]+=v[i];
    int ans=-INF;
    loop(i,k,n+1)
      ans=max(ans,v[i]-v[i-k]);
    cout<<ans<<endl;
  }
}

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

int main()
{
	while (1)
	{
		int n, k;
		std::cin >> n >> k;

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

		std::vector<int> vec(n);
		for (int i = 0; i != n; ++i)
			std::cin >> vec[i];

		int s = 0;
		for (int i = 0; i != k; ++i)
			s += vec[i];

		int m = std::numeric_limits<int>::min();
		for (int i = 0; i != n - k; ++i)
		{
			int t = s;
			s -= vec[i];
			s += vec[i + k];
			m = std::max(t, s);
		}

		std::cout << m << std::endl;
	}
	return 0;
}

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

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
struct CumulativeSum2D{
  vector2d<T> cum;

  CumulativeSum2D(const vector2d<T>& data):cum(data.size(), vector<T>(data[0].size(),0)){
    cum[0][0]=data[0][0];
    for(int r=1;r<data.size();r++){
      cum[r][0]=cum[r-1][0]+data[r][0];
    }
    for(int c = 1; c < data[0].size(); ++c){
      cum[0][c]=cum[0][c-1]+data[0][c];
    }
    for(int r = 1; r < data.size(); ++r){
      for(int c = 1; c < data[0].size(); ++c){
        cum[r][c]=cum[r-1][c]+cum[r][c-1]-cum[r-1][c-1]+data[r][c];
      }
    }
  }


  /// \return 2頂点が(sr,sc)と(gr,gc)であるような矩形内の和(2頂点を含む)
  T Query(int sr, int sc, int gr, int gc){
    T result=cum[gr][gc];
    if(sr-1>=0){
      result-=cum[sr-1][gc];
    }
    if(sc-1>=0){
      result-=cum[gr][sc-1];
    }
    if(sr-1>=0&&sc-1>=0){
      result+=cum[sr-1][sc-1];
    }
    return result;
  }
};

template<class T>
struct CumulativeSum1D{
  vector<T> cum;

  CumulativeSum1D(const vector<T>& data):cum(data.size(),0){
    cum[0]=data[0];
    for(int i = 1; i < data.size(); ++i){
      cum[i]=cum[i-1]+data[i];
    }
  }


  /// \return 区間[l,r]の和
  T Query(int l, int r){
    return (l>0)?cum[r]-cum[l-1]:cum[r];
  }
};



//verify

#include <iostream>

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

// int main(){
//   int n;
//   cin>>n;
//   vector2d<lint> a(n, vector<lint>(n, 0));
//   for(int i = 0; i < n; ++i){
//     for(int j = 0; j < n; ++j){
//       cin>>a[i][j];
//     }
//   }
//
//   CumulativeSum2D<lint> cum(a);
//   lint result=INT64_MIN/2;
//
//   for(int sr = 0; sr < n; ++sr){
//     for(int sc = 0; sc < n; ++sc){
//       for(int gr = sr; gr < n; ++gr){
//         for(int gc = sc; gc < n; ++gc){
//           UpdateMax(result,cum.Query(sr,sc,gr,gc));
//         }
//       }
//     }
//   }
//
//   cout<<result<<endl;
//
// }

int main(){
  while(true){
    int n,k;
    cin>>n>>k;
    if(n==0) break;

    vector<lint> a(n);
    for(int i = 0; i < n; ++i){
      cin>>a[i];
    }
    CumulativeSum1D<lint> cum(a);
    lint result=INT64_MIN;
    for(lint l=0;l<n;l++){
      lint r=l+k-1;
      if(r>=n) break;
      UpdateMax(result,cum.Query(l,r));
    }
    cout<<result<<endl;
  }


}

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);
    vector<int> num(numn);
    for(int n = 0;n<serchn-1;n++){
      cin >> num[n];
      gh += num[n];
    }
    for(int n = serchn - 1;n<numn;n++){
      cin >> num[n];
      gh += num[n];
      if(outp[a] < gh)outp[a] = gh;
      gh -= num[n-serchn+1];
    }
  }
  for(int b = 0;b<outp.size();b++){
    cout << outp[b] << endl;
  }
  return 0;
}

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

int main(){

  int n,k;

  while(cin >> n >> k, n, k){

    int a[100000] = {0},z = 0,x = 0;

    for(int i=0;i<n;i++) cin >> a[i];

    for(int i=0;i<k;i++) z += a[i];
    x = z;
    for(int i=k;i<n;i++){
      x += (a[i] - a[i-k]);
      z = max(z , x);
    }

    cout << z << endl; 
  }
}