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 <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


const int MAX = 200000;
const ll INF = 1LL<<61;

int n, k;
long long a[MAX];

int main() {
    while (cin >> n >> k) {
        if (n == 0) break;
        memset(a, 0, sizeof(a));
        for (int i = 0; i < n; ++i) cin >> a[i+1];
        for (int i = 0; i <= n; ++i) a[i+1] += a[i];
        
        long long res = -INF;
        for (int i = 0; i + k <= n; ++i) {
            chmax(res, a[i+k] - a[i]);
        }
        cout << res << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
	while (1){
		int n, k;
		int b[100000] = {};
		scanf("%d%d", &n, &k);
		if (n == 0 && k == 0)return 0;
		int base = 0;
		for (int i = 0; i < k; i++){
			int a;
			scanf("%d", &a);
			b[i] = a;
			base += a;
		}
		int sa = 0;
		for (int i = k; i < n; i++){
			int c;
			scanf("%d", &c);
			sa = max(sa, c - b[0]);
		}
		printf("%d\n", sa + base);
	}
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int n,k;
	cin >> n >> k;
	if(n == 0 && k == 0) break;
	ll a[100001];
	REP(i,n){
	    cin >> a[i];
	}
	REP(i,n-1){
	    a[i+1] += a[i];
	}
	ll ans = -1000000000000000;
	FOR(i,k,n){
	    ans = max(ans,a[i] - a[i-k]);
	}
	cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

while(1){
    int n, k;
    cin>> n>> k;
    if(n==0&&k==0) break;
    int a[n];
    for(int i=0; i<n; i++){
        cin>> a[i];
    }

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

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

C++: #include <iostream>

using namespace std;

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

    if ((k == 0 && n == 0)) {
      return 0;
    }
    int a[100000];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    int s = 0;
    for (int i = 0; i < k; i++) {
      s += a[i];
    }
    for (int i = 0; i + k < n; i++) {
      int t = s + a[k + i] - a[i];
      if (t > s) {
        s = t;
      }
    }
    cout << ' '<<  s << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cmath>
#define INF 2000000000
using namespace std;

int main(){
	int n,k,a[100001];
	while(1){
		a[0] = 0;
		cin >> n >> k;
		if(n == 0 && k == 0) break;
		for(int i = 0;i < n;i++) {
			int t;
			cin >> t;
			a[i + 1] = a[i] + t;
		}
		int ma = -INF;
		for(int i = 0;i <= n - k;i++){
			ma = max(ma,a[i + k] - a[i]);
		}
		cout << ma << endl;
	}
	return 0;	
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long m[100000][2];
int main(){
while(1){
long long n,k,i,j,x=0;
cin>>n>>k;
if(n==0&&k==0)break;
for(i=0;i<n;i++)cin>>m[i][0];
m[0][1]=m[0][0];
for(i=1;i<n;i++){
m[i][1]=m[i-1][1]+m[i][0];
}
for(i=k-1;i<n;i++){
x=max(x,m[i][1]-m[i-k][1]);
}
cout<<x<<endl;
return 0;
}
}

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

using namespace std;

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

C++: #include <cstdio>

#define MAX(x, y) (x < y) ? y : x

int main(void)
{
	int n, k;
	int data[100000] = {0};
	
	while (1){
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0) break;
		for (int i = 0; i < n; i++){
			scanf("%d", &data[i]);
		}
		
		for (int i = 0; i < n - 1; i++){
			data[i + 1] += data[i];
		}
		for (int i = 0; i < n; i++){
//			printf("%2d ", data[i]);
		}
		int max = 0;
		for (int i = 0; i <= (n - k); i++){
			if (!(i == 0)) max = MAX(max, data[i + k - 1] - data[i - 1]);
			else max = data[i + k - 1];
		}
//		printf("\n");
		/*
		int max = 0, tmp;
		for (int i = 0; i <= (n - k); i++){
			tmp = 0;
			for (int j = i; j < (i + k); j++){
				tmp += data[j];
			}
			max = MAX(max, tmp);
		}*/
		
		printf("%d\n", max);
	}
	
	return (0);
}

C++: #include<stdio.h>

int main(void){
	int i,n,k,sum,max;
	int N[15000];

	while(0==0){
		scanf("%d %d",&n,&k);
		sum=0;
		if(n==0 && k==0) break;

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

		for(i=0;i<k;i++)
		    sum+=N[i];//初期値
		
		max=sum;

		for(i=k;i<n;i++){
			sum+=N[i];
			sum-=N[i-k];
			if(sum>max)max=sum;
		}

		printf("%d\n",max);
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-10;
const vi emp;

int n,k;
vi a;

int main(){
	while(1){
		cin>>n>>k;
		if(!n&&!k) break;
		a=vi(n);
		ll sum=0,ans;
		for(auto i=a.begin();i!=a.end();i++){
			cin>>*i;
			if(i<a.begin()+k) sum+=*i;
		}
		ans=sum;
		for(auto i=a.begin()+k;i!=a.end();i++){
			sum+=*i-*(i-k);
			ans=max(ans,sum);
		}
		cout<<ans<<endl;
	}
}