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

const int N = (int) 2e5 + 5;

int n, k;
long long a[N], s[N];
map <long long, long long> remain;

int main() {
	ios_base :: sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		s[i] = s[i - 1] + a[i];
	}
	remain[s[0] - 0]++;
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i - k >= 0) remain[(s[i - k] - (i - k)) % k]--;
		ans += remain[(s[i] - i) % k]++;
	}
	cout << ans << "\n";
	return 0;
}