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)

/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=1000010;
char s[N];
int n,nxt[N],pre[N];
typedef unsigned long long ull;
const ull base=19260817;
ull pw[N],Hash[N];
void init(){
	pw[0]=1;for(int i=1;i<=n;i++)pw[i]=pw[i-1]*base,Hash[i]=Hash[i-1]*base+s[i];
	int j=0;nxt[1]=0;
	for(int i=2;i<=n;i++){
		while(j && s[j+1]!=s[i])j=nxt[j];
		if(s[j+1]==s[i])j++;
		nxt[i]=j;
	}
	j=n+1;pre[n]=n+1;
	for(int i=n-1;i;i--){
		while(j<=n && s[j-1]!=s[i])j=pre[j];
		if(s[i]==s[j-1])j--;
		pre[i]=j;
	}
}
ull gethash(int l,int r){return Hash[r]-Hash[l-1]*pw[r-l+1];}
bool check(int id){
	int flag1=(!nxt[id] || (id)%(id-nxt[id]));
	int flag2=(pre[id+1]==n+1 || (n-id)%(n-id-(n-pre[id+1]+1)));
	return (flag1&flag2);
}
int main(){
	scanf("%s",s+1);n=strlen(s+1);
	int flag=1;
	for(int i=2;i<=n;i++)
		if(s[i]!=s[1]){flag=0;break;}
	if(flag)return printf("%d\n%d\n",n,1),0;
	init();flag=1;int ans=0;
	for(int i=2;i*i<=n;i++)
		if(n%i==0){
			int x=i;
			if(gethash(1,n-x)==gethash(x+1,n)){flag=0;ans=x;break;}
			x=n/i;
			if(gethash(1,n-x)==gethash(x+1,n)){flag=0;ans=x;break;}
		}
	if(flag)return printf("%d\n%d\n",1,1),0;
	printf("%d\n",n/ans);int sum=0;
	for(int i=1;i<n;i++)if(check(i))sum++;
	printf("%d\n",sum);
	return 0;
}