Go: package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	parseProblem(os.Stdin)
}

func parseProblem(r io.Reader) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	for true {
		n, k := scanInt(sc), scanInt(sc)
		if n == 0 && k == 0 {
			break
		}
		sum := make([]int, n+2)
		for i := 2; i <= n+1; i++ {
			sum[i] = sum[i-1] + scanInt(sc)
		}
		max := math.MinInt32
		for i := 1; i+k <= n+1; i++ {
			if v := sum[i+k] - sum[i]; max < v {
				max = v
			}
		}
		fmt.Println(max)
	}
	return
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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;
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;



int main() {

	while (true) {
		int n, k, ans = 0;
		int a[100002], b[100002];
		cin >> n >> k;
		if (n == 0 && k == 0)break;
		rep(i, n)cin >> a[i];
		b[0] = 0;
		REP(i, 1, n + 1)b[i] = b[i - 1] + a[i - 1];

		REP(i, k, n + 1)ans = max(ans, b[i] - b[i - k]);

		cout << ans << endl;
	}

	return 0;
}

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

int main(void)
{
  int n, k;
  int max;
  int sum;
  int* num_sequence;
  while (true)
  {
    cin >> n >> k;
    if ( n == 0 && k == 0 ) break;

    //int* num_sequence = new int[n];
    num_sequence = new int[n];
    for (int i = 0; i < n; i++)
    {
      cin >> num_sequence[i];
    }

    max = -999999;
    for (int j = 0; j < n-k+1; j++)
    {
      sum = 0;
      for (int i = 0; i < k; i++)
      {
        sum += num_sequence[i+j];
      }
      if ( sum > max ) max = sum;
    }

    cout << max << endl;

    delete[] num_sequence;
  }
  return 0;
}

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

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    int n, k;
    int ans = -50000;
    int sum = 0;
    int lastNum;
    vi series;
    cin >> n >> k;

    for(int i=0; i < n; i++){
        int m;
        cin >> m;
        series.push_back(m);

        if(i < k-1) sum += m;
        else {
            sum += m-series[i-k];
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;

}

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
ll n,k;
ll val[100000];
ll sum[100000];
int main()
{while(1){
	memset(val,0,sizeof(val));
	memset(sum,0,sizeof(sum));
	cin>>n>>k;
	if(!n) return 0;
	for(ll i=0;i<n;i++) cin>>val[i];
	for(ll i=0;i<k;i++) sum[0]+=val[i];
	ll ans=sum[0];
	for(ll i=1;i<=n-k;i++){
		sum[i]=sum[i-1]-val[i-1]+val[i+k-1];
		ans=max(ans,sum[i]);
	}
	cout<<ans<<endl;
}}

C++: #include <cstdio>

using namespace std;

int n,k,s,smax;
int a[100000];
int s1,s2;

int main(){
	scanf("%d %d\n",&n,&k);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int j=0;j<k;j++) s1+=a[j];
	smax=s1;
	for(int l=0;l<n-k;l++){
		s2=s1-a[l]+a[l+k];//最後の処理をどうするか
		if(s2>smax) smax=s2;
		s1=s2;
	}
		printf("%d\n",smax);
	return 0;
}

C++: #include <iostream>
#define MAX(a,b) (((a)>(b))?(a):(b))
using namespace std;

int main(void){
	int n,k;
	int a[100000];
	int sum=0;
	int m=0;
	while (cin>>n>>k,n||k) {
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<k;i++)sum+=a[i];
		m=sum;
		for(int i=k+1;i<n;i++){
			sum-=a[i-k-1];
			sum+=a[k];
			m=MAX(sum,m);
		}
		cout<<m<<endl;
	}
	return 0;
}

C++: //aoj0516 in binary indexed tree

#include<bits/stdc++.h>
using namespace std;

int n, k;
int a[100010];
int ans = 0;

struct bittree
{
  int tree[100010];

  void reset()
  {
    memset(tree, 0, sizeof tree);
  }
  
  void add(int where, int val)
  {
    for(int i = where; i <= n; i += i & -i){
      tree[i] += val;
    }
  }

  int sum(int where)
  {
    int ret = 0;
    
    for(int i = where; i >= 1; i -= i & -i){
      ret += tree[i];
    }

    return ret;
  }
} tr;

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

    tr.reset();
    
    for(int i = 1; i <= n; i++){
      tr.add(i, a[i]);
    }

    for(int i = 1; i <= n - k + 1; i++){
      ans = max(ans, tr.sum(i + k - 1) - tr.sum(i - 1));
    }

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

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++){
			if (data[i] < 0) data[i] *= 2;
		}
		
		for (int i = 0; i < n - 1; i++){
			data[i + 1] += data[i];
		}
		int max = 0;
		for (int i = 0; i <= (n - k); i++){
			int tmp = data[i + k] - data[i];
//			for (int j = i; j < (i + k); j++){
//				if (data[j] < 0) tmp += data[j];
//			}
			max = MAX(max, tmp);
		}
		
		/*
		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 <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    int n, k;
    int ans = -50000;
    vi series;
    cin >> n >> k;
    for(int i=0; i < n; i++){
        int m;
        cin >> m;
        series.push_back(m);
        int sum = 0;
        if(2 < i){
            for(int j=0; j < 3; j++){
                sum += series[i-j];
            }
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;

}