import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, k] <- getIntList
    as <- getIntList
    let ls = scanl (+) 0 as
    let rs = scanr (+) 0 as
    let s = head rs
    print $ sum [length . filter (\x -> x `mod` k == i) $ zipWith (\x y -> s - x - y) ls (drop i rs) | i <- [1..n]]