module Mi = Map.Make(struct type t = int let compare = (-) end)
let rec fix f x = f (fix f) x
let () =
  Scanf.scanf "%d %d" @@ fun n k ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" pred) in
  (1, Mi.singleton 0 0, Mi.singleton 0 1, 0) |> fix (fun f (i, sa, cm, ans) ->
    if i > n then ans else
    let si = (Mi.find (i-1) sa + a.(i-1)) mod k in
    let cm =
      if i < k then cm else
        let idx = Mi.find (i-k) sa in
        Mi.add idx (Mi.find idx cm - 1) cm in
    let ans = ans + try Mi.find si cm with _ -> 0 in
    let sa = Mi.add i si sa in
    let cm = Mi.add si (1 + try Mi.find si cm with _ -> 0) cm in
    f (i+1, sa, cm, ans))
  |> Printf.printf "%d\n"
