import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m] <- getIntList
    as <- getIntList
    let ss = scanl (\a b -> (a+b) `mod` m) 0 as
    let ans = sum . map (comb . length) . group $ sort ss
            where comb x = x * (x-1) `div` 2
    print ans