import java.util.*

fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map{it.toLong()}
    val A = readLine()!!.split(" ").map{it.toLong()}

    val B = Array(N.toInt() + 1) { 0L }
    val mp = TreeMap<Long, ArrayList<Int>>()

    mp[0] = ArrayList()
    mp[0]!!.add(0)
    for (i in A.indices) {
        B[i + 1] = (B[i] + A[i]) % K

        val b = ((i + 1) - B[i + 1] + K) % K

        if (mp[b] == null) {
            mp[b] = ArrayList()
            mp[b]!!.add(i + 1)
        } else {
            mp[b]!!.add(i + 1)
        }
    }

    var res = 0L

    for (list in mp.values) {
        val Q = ArrayDeque<Int>()

        for (v in list) {
            while (Q.isNotEmpty() && v - Q.first >= K) {
                Q.removeFirst()
            }
            res += Q.size
            Q.addLast(v)
        }
    }

    println(res)
}
