import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()

    val a = LongArray(n) { sc.nextLong() }
    val sums = LongArray(n+1)
    for (i in 0 until n) sums[i+1] = sums[i] + a[i] - 1

    var ans = 0L
    val mp = mutableMapOf(0L to 0L)

    for (i in 0..n) {
	if (i >= k) {
	    val tmp1 = mp[sums[i-k]%k]!!
	    mp[sums[i-k]%k] = tmp1 - 1
	}

	val tmp = mp[sums[i]%k] ?: 0
	ans += tmp
	mp[sums[i]%k] = tmp + 1
    }
    println(ans);
}
