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

int main()
{
	int64_t n, k;
	cin >> n >> k;
	vector<int64_t> as(n);
	for (auto &&a : as)
	{
		cin >> a;
	}

	for (auto &&a : as)
	{
		a--;
	}

	vector<int64_t> sum(n + 1, 0);
	for (int i = 0; i < n; i++)
	{
		sum[i + 1] = sum[i] + as[i];
	}

	int64_t ans = 0;

	map<int64_t, int64_t> mp;

	for (int i = 0; i <= n; i++)
	{
		if (k <= i)
		{
			mp[sum[i - k] % k]--;
		}
		ans += mp[sum[i] % k]++;
	}

	cout << ans << endl;

	return 0;
}