import qualified Data.ByteString.Char8 as B
import Data.Attoparsec.ByteString.Char8
import qualified Data.IntMap as M
import Data.List
import Data.Char

main :: IO ()
main = do
    Right m <- parseOnly (decimal *> space *> decimal) <$> B.getLine
    Right as <- parseOnly (decimal `sepBy` space) <$> B.getLine
    print $ solve m as

solve :: Int -> [Int] -> Int
solve m =  M.foldl' (+) 0
     . fmap (\x -> x * (x - 1) `div` 2)
     . foldr (\k mp -> M.insertWith (+) k 1 mp)  M.empty
     . map (`mod` m)
     . scanl' (+) 0
