fun main(args: Array<String>) = yorukatsu14f()

fun yorukatsu14f() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val aList = readLine()!!.split(' ').map { it.toLong() - 1 }.toLongArray()

    val cSumMod = LongArray(n + 1)
    for (i in 0 until n) cSumMod[i + 1] = (cSumMod[i] + aList[i]) % k

    var answer = 0L
    val curr = mutableMapOf<Long, Long>()

    for ((index, cs) in cSumMod.withIndex()) {
        answer += curr[cs] ?: 0
        curr[cs] = (curr[cs] ?: 0) + 1
        if (index + 1 >= k)
            curr[cSumMod[index + 1 - k]] = curr[cSumMod[index + 1 - k]]!! - 1
    }

    println(answer)
}
