module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let acc = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    acc.(i + 1) <- (as_.(i) + acc.(i) + k - 1) mod k;
  done;
  let map = Array.make (n + 2) IntMap.empty in
  for i = 0 to n do
    map.(i + 1) <-
      IntMap.add acc.(i)
        (1 +
          try IntMap.find acc.(i) map.(i)
          with Not_found -> 0) map.(i)
  done;
  Printf.printf "%d\n" @@
  Array.fold_left ( + ) 0 @@
  Array.init (n + 1) @@ fun i ->
    ( try IntMap.find acc.(i) map.(i)
      with Not_found -> 0 ) -
    ( try IntMap.find acc.(i) map.(max 0 (i - k + 1))
      with Not_found -> 0 )