#include <bits/stdc++.h>
typedef unsigned long long ull;
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector<ull> A(N), S(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[i]--;
		S[i + 1] = (S[i] + A[i] + K) % K;
	}

	map<int, int> mp;
	ull ans = 0;
	for (int i = 0; i <= N; i++) {
		if (i - K >= 0) mp[S[i - K]]--;
		ans += mp[S[i]];
		mp[S[i]]++;

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