mport Control.Monad
import Data.List

main = do
    [n, m] <- map read <$> words <$> getLine
    a      <- map read <$> words<$>getLine
    putStrLn $ show $ solve m a

solve :: Int -> [Int] -> Integer
solve m a = sum $ map (calc . fromIntegral . length) $ group $ sort $ foldr add [0] a
  where
    calc l = l * (l - 1) `div` 2
    add v sumarray = ((v + head sumarray) `mod` m) : sumarray
