main = do
  line_nm <- getLine
  line_a <- getLine
  let
    [n,m] = map read $ words line_nm :: [Int]
    la = map read $ words line_a :: [Int]
    atob la sum
      | la == [] = []
      | otherwise = (mod (sum+(head la)) m) : (atob (tail la) (sum+(head la)))
    count lb
      | lb == [] = []
      | otherwise = insert (head lb) (count (tail lb))
    insert x ls
      | ls == [] = [(x,1)]
      | fst (head ls) == x = ((fst $ head ls),((snd $ head ls)+1)) : (tail ls)
      | otherwise = (head ls) : (insert x (tail ls))
    sumup ls sum
      | ls == [] = sum
      | otherwise = sumup (tail ls) (sum+(calc $ snd $ head ls))
    calc x = (div (x*(x-1)) 2)
    in
      do 
        putStrLn $ show $ sumup (insert 0 (count $ atob la 0)) 0
