import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B
import Debug.Trace

main :: IO ()
main = breads >>= main'
    where
        main' [n, m] = breads >>= print . solve n m

solve :: Int -> Int -> [Int] -> Int 
solve n m = sum . map count . group . sort . scanl (\l r -> val $ l + r) 0 . map val
    where
        count xs = (n * (n - 1)) `div` 2
            where
                n = length xs
        val = (`mod` m)

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine