fun main(args: Array<String>) {
    val (_, k) = readLine()!!.split(" ").map { it.toInt() }
    val aa = readLine()!!.split(" ").map { it.toInt() }
    val sum = mutableListOf(0)
    for (a in aa) {
        sum.add(((sum.last() + a) % k + k - 1) % k)
    }
    var indices = mutableMapOf<Int, MutableList<Int>>()
    for (i in 0 until sum.size) {
        if (!indices.containsKey(sum[i])) {
            indices[sum[i]] = mutableListOf()
        }
        indices[sum[i]]!!.add(i)
    }
    var ret = 0L
    for (l in indices.values) {
        var s = 0
        var e = 0
        while (s < l.size) {
            while (e < l.size) {
                if (l[e] - l[s] >= k) {
                    break
                }
                e += 1
            }
            ret += e - s - 1
            s += 1
        }
    }
    println(ret)
}
