import Data.List
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B
main=do
    (n:m:_)<-map read.words<$>getLine::IO[Int]
    --
    xm<-foldl (\m a->M.insertWith(+)a 1 m) M.empty.map (flip mod m).tail.scanl' (+) 0.unfoldr (B.readInt.B.dropWhile(==' ')) <$> B.getLine
    --
    print $ (n0 xm) + (sum.map (\a->(a*a-a)`div`2).M.elems $ xm)
--
n0 m = case M.lookup 0 m of
    Nothing -> 0
    Just n  -> n