;; -*- coding:utf-8 -*-

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 1))
    #-swank '(optimize (speed 3) (safety 0) (debug 0))))

(defmacro print-line (obj &optional (stream '*standard-output*))
  `(prog1 (princ ,obj ,stream) (terpri ,stream)))


;; Hauptteil

(let ((buf (make-string 30 :element-type 'base-char))) ; fix me
  (defun read-vector (size &optional (in *standard-input*))
    (declare (optimize (speed 3) (safety 1)))
    (let ((dest-arr (make-array size :element-type 'fixnum))) ; fix me
      (dotimes (idx size)
        (loop for ch of-type base-char = #-swank(code-char (read-byte in nil #\space))
              #+swank (read-char in nil #\space)
              for pos from 0
              when (char= ch #\space)
                do (loop-finish)
              do (setf (aref buf pos) ch)
              finally (setf (aref dest-arr idx)
                            (parse-integer buf :end pos))))
      dest-arr)))

(deftype uint nil `(integer 0 ,(expt 10 9)))
(defun main ()
  (let* ((n (read))
         (m (read))
         (a-vec (read-vector n))
         (mod-bin (make-hash-table)))
    (loop for idx below n
          sum (aref a-vec idx) into local-sum
          do (let ((prefix-mod (mod local-sum m)))
               (if (nth-value 1 (gethash prefix-mod mod-bin))
                   (incf (gethash prefix-mod mod-bin))
                   (setf (gethash prefix-mod mod-bin) 1))))
    (print-line
     (+ (or (gethash 0 mod-bin) 0)
        (loop for x of-type fixnum being each hash-values in mod-bin
              sum (ash (* x (- x 1)) -1))))
    mod-bin))

#-swank(main)
