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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n, a;
    scanf("%ld%ld", &n, &a);

    vector<long> x(n);
    long i,j;
    for(i=0; i<n; i++) {
        scanf("%ld", &x[i]);
        x[i] -= a;
    }
    sort(x.begin(), x.end());

    long cnt=0;
    long k = n/2;
    vector<ll> x0(1<<k);    
    for(i=0; i<(1<<k); i++) {
        ll sum=0;
        for(j=0; j<k; j++) {
            if(i & (1<<j)) sum+=x[j];
        }
        x0[cnt]=-sum;
        cnt++;
    }
    assert(cnt==(1<<k));

    cnt=0;
    vector<ll> x1(1<<(n-k));    
    for(i=0; i<(1<<(n-k)); i++) {
        ll sum=0;
        for(j=0; j<(n-k); j++) {
            if(i & (1<<j)) sum+=x[j+k];
        }
        x1[cnt]=sum;
        cnt++;
    }
    assert(cnt==(1<<(n-k)));

    sort(x0.begin(), x0.end());
    sort(x1.begin(), x1.end());

    ll ans=0;
/*
i=0;
    j=0;
    while(i<x0.size() && j<x1.size()) {
        ll curr=x0[i];
        ll curr1=x1[j];
        if(curr==curr1) {
            long cnt0=0;
            while(i+cnt0<x0.size() && x0[i+cnt0]==curr) {
                cnt0++;
            }
            long cnt1=0;
            while(j+cnt1<x1.size() && x1[j+cnt1]==curr) {
                cnt1++;
            }
            if(cnt0>0 && cnt1>0) {
                ans += ((ll)cnt0*cnt1);
            }
            i+=cnt0;
            j+=cnt1;
        }
        else if(curr>curr1) {
            j++;
        }
        else {
            i++;
        }
    }
    */
    printf("%lld\n", ans-1);
    return 0;
}