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>
using namespace std;

int main(){
	int n, k;
	int input[100000];
	int sun;
	int ans = 0;
	cin >> n >> k;

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

	for(int i=0; i < n-k; i++){
		sun = 0;
		for(int j=i; j < i+k; j++){
			sun += input[j];
		}
		ans = max(ans, sun);
	}
	cout << ans << endl;
}

C++: #include <iostream>
#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-2)w=max(w,c[i]+c[i+2]+c[i+1];
    cout<<w<<endl;
  }
}

C++: #include<iostream>
#include<stdlib.h>

using namespace std;

int main(){
  int n,k;
  int sum1=0 , max = 0;
  int now = 0, nextdata, next;
  int* s;
  while(1){
    sum1 = 0;
    max = 0;
    cin >>n >>k;

    if(n == 0) break;

    s = (int*)malloc(sizeof(int) * k);

    int data;
    for(int i = 0; i<k; i++){
      cin >>data;
      s[i] = data;
      sum1 += data;
    }
    max = sum1;
    now = k-1;

    for(int i = 0; i<n-k; i++){
      cin >>data;
      if(now+1 == k) {
	next = 0;
	nextdata = s[0];
      } else{
	next = now + 1;
	nextdata = s[next];
      }

      sum1 = sum1- nextdata + data;
      if( sum1 > max) max = sum1;
      now = next;
      s[now] = data;
      /*for(int j = 0; j < k; j++){
	cout << s[j]<<" ";
      }
      cout << endl;*/
    }

    cout << max << endl;
    }
  return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	
	while(1){
		int n,m;
		
		cin>>n>>m;
		
		if(n==0 && m ==0){
			break;
		}
		int input[100000];
		
		for(int i=0;i<n;i++){
			cin>>input[i];
		}
		
		int cont = m;
		
		int now = 0;
		for(int i=0;i<m;i++){
			now += input[i];
		}
		
		
		int max = now;
		for(int i=m;i<n;i++){
			now-=input[i-m];
			now+=input[i];
			
			if(now>max){
				max=now;
			}
		}
	
	cout<<max<<endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
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;
	}
	getchar();
	getchar();
	return 0;
}

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

using namespace std;

int main(){
	int n,k,sum=0,max=0;
	int a[100001];
	while(scanf("%d %d",&n,&k)){
		if(n==0&&k==0)
		break;
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(int i=0;i<n;i++){
			if(i<k)
			sum+=a[i];
			else if(i>=k){
				sum+=a[i];
				sum-=a[i-k];
			}
			if(i==k-1)
			max=sum;
			else if(i>k-1){
				max=(max<sum ? sum:max);
			}
		}
		printf("%d\n",max);
	}
}

C++: #include <cstdio>

using namespace std;

typedef unsigned long long ull;

ull max1(ull a, ull b) { return a > b ? a : b; }

int main()
{
	ull n, k; scanf("%llu %llu", &n, &k);

	ull N[100001];

	for (ull i = 1; i <= n; ++i) scanf("%llu", &N[i]);

	ull sum = 0;

	for (ull i = 1; i <= k; ++i) sum += N[i];

	for (ull i = k; i < n; ++i) sum = max1(sum, sum - N[i-k+1] + N[i+1]);

	printf("%llu\n", sum);
}

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

int sum(int S[], int begin, int end) {
    int ans = 0;
    for (int i = begin; i < end; ++i) {
        ans += S[i];
    }
    return ans;
}

int main() {

    int n, k;
    cin >> n >> k;
    int S[100000] = {0};
    for (int i = 0; i < n; ++i) {
        cin >> S[i];
    }

    int m = n - k + 1;
    int tmp = 0;
    int ans = -1000000000;
    for (int i = 0; i < m; ++i) {
        int tmp = sum(S, i, i + k);
        if (ans < tmp) ans = tmp;
    }

    cin >> n >> k;
    if (n == 0 && k == 0) cout << ans << endl;

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#define N 100000

using namespace std;

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

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

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

#define x first
#define y second


int main() {
    int n,k;
    while(cin>>n>>k){
        if(n==0 && k==0)break;
        int num[200000]={};
        rep(i,n) cin>>num[i];
        
        int now=0;
        rep(i,k){
            now+=num[i];
        }
        int maxi=-1;
        for(int i=1;i<n-k+1;i++){
            now-=num[i-1];
            now+=num[i+k-1];
            maxi=max(now,maxi);
        }
        cout<<maxi<<endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int main() {
	for(int n, k; cin >> n >> k && n && k;) {
		vector<int> arr(n);
		vector<int> sum(n);
		rep(i,n) cin >> arr[i];
		rep(i,k) sum[k-1] += arr[i];
		for(int i = k; i < n; i++) {
			sum[i] = sum[i - 1] + arr[i] - arr[i - k];
		}
		cout << *max_element(all(sum)) << endl;
	}
	return 0;
}