;; -*- 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

(defun split-by-one-space (str size)
  (declare (optimize (speed 3) (safety 1))
           (simple-string str))
  (let ((dest-arr (make-array size :element-type 'fixnum)))
    (loop for idx below (length dest-arr)
          for pos1 = 0 then (1+ pos2)
          for pos2 = (position #\space str :start pos1 :test #'char=)
          do (setf (aref dest-arr idx)
                   (parse-integer str :start pos1 :end pos2))
          finally (return dest-arr))))

(deftype uint nil `(integer 0 ,(expt 10 9)))
(defun main ()
  (let* ((n (read))
         (m (read))
         (a-vec (split-by-one-space (read-line) n))
         (mod-vec (let ((vec (make-array n :element-type 'fixnum)))
                    (dotimes (i n) (setf (aref vec i)
                                         (mod (aref a-vec i) m)))
                    vec))
         (init-sum (loop for x across mod-vec
                         count (zerop (mod x m)))))
    (print-line (calc m n mod-vec mod-vec init-sum 1))))

(defun calc (m n last-vec one-vec sum depth)
  (if (= depth n)
      sum
      (let* ((size (length last-vec))
             (next-vec (make-array (- size 1) :element-type 'fixnum)))
        (loop for i from 0 below (- size 1)
              count (let ((rem (mod (+ (aref last-vec i)
                                       (aref one-vec (+ depth i)))
                                    m)))
                      (setf (aref next-vec i) rem)
                      (zerop rem))
                into local-sum
              finally (return (calc m n next-vec one-vec (+ sum local-sum) (1+ depth)))))))

#-swank(main)
