import qualified Data.ByteString.Char8 as B
import           Data.Char
import           Data.List             as L

main :: IO ()
main = do
  [n, m] <- map read.words <$> getLine
  xs <- L.unfoldr (B.readInt.B.dropWhile isSpace) <$> B.getLine
  print $ solve m xs

solve :: Int -> [Int] -> Int
solve m xs = zeros + sum[ l * (l - 1) `quot` 2| ys<-yss,let l = length ys]
  where
    zeros
        | y == 0 = length ys
        | otherwise = 0
    yss@(ys@(y:_):_) = L.group
        .L.sort
        . scanl1 (\x y -> (x + y) `rem` m)
        $ map (`rem` m) xs