Problem:
Score : 300 points

Problem Statement

Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i.
He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A.
In how many ways can he make his selection?

Constraints

1 \leq N \leq 50

1 \leq A \leq 50

1 \leq x_i \leq 50

N,\,A,\,x_i are integers.

Partial Score

200 points will be awarded for passing the test set satisfying 1 \leq N \leq 16.

Input

The input is given from Standard Input in the following format:

N A
x_1 x_2 ... x_N

Output

Print the number of ways to select cards such that the average of the written integers is exactly A.

Sample Input 1

4 8
7 9 8 9

Sample Output 1

5

The following are the 5 ways to select cards such that the average is 8:

Select the 3-rd card.

Select the 1-st and 2-nd cards.

Select the 1-st and 4-th cards.

Select the 1-st, 2-nd and 3-rd cards.

Select the 1-st, 3-rd and 4-th cards.

Sample Input 2

3 8
6 6 9

Sample Output 2

0

Sample Input 3

8 5
3 6 2 8 7 6 5 9

Sample Output 3

19

Sample Input 4

33 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

Sample Output 4

8589934591

The answer may not fit into a 32-bit integer.

Solution in C++ (GCC 9.2.1) (judge verdict: Time Limit Exceeded)

    #include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int, int>;
     
const int MOD = 1e9 + 7;


//bit全探索
vector<ll>bitSearch(int bit,int n){
    vector<ll>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    S.push_back(1e9);
    return S;
}


int main(){
   ll n, a;
   cin >> n >> a;
   vector<ll> x(n / 2), y(n - n / 2);
   rep(i, n / 2)cin >> x[i];
   rep(i, n - n / 2)cin >> y[i];

   ll res = 0;
   int xs = x.size(), ys = y.size();
   vector<vector<ll>>  bit0(n + 1), bit1(n + 1);

   for(ll bit = 0; bit < (1 << xs); bit++){
      auto S = bitSearch(bit, xs);
      int sz = S.size() - 1;
      //if(sz == 0)continue;
      ll sum = 0;
      for(auto s :  S){
         if(s == INF)break;
         sum += x[s];
      }
      bit0[sz].push_back(sum);
   }

   for(ll bit = 0; bit < (1 << ys); bit++){
      auto S = bitSearch(bit, ys);
      int sz = S.size() - 1;
      //if(sz == 0)continue;
      ll sum = 0;
      for(auto s :  S){
         if(s == INF)break;
         sum += y[s];
      }
      bit1[sz].push_back(sum);
   }
   rep(i, n + 1){
      sort(ALL(bit0[i]));
      sort(ALL(bit1[i]));
      bit1[i].push_back(INF);
   }

   rep(i, n + 1){          //bit0の要素何個足してるか
      int sz = bit0[i].size();
      rep(j, sz){          //bit0[i]の要素
         rep(k, n + 1){    //bit1の要素何個足してるか
            ll rem = (ll)(a * (i + k)) - bit0[i][j];
            if(rem < 0)continue;
            ll dif = upper_bound(ALL(bit1[k]), rem) - lower_bound(ALL(bit1[k]), rem);
            res += dif;
           //cout << bit0[i][j] << " " << dif << endl;
         }
      }
   }
  res--;
   cout << res << endl;
}