-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

import qualified Data.IntMap as IntMap

main = print . solve . map read . words =<< getContents


solve (n:a:xs) = ans where
    m0 = IntMap.singleton 1 $ IntMap.singleton 0 1
    ans = IntMap.foldlWithKey r 0 mp
    r s 1 _ = s
    r s i m = s + (IntMap.findWithDefault 0 (a * (i - 1)) m)
    mp = foldl f m0 xs
    f m1 i = IntMap.foldlWithKey g m1 m1 where
        g m2 j m3 = IntMap.insert e m5 m2 where
            e = j + 1
            m4 = IntMap.findWithDefault IntMap.empty e m2
            m5 = IntMap.foldlWithKey h m4 m3
            h m6 t c = IntMap.insert u w m6 where
                u = t + i
                w = case IntMap.lookup u m6 of
                    Nothing -> c
                    Just d -> d + c
