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----------------------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>

//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1 << 25
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << "\n";
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
//const------------------------------------------------------------------------------------------------------------------------
const double EPS = 1e-10;
const double PI = acos( -1.0 );

//global-----------------------------------------------------------------------------------------------------------------------
int n, m, k;
VI a, b, c;
#define mod 1000000007
//function-------------------------------------------------------------------------------------------------------------------- 
int main() {
	while ( true ) {
		scanf( "%d %d", &n, &m );
		if ( !n && !m ) {
			return 0;
		}
		rep( i, n ) {
			scanf( "%d", &k );
			a.push_back( k );
		}
		int mx = 0;
		rep( i, n - m + 1 ) {
			int d = 0;
			rep( j, m ) {
				d += a[ i + j ];
			}
			mx = max( mx, d );
		}
		printf( "%d\n", mx );
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int n, k, a[112345];
int ans;

int main()
{
	while (true)
	{
		memset(a, 0, sizeof(a));
		ans = -1;
		in >> n >> k;
		rep(i, n) { in >> a[i + 1]; }
		if (n == 0 && k == 0) { break; }

		rep(i, n) { a[i + 1] += a[i]; }
		rep(i, n - k + 1)
		{
			auto res = a[i + k] - a[i];
			ans = std::max(ans, res);
		}

		out << ans << std::endl;
	}
	return 0;
}

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

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

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

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

int main()
{
	while (1)
	{
		int a = 0, b = 0;
		double c = -1000;
		double as = 0;
		cin >> a;
		cin >> b;
		if (a == 0 && b == 0)
		{
			break;
		}
		vector<double> size;
		for (int i = 0; i < a; i++)
		{
			int w;
			cin >> w;
			size.push_back(w);
		}
		for (int i = 0; i < a - 2; i++)
		{
			
			for (int ii = 0; ii < b; ii++)
			{
				as += size[i + ii];
			}
			size.push_back(as);
		}
		for (int i = 0; i < a - 2; i++)
		{
			if (c < size[i + a])
			{
				c = size[i + a];
			}
		}
		cout << c << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k;
    long long int a;
    const long long int INF=1LL<<60;
    while (cin>>n>>k) {
        if (n==0&&k==0) {
            break;
        } else {
            std::deque<long long int> deq;
            for (int i=0;i<n;i++) {
                cin>>a;
                deq.emplace_back(a);
            }
            std::deque<long long int> s(n+1,0);
            long long int ans=-INF;
            for (int i=0;i<n;i++) {
                s[i+1]=s[i]+deq[i];
            }
            for (int i=0;i<=n-k;i++) {
                ans=max(ans,s[k+i]-s[i]);
            }
            cout<<ans<<endl;
        }
    }
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
	int n,k;
	while(1){
		scanf("%d %d",&n,&k);
		if(n==0)	return 0;
		int a[n];
		for(int i=0;i<n;i++)	scanf("%d",&a[i]);
		ll bgs=0,temp=0;
		for(int i=0;i<k;i++)	temp+=a[i];
		bgs=temp;
		for(int i=1;i<=n-k;i++){
			temp=temp-a[i-1]+a[i+k-1];
			bgs=max(bgs,temp);
		}
		printf("%lld\n",bgs);
	}
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,k;
	while(1){
		int a[100000];
		cin>>n>>k;
		if(n==0&&k==0)break;
		int f=0;
		int max=0,sum;
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;i<n;i++){
			sum=0;
			for(int j=0;j<k;j++){
				if(i+j>=n){
					f=1;
					break;
				}
				sum+=a[i+j];
			}
			if(f==1)break;
			if(max<sum){
				max=sum;
			}
		}
		cout<<max<<endl;
	}
}

C++: #include <iostream>
using namespace std;
int main() {
	int n, k, a[100005] = { 0 }, sum[100005] = { 0 }, m = -299999;
	cin >> n >> k;
	if (n == 0 && k == 0) return 0;
	for (int i = 0; i < n; i++) cin >> a[i];
	sum[0] = a[0] + a[1] + a[2];
	for (int i = 1; i < n-2; i++) {
		sum[i] = sum[i - 1] + a[i + 2] - a[i - 1];
	}
	for (int i = 0; i < n - 2; i++) {
		if (m < sum[i]) {
			m = sum[i];
		}
	}
	cout << m << endl;
}

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

int main(){
  long long n,k;

  while(1) {
    ans=-1000000000;
    cin>>n>>k;
    if(n == 0 and k == 0) break;
    long long a[n];for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<n-k+1;i++){
      long long temp=0;
      for(int j=i;j<i+k;j++){
        temp+=a[j];
      }
      ans=max(temp,ans);
    }
    cout<<ans<<endl;
  }
}

C++: #include<iostream>
main(){for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M)){for(i=s=0;i<n;i++<k&&(M=s+=a[i-1]))std::cin>>a[i];for(i=k;i<n;M<s&&(M=s))s+=a[i]-a[i++-k];}}

C++: #include<cstdio>
#include<cstdlib>
using namespace std;
#define MAX_N 100000

unsigned long long int n, k, i, j, a[MAX_N], max = 0, f;

int sort(const void *a, const void *b){
  return *(int*)b - *(int*)a;
}

int main(){
  while(1){
    scanf("%lld %lld", &n, &k);
    if(n == 0 && k == 0) break;
    max = 0;
    for(i = 0; i < n; i++) scanf("%lld", &a[i]);
    for(i = 0; i < k; i++) max += a[i];
    f = max;
    for(i = 0; i < n - k; i++){
      f -= a[i];
      f += a[i + k];
      if(f > max) max = f;
    }
    printf("%lld\n", max);
  }
  return 0;
}