import qualified Data.Map as M
f::Int->Int->Int
f n m = m `mod` n 

f2::Int->Int->[Int]->M.Map Int Int->Int
f2 _ _ [] _=0
f2 m m2 (x:xs) ms=
                  let m3=(m+x) `mod` m2
                      m4=(m2-(x `mod` m2) ) `mod` m2
                      ms2=M.insertWith (-) m3 1 ms
                  in if M.member m4 ms
                  then 
                  let (Just t)=(M.lookup m4 ms)
                      t2=maximum (t:0:[])
                      --ms2=M.delete y2 ms
                  in t2+(f2 m3 m2 xs ms2)
                  else f2 m3 m2 xs ms2

main = do
       a<-getLine
       b<-getLine
       let (_:m:[])=(map read . words) a::[Int]
           xs=(map read . words ) b ::[Int]
           ys=(map (f m) $ scanl1 (+) xs)
           zs=zip ys [1,1..]
           ms=M.fromListWith (+) zs
       print $ f2 0 m xs ms