import Data.List

sums::Int->[Int]->[Int]
sums i [] = [i]
sums i (x:xs) = i:(sums (i+x) xs)

proc::Int->[Int]->Integer
proc m ls = let c =  map (\ v -> mod v m) (sums 0 ls) in
            let nums = ((map (\l -> length l)).group.sort) c in
            sum (map ((\i-> div (i*(i-1)) 2).toInteger) nums)

main::IO()
main=do
  c<-getLine
  let n:m:[]=map read (words c)
  d<-getLine
  let dat = map read (words d)
  print (proc m dat) 