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

Scanf.scanf "%d %d" (fun n m ->

    let rec loop i cur map =
        if i = n then map else
            let a = Scanf.scanf " %d" (fun a -> a) in
            let cur = (cur + a) mod m in
            let map = M.add cur (1 + try M.find cur map with _ -> 0) map in
            loop (i + 1) cur map
    in
    let map = loop 0 0 (M.add 0 1 M.empty) in
    M.fold (fun _ v acc -> acc + v * (v - 1) / 2) map 0 |> Printf.printf "%d\n"
)