import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, K = in.next().toInt
  val A = new Array[Long](N+1)
  for (i <- 1 to N) {
    A(i) = in.next().toLong
  }

  // 
  for (i <- 1 to N) {
    A(i) += A(i-1)
    A(i) %= K
  }

  for (i <- 1 to N) {
    A(i) += K - (i % K)
    A(i) %= K
  }

  val hash = Map[Long, Int]()
  if (K > 1)
    hash += (0L -> 1)
  var ans = 0L
  for (i <- 1 to N) {
    val now = A(i)

    if (hash.contains(now))
      ans += hash(now)

    if (hash.contains(now))
      hash(now) += 1
    else
      hash += (now -> 1)

    if (i >= K-1) {
      hash(A(i-(K-1))) -= 1
    }
  }

  println(ans)
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
