{-# LANGUAGE RankNTypes #-}                                                                                                                           
import Control.Monad                                                                                                                                  
import Control.Monad.ST                                                                                                                               
import Data.Array.ST                                                                                                                                  
                                                                                                                                                      
type Idx = (Int,Int,Int)                                                                                                                              
                                                                                                                                                      
main :: IO ()                                                                                                                                         
main = do                                                                                                                                             
  [n,a] <- map read . words <$> getLine :: IO [Int]                                                                                                   
  xs <- (0:) . map read . words <$> getLine :: IO [Int]                                                                                               
  print $ sum $ solve n a xs                                                                                                                          
                                                                                                                                                      
solve :: Int -> Int -> [Int] -> [Int]                                                                                                                 
solve m b ys = runST $ do                                                                                                                             
  let smax = m * maximum (b:ys)                                                                                                                       
  dptbl <- newArray ((0,0,0),(m,m,smax)) (-1) :: forall s. ST s (STUArray s Idx Int)                                                                  
  forM_ [(jt,k,s) | s <- [0..smax], k <- [0..m], jt <- zip [0..] ys] $ \((j,yj),k,s) -> do                                                            
    ra <- readArray dptbl (j,k,s)                                                                                                                     
    case ra of                                                                                                                                        
      -1 | (j,k,s) == (0,0,0)    -> writeArray dptbl (j,k,s) 1                                                                                        
         | j>=1 && s<yj          -> readArray dptbl (j-1,k,s) >>= writeArray dptbl (j,k,s)                                                            
         | j>=1 && k>=1 && s>=yj -> liftM2 (+) (readArray dptbl (j-1,k,s)) (readArray dptbl (j-1,k-1,s-yj)) >>= writeArray dptbl (j,k,s)              
         | otherwise             -> writeArray dptbl (j,k,s) 0                                                                                        
      _                          -> return ()                                                                                                         
  mapM (\k -> readArray dptbl (m,k,k*b)) [1..m]

Measured memory_bytes: 52220