n, a = gets.chomp.split(" ").map(&:to_i)                                                                                                                                                                                                                                        
x = gets.chomp.split(" ").map(&:to_i)                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                
na = 2500                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                
dp = Array.new(n+1){ Array.new(n+1){ Array.new(na+1, 0)} }                                                                                                                                                                                                                      
dp[0][0][0] = 1                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                
n.times do |j|                                                                                                                                                                                                                                                                  
  n.times do |k|                                                                                                                                                                                                                                                            
    (na+1).times do |s|                                                                                                                                                                                                                                                          
      dp[j+1][k][s] += dp[j][k][s]                                                                                                                                                                                                                                            
      dp[j+1][k+1][s+x[j]] += dp[j][k][s] if dp[j][k][s] != 0                                                                                                                                                                                                                   
    end                                                                                                                                                                                                                                                                         
  end                                                                                                                                                                                                                                                                           
end                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                
ans = 0                                                                                                                                                                                                                                                                         
n.times do |i|                                                                                                                                                                                                                                                                  
  ans += dp[n][i+1][(i+1)*a]                                                                                                                                                                                                                                                    
end                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                
p ans

Measured memory_bytes: 52604