import Foundation
class Scanner {
    static func readInt() -> Int {
        return Int(readLine()!)!
    }
    
    static func readIntArr() -> [Int] {
        return readLine()!.split(separator: " ").map { Int($0)! }
    }
    
    static func readM(_ n: Int) -> [[Int]] {
        var res = [[Int]]()
        for _ in 0..<n {
            res.append(readIntArr())
        }
        return res
    }
    
    static func readUknownIntMat() -> [[Int]] {
        var res = [[Int]]()
        while let line = readLine() {
            res.append(line.split(separator: " ").map { Int($0)! })
        }
        return res
    }
}

let nk = Scanner.readIntArr()
let arr = Scanner.readIntArr()

func solve(_ arr: [Int], _ k: Int) -> Int {
  var ps = arr
  for i in stride(from: 1, to: arr.count, by: 1) {
    ps[i] += ps[i-1]
  }
  var map = [Int: Set<Int>]()
  map[0] = Set([-1])
  var res = 0
  for i in stride(from: 0, to: min(arr.count, k), by: 1) {
    let rem = ps[i]%k
    for (key,v) in map {
      let length = (rem-key)%k < 0 ? (rem-key)%k + k : (rem-key)%k
      let startIndex = i-length
      if v.contains(startIndex) {
        res += 1
      }
    }
    map[ps[i]%k, default: Set<Int>()].insert(i)
  }
  var left = 0, right = k
  var first = map[0]!
  first.remove(-1)
  map[0] = first
  while right < arr.count {
    let leftRem = ps[left]%k
    var ls = map[leftRem]!
    ls.remove(left)
    map[leftRem] = ls
    let rightRem = ps[right]%k
    for (key,v) in map {
      let length = (rightRem-key)%k < 0 ? (rightRem-key)%k + k : (rightRem-key)%k
      if v.contains(right-length) {
        res += 1
      }
    }
    map[rightRem, default: Set<Int>()].insert(right)
    right += 1
  }
  return res
}

//let date = Date()
//print(date)
print(solve(arr, nk[1]))
//print(Date().timeIntervalSince(date))
