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 (Python):
N,A=map(int,input().split())
x=list(map(int,input().split()))
X=max(max(x),A)
y=[x[i]-A for i in range(N)]
dp=[[0 for i in range(2*N*X+1)] for j in range(N+1)]
dp[0][N*X]=1
for j in range(1,N+1):
  for k in range(2*N*X+1):
    dp[j][k]=dp[j-1][k]
    if 0<= k-y[j-1] and k-y[j-1]<=2*N*X:
      dp[j][k]+=dp[j-1][k-y[j-1]]
print(dp[N][N*X]-1)

Solution (Python):
N,A=map(int,input().split())
x=list(map(int,input().split()))
dp=[[[0 for i in range(50*50+1)] for j in range(N+1) ]for k in range(N+1)]
dp[0][0][0]=1
for i in range(1,N+1):
  for j in range(N+1):
    for k in range(50*50+1):
      dp[i][j][k]=dp[i-1][j][k]
      if x[i-1]<= k and j>0: dp[i][j][k]+=dp[i-1][j-1][k-x[i-1]]
ans=0
for j in range(1,N+1):
  ans+=dp[N][j][j*A]
print(ans)

Solution (Python):

n, a = map(int, input().split())
l_a = list(map(lambda x: int(x) - a, input().split()))

dic = dict()
dic[0] = 1
for x in l_a:
    for key, value in list(dic.items()):
        dic[x + key] = value + dic.get(x+key,0)

print(dic[0] - 1)

Solution (Python):

num_N, num_A = map(int, input().split())
l_card = list(map(int, input().split()))

l_card_ave = [i - num_A for i in l_card]

dict_ans = dict()
dict_ans[0] = 1
for card in l_card_ave:
    for key, value in list(dict_ans.items()):
        dict_ans[key + card] = dict_ans.get(key + card, 0) + value

print(dict_ans[0] - 1)

Solution (Python):

from collections import defaultdict

num_card, num_ave = map(int, input().split())
l_card = map(lambda x: int(x) - num_ave, input().split())

counter = defaultdict(int)
counter[0] = 1

for card in l_card:
    for d, c in list(counter.items()):
        counter[d + card] += c

print(counter[0] - 1)

Solution (Python):
n,a=map(int,input().split())
x=list(map(int,input().split()))
dp=[[[0 for _ in range(50*n+1)] for j in range(n+1)] for _ in range(n+1)] 
dp[0][0][0] = 1
for i in range(1, n+1):
    for j in range(i+1):
        for k in range(50*n+1):
            if i > 0:
                dp[i][j][k] = dp[i-1][j][k]
                if k >= x[i-1]:
                    dp[i][j][k] += dp[i-1][j-1][k-x[i-1]]

ans = 0
for j in range(1,n+1):
    ans += dp[n][j][a*j]
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**9

def f():
    n,a = list(map(int, input().split()))
    x = list(map(int, input().split()))
    x.sort()
    b = [(a-_) for _ in x if _ < a]
    c = [0 for _ in x if _ == a]
    d = [(_-a) for _ in x if _ > a]
    m = 50*50
    ba = [0]*(m+1)
    ba[0] = 1
    for bi in b:
        for j in range(m-bi,-1,-1):
            ba[j+bi] += ba[j]
    da = [0]*(m+1)
    da[0] = 1
    for di in d:
        for j in range(m-di,-1,-1):
            da[j+di] += da[j]
    r = -1
    for i in range(m+1):
        r += ba[i] * da[i]
    cl = len(c)
    cr = 2**cl - 1
    return r * (cr+1) + cr

print(f())

Solution (Python):
import numpy as np

N, A = map(int, input().split())
xs = np.array(list(map(int, input().split()))) - A

dp = np.zeros((50*50*2+1, N+1), dtype=np.int64)
dp[50*50,0] = 1

for i, x in enumerate(xs):
    dp[:,i+1] = dp[:,i]
    dp[max(0,x):min(len(dp),len(dp)+x),i+1] += dp[max(0,-x):min(len(dp),len(dp)-x),i]

print(dp[50*50,N]-1)

Solution (Python):
N, A = map(int, raw_input().split())
a = sorted(map(lambda x:int(x)-A, raw_input().split()))
mem = {}

def rec(p, acm):
    if (p, acm) in mem:
        return mem[(p, acm)]
    if p >= N:
        return 0
    if a[p] > 0 and acm > 0:
        return 0
    mem[(p, acm)] = rec(p+1, acm+a[p]) + rec(p+1, acm)
    if acm+a[p] == 0:
        mem[(p, acm)] += 1
    return mem[(p, acm)]

print rec(0, 0)

Solution (Python):
n,a=map(int,input().split())
x=[0]+[i-a for i in map(int,input().split())]
d={}
def f(i):
    if i==n+1:
        return {0:1}
    if i in d:
        return d[i]
    d[i]={}
    for j in range(i+1,n+2):
        for k,v in f(j).items():
            d[i].setdefault(x[i]+k,0)
            d[i][x[i]+k]+=v
    return d[i]
print(f(0)[0]-1)

Solution (Python):
def makelist(n, m, p):
	return [[[0 for k in range(p)] for i in range(m)] for j in range(n)]

N, A = map(int, input().split())
x = list(map(int, input().split()))

dp = makelist(N+1, N+1, N*A+1)
dp[0][0][0] = 1
for i in range(N):
	for j in range(i+1):
		for k in range(N*A):
			if k + x[i] <= N * A:
				dp[i+1][j+1][k+x[i]] += dp[i][j][k]
			dp[i+1][j][k] += dp[i][j][k]

ans = 0
for i in range(1, N+1):
	ans += dp[N][i][i*A]

print(ans)

Solution (Python):
N, A = map(int, input().split())
xs = map(lambda x: int(x) - A, input().split())

d = dict()
d[0] = 1
for x in xs:
    for s, v in list(d.items()):
        d[s + x] = d.get(s + x, 0) + v

print(d[0]-1)

Solution (Python):
def solve():
	N,A = map(int,raw_input().split())
	x = map(int,raw_input().split())
	ofs = N*50; M = ofs*2 + 1
	DP = [[0]*M for i in xrange(N+1)]
	DP[0][ofs] = 1
	for i in xrange(N):
		for j in xrange(M):
			if DP[i][j] == 0: continue
			DP[i+1][j+x[i]-A] += DP[i][j]
			DP[i+1][j] += DP[i][j]
	print DP[N][ofs] - 1
solve()

Solution (Python):
from collections import defaultdict
def solve():
	N,A = map(int,raw_input().split())
	x = map(int,raw_input().split())
	DP = [defaultdict(int) for i in xrange(N+1)]
	DP[0][0] = 1
	for i in xrange(N):
		for k,v in DP[i].iteritems():
			DP[i+1][k+x[i]-A] += v
			DP[i+1][k] += v
	print DP[N][0] - 1
solve()

Solution (Python):

from collections import defaultdict
N, A = map(int, input().split())

X = map(lambda s: int(s) - A, input().split())

counter = defaultdict(int)
counter[0] = 1

for x in X:
  for d,c in list(counter.items()):
    counter[d+x] += c

print(counter[0]-1)

Solution (Python):
from sys import exit

def reads():
  return [int(x) for x in input().split()]

(N, A) = reads()
x = reads()

d = dict()

d[0] = 1

for i in range(N):
  for (s, N) in list(d.items()):
    k = s + x[i] - A
    d[k] = d.get(k, 0) + N

print(d[0]-1)

Solution (Python):
n,a=map(int,raw_input().split())
x=map(int,raw_input().split())
x.sort()
dp=[[[0]*(n+1) for i in xrange(n*a+1)] for j in xrange(n+1)]
for i in xrange(n+1):
    dp[i][0][0]=1
ans=0
for i in xrange(n):
    for j in xrange(1,n*a+1):
        for k in xrange(1,n+1):
            if i+1<k:break
            if j<x[i]:
                dp[i+1][j][k]=dp[i][j][k]
                continue
            dp[i+1][j][k]=dp[i][j][k]+dp[i][j-x[i]][k-1]
for j in xrange(1,n*a+1):
    for k in xrange(1,n+1):
        if j==a*k:
            ans+=dp[n][j][k]
print(ans)

Solution (Python):
import collections

N, A = [int(s) for s in input().split()]

x = [int(s) for s in input().split()]

S = [collections.Counter() for _ in range(51)]

S[0][0] = 1
for i, xi in enumerate(x):
    prev = [(k,s,c) for k in range(i+1) for s,c in S[k].items()]
    for (k,s,c) in prev:
        S[k+1][s+xi] += c
    

ans = 0
for (k, s, c) in ((k,s,c) for k in range(1,N+1) for s,c in S[k].items()):
    if A*k == s:
        ans += c

print(ans)

Solution (Python):

line1=input().split()
n=int(line1[0])
a=int(line1[1])
nums=input().split()
for i in range(n):
    nums[i]=int(nums[i])-a

works={}

works[0]=1
s=0
for x in nums:

    if x>=0:
        for i in range(50*(n+1),-50*(n+1), -1):
            try:
                works[i]+=works[i-x]
            except:
                try:
                    works[i]=works[i-x]
                except:
                    pass
    else:
        for i in range (-50*(n+1),50*(n+1)):
            try:
                works[i+x]+=works[i]
            except:
                try:
                    works[i+x]=works[i]
                except:
                    pass

print (works[0]-1)

Solution (Python):
N, A = map(int, input().split(' '))

X = map(int, input().split(' '))
X = [x - A for x in X]

from collections import defaultdict
counter = defaultdict(int)
counter[0] = 1

for x in X:
	copy = dict(counter)
	for d,c in copy.items():
		counter[d+x] += c

print(counter[0]-1)

Solution (Python):
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')


def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())


def join(s):
    return ''.join(s)


def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)


def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m


def index(a, x):
    
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1


def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m

nh=zip([1,0,-1,0],[0,1,0,-1])



n,a = ii()
x = ii()
ans=0

@memoize
def dp(i,b,c):
    if i<0:
        return 0
    elif b>i+1:
        return 0
    elif b==1:
        return x[0:i+1].count(c)
    else:
        return dp(i-1,b,c)+dp(i-1,b-1,c-x[i])
        
for j in range(n):
    ans+=dp(n-1,j+1,a*(j+1))

print ans

Solution (Python):
n, a = map(int, raw_input().split())
values = sorted(map(lambda s: int(s) - a, raw_input().split()))
counts = {}
for x in values:
    items = counts.items()
    for a, count in items:
        y = x + a
        counts[y] = counts.setdefault(y, 0) + count
    counts[x] = counts.setdefault(x, 0) + 1
print(counts[0] if 0 in counts else 0)