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

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let (acc, _, _) = Array.fold_left (fun (acc, offset, map) a ->
    let offset = offset + a in
    let map = IntMap.add ((a + m - offset) mod m) (1 + try IntMap.find ((a + m - offset) mod m) map with Not_found -> 0) map in
    acc + (try IntMap.find ((m - offset) mod m) map with Not_found -> 0), offset, map) (0, 0, IntMap.empty) as_ in
  Printf.printf "%d\n" acc
