#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;

//E
int main() {
	ll N;
	scanf("%lld", &N);
	ll K;
	scanf("%lld", &K);
	vector<ll> A(N);
	for (ll i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
	}

	for (ll i = 0; i < N; i++) {
		A[i]--;
	}

	vector<ll> sum(N + 1, 0);
	sum[0] = 0;
	for (ll i = 1; i <= N; i++) {
		sum[i] = (sum[i - 1] + A[i - 1]) % K;
	}

	ll result = 0;
	ll iBack = 0;
	map<ll, ll> mp;
	mp[0] = 1;
	for (ll iFront = 1; iFront <= N; iFront++) {

		ll nextBack = max(0ll, iFront - (K - 1));
		if (iBack != nextBack) {
			mp[sum[iBack]]--;
			iBack = nextBack;
		}

		result += mp[sum[iFront]];

		mp[sum[iFront]]++;
	}

	printf("%lld\n", result);
}

//D
/*
struct LLPair {
	int a = 0;
	int b = 0;
	LLPair() {}
	LLPair(int a, int b) {
		this->a = a;
		this->b = b;
	}
};

int main() {
	int N;
	scanf("%d", &N);
	vector<LLPair> e(N - 1);
	for (int i = 0; i < N - 1; i++) {
		scanf("%d %d", &e[i].a, &e[i].b);
		e[i].a--;
		e[i].b--;
	}

	vector<map<int, int>> mp(N, map<int, int>()); //node[N] ���� node[N][next]�ւ̃G�b�W��index 

	vector<vector<int>> graph(N, vector<int>(0));
	for (int i = 0; i < N - 1; i++) {
		graph[e[i].a].push_back(e[i].b);
		graph[e[i].b].push_back(e[i].a);
		mp[e[i].a][e[i].b] = i;
		mp[e[i].b][e[i].a] = i;
	}

	vector<int> result(N - 1);
	int maxColor = 0;

	queue<LLPair> q;
	q.push(LLPair(0, -1)); //node:0 �e��color:-1

	vector<bool> visited(N, false);

	while (q.empty() == false) {
		LLPair node = q.front();
		q.pop();
		visited[node.a] = true;

		int color = 1;
		for (auto next : graph[node.a]) { 
			if (visited[next] == true) {
				//�e
				continue;
			}

			if (node.b == color) {
				//�e-�c����Ƃ͈Ⴄ�F��
				color++;
			}

			q.push(LLPair(next, color));
			maxColor = max(maxColor, color);
			result[mp[node.a][next]] = color;

			color++;
		}
	}

	printf("%d\n", maxColor);
	for (auto val : result) {
		printf("%d\n", val);
	}
}
*/

//C
/*
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

ll A;
ll B;
ll X;

//2���T���̑ΏۂƂȂ�֐�(�P������)
ll BinarySearchFunc(ll x) {
	return A * x + B * GetDigit(x);
}

//2���T���̃e���v���[�g
ll BinarySearch(ll left, ll right, ll key) {
	while (right != left) {
		ll mid = (right + left + 1) / 2;
		ll val = BinarySearchFunc(mid);

		if (val > key) { //���̏�������K�v�ɉ����ĕς���
			right = mid - 1;
		}
		else {
			left = mid;
		}
	}
	return right;
}

int main() {
	scanf("%lld", &A);
	scanf("%lld", &B);
	scanf("%lld", &X);

	ll result;

	if (BinarySearchFunc(1000000000) <= X) {
		result = 1000000000;
	}
	else if(BinarySearchFunc(1) > X) {
		result = 0;
	}
	else {
		result = BinarySearch(0, 1000000000, X);
	}

	printf("%lld\n", result);
}
*/

//B
/*
int main() {
	ll N;
	scanf("%lld", &N);
	char S[101010];
	scanf("%s", S);
	ll len = strlen(S);

	for (ll i = 0; i < len; i++) {
		char c = S[i] + N;
		if (c > 'Z') {
			c -= 26;
		}

		S[i] = c;
	}

	printf("%s\n", S);
}
*/

//A
/*
int main() {
	string arr[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
	
	string s;
	cin >> s;

	ll result = 0;

	for (ll i = 0; i < 7; i++) {
		if (s == arr[i]) {
			result = 7 - i;
			break;
		}
	}

	printf("%lld\n", result);
}
*/


Measured memory_bytes: 15872