import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : k : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  as <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    step :: (Int, [(Int, Int)]) -> Int -> (Int, [(Int, Int)])
    step (c, lrs) a = let c' = c + d in c' `seq` (c', lrs')
      where
        lrs' = (1, a `mod` k) : map f lrs :: [(Int, Int)]
        f :: (Int, Int) -> (Int, Int)
        f (l, r) = let l' = succ l; r' = (r + a) `mod` k in l' `seq` r' `seq` (l', r')
        d = length . filter (uncurry (==)) $ lrs' :: Int
  print . fst . foldl step (0, []) $ as

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
