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()))
y=[x[i]-a for i in range(n)]
z=max(max(x),a)
dp=[[0 for _ in range(2*n*z+1)] for _ in range(n+1)]
dp[0][n*z]=1
for i in range(n):
    for j in range(2*n*z+1):
        if 0<=j+y[i]<=2*n*z:
            dp[i+1][j]=dp[i][j]+dp[i][j+y[i]]
        else:
            dp[i+1][j]=dp[i][j]
print(dp[-1][n*z]-1)

Solution (Python):
N, A = map(int, input().split())
X = [int(x) - A for x in input().split()]

from collections import Counter

total = Counter([0])
for x in X:
    mix = Counter()
    for i, cnt in total.items():
        mix[i + x] += cnt
    total += mix

print(total[0] - 1)

Solution (Python):
from collections import Counter
N, A = map(int, input().split())
X = [int(x) - A for x in input().split()]
C = Counter([0])
for x in X:
  tmp = Counter()
  for i, c in C.items():
    tmp[i + x] += c
  C += tmp
print(C[0] - 1)

Solution (Python):
from collections import defaultdict

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

for i in range(N):
    x[i] -= A
X = max(max(x), A)

dp = [defaultdict(int) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(N):
    for j in range(-N * X, N * X + 1):
        dp[i + 1][j] = dp[i][j] + dp[i][j - x[i]]
print(dp[N][0] - 1)

Solution (Python):
from collections import defaultdict

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

for i in range(N):
    x[i] -= A
X = max(max(x), A)

dp = [defaultdict(int) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(N):
    for j in range(-N * X, N * X + 1):
        if - N * X <= j - x[i] <= N * X:
            dp[i + 1][j] = dp[i][j] + dp[i][j - x[i]]
        else:
            dp[i + 1][j] = dp[i][j]
print(dp[N][0] - 1)

Solution (Python):
from collections import Counter

n,a = map(int, input().split())
x = [int(i) - a for i in input().split()] 

total = Counter([0])

for i in x:
    tmp = Counter()
    for j, cnt in total.items():
        tmp[i+j] += cnt
    total += tmp 

print(total[0] - 1)
exit(0)

Solution (Python):
N, A = map(int, input().split())
X = [int(x) - A for x in input().split()]

import functools
@functools.lru_cache(maxsize=None)
def f(acc, left):
    if not left: return 0
    ret = 0
    y = acc + left[0]
    ret += 1 if y == 0 else 0
    ret += f(y, left[1:])
    ret += f(acc, left[1:])
    return ret
print(f(0, tuple(X)))

Solution (Python):


""" 2次元DP """

N,A = map(int, input().split())
xN = list(map(int, input().split()))
X = max(max(xN), A)

yN = [int(i)-A for i in xN]


dp = [[0] * (2*N*X+1) for j in range(N+1)]

dp[0][N*X] = 1

ans = 0
for i in range(1,N+1):
    for t in range(2*N*X+1):
        
        if t - yN[i-1] < 0 or t - yN[i-1] > 2*N*X:
            dp[i][t] = dp[i-1][t]
        
        elif 0 <= t - yN[i-1] <= 2*N*X:
            dp[i][t] = dp[i-1][t] + dp[i-1][t - yN[i-1]]

print(dp[N][N*X]-1)

Solution (Python):


""" 3次元DP """

N,A = map(int, input().split())
xN = list(map(int, input().split()))
X = max(max(xN), A)


dp = [[[0] * (N*X+1) for j in range(N+1)] for i in range(N+1)]
dp[0][0][0] = 1

ans = 0
for i in range(1,N+1):
    for j in range(N+1):
        for k in range(N*X+1):
            
            
            if k < xN[i-1]:
                dp[i][j][k] = dp[i-1][j][k]
            
            
            elif k >= xN[i-1] and j > 0:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-xN[i-1]]
            
            if i == N and j > 0 and k == j*A:
                ans += dp[i][j][k]




        
print(ans)

Solution (Python):
n, a = map(int, input().split())
x = list(map(int, input().split()))

y = []
for i in range(n):
    y.append(x[i] - a)

dp = [[0 for i in range(110*n)] for j in range(n+1)]

const = 50*n
dp[0][const] = 1


for i in range(n):
    for j in range(100*n + 1):
        dp[i+1][j] = dp[i][j]
        if j - y[i] >= 0 and j - y[i] <= 100*n:
            dp[i+1][j] += dp[i][j - y[i]]

print(dp[n][const]-1)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())


N,A = inpl()
xx = inpl()

pos_numbers = []
neg_numbers = []
Zero = 0

for x in xx:
	tmp = x - A
	if tmp < 0:
		neg_numbers.append(-tmp)
	elif tmp == 0:
		Zero += 1
	else:
		pos_numbers.append(tmp)

pos_sum = set([0])
pos_dd = defaultdict(int)
pos_dd[0] = 1
for n in pos_numbers:
	tmp_set = set()
	tmp_list = list(pos_sum)
	tmp_list.sort(reverse=True)
	for s in tmp_list:
		tmp_set.add(s+n)
		pos_dd[s+n] += pos_dd[s]
	pos_sum = pos_sum | tmp_set


neg_sum = set([0])
neg_dd = defaultdict(int)
neg_dd[0] = 1
for n in neg_numbers:
	tmp_set = set()
	tmp_list = list(neg_sum)
	tmp_list.sort(reverse=True)
	for s in tmp_list:
		tmp_set.add(s+n)
		neg_dd[s+n] += neg_dd[s]
	neg_sum = neg_sum | tmp_set

ans = 0
for n in pos_sum:
	ans += pos_dd[n]*neg_dd[n]

ans *= 2**Zero
print(ans-1)

Solution (Python):
from collections import Counter

n,a = map(int,input().split())
x = list(map(int,input().split()))

dp = [Counter()]

dp[0][0] = 1
for i,j in enumerate(x):
	dp.append(Counter())
	for k in reversed(range(i+1)):
		for m,p in dp[k].items():
			dp[k+1][m+j] += p

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

Solution (Python):
from collections import Counter
N,A = map(int,input().split())
src = list(map(int,input().split()))

dp = [Counter() for i in range(N+1)]
dp[0][0] = 1
for i,a in enumerate(src):
    for j in reversed(range(i+1)):
        for k,v in dp[j].items():
            dp[j+1][k+a] += v
ans = 0
for i,ctr in enumerate(dp):
    if i==0: continue
    ans += ctr[i*A]
print(ans)

Solution (Python):
from collections import Counter

n,a = map(int, input().split())
l = list(map(int, input().split()))

l = [ai - a for ai in l]

cnt = Counter([0, l[0]])

for li in l[1:]:
    tmp = Counter([])
    for k,v in cnt.items():
        tmp[k+li] += v
        
    cnt += tmp
    
print(cnt[0]-1)

Solution (Python):
from collections import Counter

n,a = map(int,input().split())
x = [int(i)-a for i in input().split()]

dp = [Counter()]

dp[0][0] = 1
for i,j in enumerate(x):
	dp.append(Counter())
	for k in reversed(range(i+1)):
		for m,n in dp[k].items():
			dp[k+1][m+j] += n

res = 0
for l in dp:
	res += l[0]
print(res-1)

Solution (Python):
n,a = map(int, input().split())
x = list(map(int, input().split()))
y = max(x)
x = [z-a for z in x]

dp = [[0]*(2*n*y+1) for _ in range(n+1)]
dp[0][n*y] = 1
for k in range(n):
    for i in range(2*n*y+1):
        res = dp[k][i]
        if i+x[k] < 0 or i+x[k] > 2*n*y:
            pass
        else:
            res += dp[k][i+x[k]]
        dp[k+1][i] = res
print(dp[-1][n*y]-1)

Solution (Python):
n,a=map(int,input().split())
l=list(map(int,input().split()))
x=max(l)
x=max(x,a)
dp=[[[0 for _ in range(n*x+1)] for _ in range(n+1)] for _ in range(n+1)]

for j in range(n+1):
  for k in range(n+1):
    for s in range(n*x+1):
      if j==0 and k==0 and s==0:
        dp[j][k][s]=1
      elif j>=1 and s<l[j-1]:
        dp[j][k][s]=dp[j-1][k][s]
      elif j>=1 and k>=1 and s>=l[j-1]:
        dp[j][k][s]=dp[j-1][k][s]+dp[j-1][k-1][s-l[j-1]]
      else:
        dp[j][k][s]=0

s=0
for k in range(1,n+1):
  s+=dp[n][k][k*a]

print(s)

Solution (Python):
def ary2(x, y, v): return [[v for _  in range(y)] for _ in range(x)]

n, a = map(int, input().split())
x = list(map(int, input().split()))
m = max(x)
dp = ary2(n + 1, n + 1, False)

for i in range(n + 1):
    for j in range(n + 1):
        if j == 0:
            dp[i][j] = {0:1}
        else:
            dp[i][j] = dict()

for i in range(1, n + 1):
    for j in range(1, i + 1):
        for s in dp[i - 1][j - 1].keys():
            dp[i][j][s + x[i - 1]] = dp[i][j].get(s + x[i - 1], 0) + dp[i - 1][j - 1].get(s, 0)
        for s in dp[i - 1][j].keys():
            dp[i][j][s] = dp[i][j].get(s, 0) + dp[i - 1][j].get(s, 0)

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

print(ans)

Solution (Python):
from functools import lru_cache

N, A = map(int, input().split())
X = tuple(int(x) for x in input().split())


@lru_cache(maxsize=None)
def rec(i, a, k):
    """
    :param i: int
        数列の長さ
    :param a: int
        総和
    :param k: int
        選ぶ個数
    :return: int
        通り数
        Number of patterns
    """
    if k == 0:
        if a == 0:
            return 1
        else:
            return 0

    ret = 0
    if i - 1 >= k:
        ret = rec(i - 1, a, k)
    if X[i - 1] <= a and i - 1 >= k - 1:
        ret += rec(i - 1, a - X[i - 1], k - 1)
    return ret


i = len(X)
m = (rec(i, k * A, k) for k in range(1, N + 1))
print(sum(m))

Solution (Python):
from functools import lru_cache

N, A = map(int, input().split())
X = tuple(int(x) for x in input().split())


@lru_cache(maxsize=None)
def rec(i, a, k):
    """
    :param i: int 
        数列の長さ
    :param a: int
        総和
    :param k: int
        選ぶ個数
    :return: int
        通り数
        Number of patterns
    """
    if k == 0:
        if a == 0:
            return 1
        else:
            return 0

    if a < 0 or i < k:
        return 0

    ret = rec(i - 1, a, k)
    ret += rec(i - 1, a - X[i - 1], k - 1)
    return ret

i = len(X)
m = (rec(i, k * A, k) for k in range(1, N + 1))
print(sum(m))

Solution (Python):
def na(): return map(int, input().split())
n, a = na()
x = list(na())
xa = list(map(lambda f: f-a, x))
'''
dp[i][点数] = パターン数
i番目まで使用したときの点数になるパターン数
'''
dp = [dict() for _ in range(n)]
if xa[0] == 0:
    dp[0][0] = 2
else:
    dp[0][0] = 1
    dp[0][xa[0]] = 1
for i in range(1, n):
    
    
    for k, v in dp[i-1].items():
        score = xa[i] + k
        dp[i][score] = dp[i].get(score, 0) + v
        dp[i][k] = dp[i].get(k, 0) + v
print(dp[n-1][0] - 1)

Solution (Python):

"""
Created on Sun Aug  5 12:20:16 2018
ABC44C
@author: maezawa
"""

def f(i, j):
    global xa
    global dp
    if i==0:
        cnt = 0
        if j==0:
            cnt += 1
        if j==xa[0]:
            cnt += 1
        return cnt
    if (i, j) in dp:
        return dp[(i,j)]
    else:
        dp[(i,j)] = f(i-1,j-xa[i]) + f(i-1,j)
        
        return dp[(i,j)]


n, a = list(map(int, input().split()))
x = list(map(int, input().split()))

xa = [x[i]-a for i in range(n)]
dp = dict([])

print(f(n-1, 0)-1)

Solution (Python):
from collections import Counter

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

cnt = Counter([0, X[0]])

for x in X[1:]:
    temp = Counter([])
    for k,v in cnt.items():
        temp[k + x] += v
        
    cnt += temp
    
print(cnt[0]-1)

Solution (Python):
from itertools import product

N, A = map(int, input().split())
x = [int(xi) for xi in input().split()]
y = [xi - A for xi in x]
X = max(max(x), A)

dp = [[0 for _ in range(2 * N * X + 1)] for _ in range(N + 1)]

dp[0][N * X] = 1
for k, t in product(range(1, N + 1), range(2 * N * X + 1)):
    if k > 0 and (t - y[k - 1] < 0 or t - y[k - 1] > 2 * N * X):
        dp[k][t] = dp[k - 1][t]
    elif k > 0 and t - y[k - 1] <= 2 * N * X:
        dp[k][t] = dp[k - 1][t] + dp[k - 1][t - y[k - 1]]

print(dp[N][N * X] - 1)

Solution (Python):
N, A = map(int, input().split())
X = [int(x) for x in input().split()]

m = {}
def f(rv, k, rest):
    if k == 0:
        if rv == 0:
            return 1
        else:
            return 0
    if rv < 0 or len(rest) < k:
        return 0
    
    def r(rv, k, rest):
        fp = (rv, k, len(rest))
        if fp in m: return m[fp]
        ret = f(rv, k, rest)
        m[fp] = ret
        return ret
    ans  = r(rv          , k    , rest[1:])
    ans += r(rv - rest[0], k - 1, rest[1:])
    return ans

print(sum([f(k * A, k, sorted(X)) for k in range(1, N + 1)]))

Solution (Python):
from itertools import product

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

X = max(max(x), A)
dp = [[0 for _ in range(2 * N * X + 1)] for _ in range(N + 1)]
dp[0][N * X] = 1

for j, t in product(range(1, N + 1), range(2 * N * X + 1)):
    y = x[j - 1] - A
    if t - y < 0 or t - y > 2 * N * X:
        dp[j][t] = dp[j - 1][t]
    elif 0 <= t - y <= 2 * N * X:
        dp[j][t] = dp[j - 1][t] + dp[j - 1][t - y]
print(dp[N][N * X] - 1)

Solution (Python):
N, A = map(int, input().split())
X = [int(x) for x in input().split()]

m = {}
def f(cv, cur, rest):
    tgt = A * len(cur)
    if len(rest) == 0:
        if cv == tgt and cv != 0:
            return 1
        else:
            return 0
    if cv > tgt and rest[0] > A:
        return 0
    
    ans = 0
    
    cc = cur.copy()
    r = rest[1:]
    sig = (cv, len(cc), tuple(r))
    if sig in m:
        ans += m[sig]
    else:
        ret = f(cv, cc, r)
        m[sig] = ret
        ans += ret

    cc.append(rest[0])
    cv += rest[0]
    sig = (cv, len(cc), tuple(r))
    if sig in m:
        ans += m[sig]
    else:
        ret = f(cv, cc, r)
        m[sig] = ret
        ans += ret
    return ans

print(f(0, [], sorted(X)))

Solution (Python):
from collections import Counter

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

X = [X[i] - A for i in range(N)]

sums = Counter([0, X[0]])

for x in X[1:]:
    c = Counter()
    for k,v in sums.items():
        c[x+k] = v
    sums += c
    
print(sums[0]-1)

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

for i in range(N):
    X[i] -= A

dp = [[0 for _ in range(100*N+1)] for _ in range(N+1)]
dp[0][50*N] = 1

for i in range(1,N+1):
    for summ in range(2*50*N+1):
        if 0 <= summ-X[i-1] <= 100*N:
            dp[i][summ] = dp[i-1][summ] + dp[i-1][summ-X[i-1]]
        else:
            dp[i][summ] = dp[i-1][summ]
            
print(dp[N][50*N]-1)

Solution (Python):
from collections import Counter

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

for i in range(N):
    X[i] -= A
    
sums = Counter([0,X[0]])

for i in range(1,N):
    ith_x = X[i]
    ith_hash = {}
    for key, value in sums.items():
        ith_hash[ith_x + key] = value
        
    sums += ith_hash
    
print(sums[0]-1)

Solution (Python):
import collections

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

for i in range(N):
    X[i] -= A

sums = collections.Counter([0,X[0]])

for i in X[1:]:
    c = collections.Counter()
    for p,q in sums.items():
        c[i+p] = q
    sums += c

print(sums[0]-1)

Solution (Python):
n,a=map(int,input().split())
x=list(map(int,input().split()))
X=max(max(x),a)
y=[]
for i in x:
    y.append(i-a)
dp=[[None for i in range(2*n*X+1)] for h in range(n+1)]
for j in range(n+1):
    for t in range(2*n*X+1):
            if j==0 and t==n*X:
                dp[j][t]=1
            elif j>=1 and (t-y[j-1]<0 or t-y[j-1]>2*n*X):
                dp[j][t]=dp[j-1][t]
            elif j>=1 and t-y[j-1]>=0 and t-y[j-1]<=2*n*X:
                dp[j][t]=dp[j-1][t]+dp[j-1][t-y[j-1]]
            else:
                dp[j][t]=0
                
print(dp[n][n*X]-1)

Solution (Python):
n, a = list(map(int, input().split()))
x = list(map(int, input().split()))
max_x = max(max(x), a)
x = [-10**6] + [xx-a for xx in x]
dp = [[0]*(2*n*max_x+1) for _ in range(n+1)]
dp[0][n*max_x] = 1




for i in range(1, n+1):
    for j in range(2*n*max_x+1):
        if j-x[i] < 0 or j-x[i] > 2*n*max_x:
            dp[i][j] = dp[i-1][j]
        elif j-x[i] >= 0 and j-x[i] <= 2*n*max_x:
            dp[i][j] = dp[i-1][j] + dp[i-1][j-x[i]]


print(dp[n][n*max_x]-1)

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

max_x = max(X)
Y = []
for x in X:
    Y.append(x - A)

dp=[[0 for t in range(60*60*2)] for j in range(60)]



for j in range(N+1):
    for t in range(2*N*max_x+1):
        if j == 0 and t == N*max_x:
            dp[j][t] = 1
        else:
            if j>=1 and (t-Y[j-1] < 0 or t - Y[j-1] > 2*N*max_x):
                dp[j][t] = dp[j-1][t]
            elif j>=1 and 0<= t-Y[j-1] <=2*N*max_x:
                dp[j][t] = dp[j-1][t] + dp[j-1][t-Y[j-1]]
            else:
                dp[j][t] = 0
print(dp[N][N*max_x]-1)

Solution (Python):
n,a = map(int,raw_input().split())

arr = map(int,raw_input().split())
arry = []

for i in range(n):
	arry.append(arr[i]-a)


dp = [[0 for i in range((n)*50*2)] for j in range(n+1)]
dp[0][n*50] = 1

for i in range(n):
	for j in range(n*50*2):
		if 0 <= j-arry[i] and j-arry[i] < n*50*2 :
			dp[i+1][j] = dp[i][j]+dp[i][j-arry[i]]
		else :
			dp[i+1][j] = dp[i][j]

print dp[n][n*50]-1

Solution (Python):
n, a = map(int, input().split())
x = [int(i) for i in input().split()]
X = max(a, *x)
dp = [[[0 for k in range(n*X+1)] for j in range(n+1)]for i in range(n+1)] 
dp[0][0][0] = 1
for j in range(n+1):
    for k in range(n+1):
        for s in range(n*X+1):
            if j == k == s == 0: continue
            if j >= 1 and s < x[j-1]: dp[j][k][s] = dp[j-1][k][s]
            elif j >= 1 and k >= 1 and s >= x[j-1]: dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]
            else: dp[j][k][s] = 0
print(sum([dp[n][k][k*a] for k in range(1, n+1)]))

Solution (Python):
def solve(N,A,X):  
  X.append(0)
  X.sort()
  ma=sum(X)




  dp=[[[0] * (ma+1) for _ in range(N+1)] for _ in range(N+1)]
  

  for i in range(N+1):
    dp[i][0][0]=1
  for i in range(1,N+1):
    cnt=X[i]
    for j in range(1,N+1):
      for k in range(ma+1):
        if k < cnt:
          dp[i][j][k]=dp[i-1][j][k]
        else:
          dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-cnt]


  ans=0
  for x in range(1,N+1):
    if x*A<=ma:
      ans+=dp[N][x][x*A]
  return ans

N,A=map(int,input().split())
X=[int(a) for a in input().split()]
ans=solve(N,A,X)
print(ans)

Solution (Python):


n, a = map(int, input().split())
X = list(map(int, input().split()))



dp = [[[0 for k in range(n*a+1)] for j in range(n+1)] for i in range(n+1)]

for i in range(n+1):
    for j in range(n+1):
        for k in range(n*a+1):
            
            if i == 0 and j == 0 and k == 0:
                dp[i][j][k] = 1

            
            elif i > 0 and k < X[i-1]:
                dp[i][j][k] = dp[i-1][j][k]

            
            
            elif i > 0 and j > 0 and k >= X[i-1]:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-X[i-1]]

            
            else:
                dp[i][j][k] = 0


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

print(ans)

Solution (Python):
n, a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]

max_x = max(x+[a])

y = [0]
for x in x:
    y.append(x-a)

dp = [[0]*(2*n*max_x+1) for i in range(n+1)]
dp[0][n+max_x] = 1

for j in range(n+1):
    for t in range(2*n*max_x+1):
        if j == 0 and t == n*max_x:
            dp[j][t] = 1
        elif j >= 1 and (t-y[j] < 0 or t-y[j] > 2*n*max_x):
            dp[j][t] = dp[j-1][t]
        elif j >= 1 and 0 <= t-y[j] <= 2*n*max_x:
            dp[j][t] = dp[j-1][t] + dp[j-1][t-y[j]]
        else:
            dp[j][t] = 0

print(dp[n][n*max_x]-1)

Solution (Python):
from collections import Counter

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

dp = [Counter({0:1})]

for i,a in enumerate(src):
    dp.append(Counter())
    for j in reversed(range(i+1)):
        for k,v in dp[j].items():
            dp[j+1][k+a] += v

ans = 0
for i,ctr in enumerate(dp):
    if i==0: continue
    ans += ctr[i*A]
print(ans)

Solution (Python):

N, A = map(int, raw_input().split())
x = map(int, raw_input().split())

ADD = 10000
DP = [0 for i in range(N * 50 + 1 + 2 * ADD)]
 
DP[ADD] = 1

for i in range(N):
    if x[i] < A:
        for j in range(-N * 60, N * 60):
            DP[j + ADD] += DP[j + (A - x[i]) + ADD]
    else:
        for j in range(N * 60, -N * 60, -1):
            DP[j + ADD] += DP[j + (A - x[i]) + ADD]

print DP[ADD] - 1

Solution (Python):
from sys import stderr
from functools import reduce
from operator import add
def f(): return [int(i) for i in input().split()]
def debug(*x): stderr.write(reduce(add, repr(x)).strip("()\',") + '\n')

n, a = f()
x = f()
s = sum(x)

dp = [[[0 for i in range(n + 1)] for j in range(s + 1)] for k in range(n + 1)]
for i in range(n + 1):
    dp[i][0][0] = 1

for i in range(1, n + 1):
    for j in range(1, s + 1):
        for k in range(1, n + 1):
            dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - x[i - 1]][k - 1]

ans = 0
k = 1
while a * k <= s and k <= n:
    ans += dp[n][a*k][k]
    k += 1
print(ans)

Solution (Python):
def main():
  n, a = map(int, input().split())
  xlst = list(map(int, input().split()))

  """
  
  
  
  xlst.insert(0, 0)
  dp =  [[[0] * (50 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
  for i in range(n + 1):
    dp[i][0][0] = 1
  
  
  for i in range(1, n + 1):
    x = xlst[i]
    dpi = dp[i]
    dpi_1 = dp[i - 1]
    for j in range(1, n + 1):
      dpij = dpi[j]
      dpi_1j = dpi_1[j]
      dpi_1j_1 = dpi_1[j - 1]
      for k in range(1, n * 50 + 1):
        if k >= x:
          
          dpij[k] += dpi_1j_1[k - x] + dpi_1j[k]
        else:
          
          dpij[k] += dpi_1j[k]

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

  """

  dp = [[0] * (n * 50 + 1) for _ in range(n + 1)]
  dp[0][0] = 1

  for x in xlst:
    for j in range(n, 0, -1):
      dpj = dp[j]
      dpj1 = dp[j - 1]
      for k in range(x, n * 50 + 1):
        dpj[k] += dpj1[k - x]

  print(sum([dp[j][j * a] for j in range(1, n + 1)]))
main()

Solution (Python):
def main():
  n, a = map(int, input().split())
  xlst = list(map(int, input().split()))

  """
  dp[i][j][k] ... iまででj個使ってkを作る
  dp[i][j][k] += dp[i - 1][j - 1][k - x]
  """
  
  """
  xlst.insert(0, 0)
  dp =  [[[0] * (50 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
  for i in range(n + 1):
    dp[i][0][0] = 1
  
  
  for i in range(1, n + 1):
    x = xlst[i]
    dpi = dp[i]
    dpi_1 = dp[i - 1]
    for j in range(1, n + 1):
      dpij = dpi[j]
      dpi_1j = dpi_1[j]
      dpi_1j_1 = dpi_1[j - 1]
      for k in range(1, n * 50 + 1):
        if k >= x:
          
          dpij[k] += dpi_1j_1[k - x] + dpi_1j[k]
        else:
          
          dpij[k] += dpi_1j[k]

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

  """

  dp = [[0] * (n * 50 + 1) for _ in range(n + 1)]
  dp[0][0] = 1

  for x in xlst:
    for j in range(n, 0, -1):
      dpj = dp[j]
      dpj1 = dp[j - 1]
      for k in range(n * 50, x - 1, -1):
        dpj[k] += dpj1[k - x]

  print(sum([dp[j][j * a] for j in range(1, n + 1)]))
main()

Solution (Python):
def main():
  n, a = map(int, input().split())
  xlst = list(map(int, input().split()))
  

  """
  dp[i][j][k] ... iまででj個使ってkを作る
  dp[i][j][k] += dp[i - 1][j - 1][k - x]
  """
  
  """
  dp =  [[[0] * (50 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
  for i in range(n + 1):
    dp[i][0][0] = 1
  
  
  for i in range(1, n + 1):
    x = xlst[i]
    dpi = dp[i]
    dpi_1 = dp[i - 1]
    for j in range(1, n + 1):
      dpij = dpi[j]
      dpi_1j = dpi_1[j]
      dpi_1j_1 = dpi_1[j - 1]
      for k in range(1, n * 50 + 1):
        if k >= x:
          
          dpij[k] += dpi_1j_1[k - x] + dpi_1j[k]
        else:
          
          dpij[k] += dpi_1j[k]

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

  """

  ans = 0
  dp = [[0] * (n * 50 + 1) for _ in range(n + 1)]
  dp[0][0] = 1
  for x in xlst:
    for j in range(n, 0, -1):
      for k in range(n * 50, x - 1, -1):
        dp[j][k] += dp[j - 1][k - x]
  for j in range(1, n + 1):
    ans += dp[j][j * a]
  print(ans)
main()

Solution (Python):
def main():
  n, a = map(int, input().split())
  xlst = list(map(int, input().split()))
  xlst.insert(0, 0)
  """
  dp[i][j][k] ... iまででj個使ってkを作る
  dp[i][j][k] += dp[i - 1][j - 1][k - x]
  """
  
  dp =  [[[0] * (50 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
  for i in range(n + 1):
    dp[i][0][0] = 1
  
  
  for i in range(1, n + 1):
    x = xlst[i]
    dpi = dp[i]
    dpi_1 = dp[i - 1]
    for j in range(1, n + 1):
      dpij = dpi[j]
      dpi_1j = dpi_1[j]
      dpi_1j_1 = dpi_1[j - 1]
      for k in range(1, n * 50 + 1):
        if k >= x:
          
          dpij[k] += dpi_1j_1[k - x] + dpi_1j[k]
        else:
          
          dpij[k] += dpi_1j[k]
  
  ans = 0
  for j in range(1, n + 1):
    ans += dp[n][j][j * a]
  
  print(ans)

main()

Solution (Python):

N, A = map(int, raw_input().split())
x = map(int, raw_input().split())

DP =[[0 for i in range(N * 50 + 1)] for j in range(N + 1)]

DP[0][0] = 1

for i in range(N):
	for j in range(N, 0, -1):
		for k in range(x[i], N * 50 + 1):
			DP[j][k] += DP[j - 1][k - x[i]]

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

print ans

Solution (Python):
from collections import Counter
from copy import copy
N,A = map(int,input().split())
src = list(map(int,input().split()))

dp = [Counter()]
dp[0][0] = 1
for i,a in enumerate(src):
    dp.append(Counter())
    for j in reversed(range(i+1)):
        for k,v in dp[j].items():
            dp[j+1][k+a] += v
ans = 0
for i in range(1,N+1):
    ans += dp[i][A*i]
print(ans)

Solution (Python):
def num_ways_for_sum(target, elems, start_idx, end_idx, cache):
    if start_idx > end_idx:
        if target == 0:
            return 1
        else:
            return 0

    cur_ways = 0
    cache_key = (target, start_idx, end_idx)
    if cache_key in cache:
        cur_ways = cache[cache_key]
    else:
        cur_ways += num_ways_for_sum(target + elems[start_idx], elems, start_idx + 1, end_idx, cache)
        cur_ways += num_ways_for_sum(target, elems, start_idx + 1, end_idx, cache)
        cache[cache_key] = cur_ways
    return cur_ways

if __name__ == '__main__':
    n, a = list(map(int, input().split(' ')))
    xs = list(map(int, input().split(' ')))
    diffs = []
    for x in xs:
        diffs.append(x - a)

    print(num_ways_for_sum(0, diffs, 0, len(xs) - 1, {}) - 1)

Solution (Python):
n, a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]

dp=[[0 for i in range(a*n+1)] for j in range(n+1)]
dp[0][0]=1
ans=0
f=0

for k in range(1,n+1):
  kx=x[k-1]
  f+=kx
  for i in range(k,0,-1):
    for j in range(kx,a*n+1):
      dp[i][j] += dp[i-1][j-kx]
      if j > f:
        break
      
for i in range(1,n+1):
  ans+=dp[i][a*i]

print(ans)

Solution (Python):
n, a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]

dp=[[0 for i in range(a*n+1)] for j in range(n+1)]
dp[0][0]=1
ans=0
f=0

for k in range(1,n+1):
  kx=x[k-1]
  f+=kx
  for i in range(k,0,-1):
    for j in range(kx,a*n+1):
      dp[i][j] += dp[i-1][j-kx]
      if j > f:
        break
      
for i in range(1,n+1):
  ans+=dp[i][a*i]

print(ans)

Solution (Python):
from collections import defaultdict as dd
N,A = map(int,input().split())
src = list(map(int,input().split()))

dp = [dd(lambda:0)]
dp[0][0] = 1
for i,a in enumerate(src):
    dp.append(dd(lambda:0))
    for j in reversed(range(i+1)):
        for k,v in dp[j].items():
            dp[j+1][k+a] += v
ans = 0
for i in range(1,N+1):
    ans += dp[i][i*A]
print(ans)

Solution (Python):
n, a = map(int, input().split())
x = list(map(int, input().split()))

x_max = max(x)
y = [i-a for i in x]


def ave_comb():
    dp = [[0 for d in range(2*n*x_max+1)] for c in range(n+1)]
    for i in range(n+1):
        dp[i][n*x_max] = 1

    for i in range(1, n+1):
        for j in range(1, 2*n*x_max+1):
            if 0 <= j - y[i-1] <= 2 * n * x_max:
                dp[i][j] = dp[i-1][j-y[i-1]] + dp[i-1][j]
            else:
                dp[i][j] = dp[i-1][j]

    return dp[n][n*x_max] - 1


def main():
    print(ave_comb())


if __name__ == '__main__':
    main()

Solution (Python):
n, a = map(int, input().split())
x = list(map(int, input().split()))


def ave_comb(v_max, ave):
    dp = [[[0 for c in range(n*v_max+1)] for b in range(n+1)] for a in range(n+1)]

    for i in range(n+1):
        dp[i][0][0] = 1

    for i in range(1, n+1):
        for j in range(1, i+1):
            for k in range(1, n*v_max+1):
                if k - x[i-1] >= 0:
                    dp[i][j][k] = dp[i-1][j-1][k-x[i-1]] + dp[i-1][j][k]
                else:
                    dp[i][j][k] = dp[i-1][j][k]

    ans = 0
    for t in range(1, n+1):
        ans += dp[n][t][ave*t]

    return ans


def main():
    x_max = max(max(x), a)

    print(ave_comb(x_max, a))


if __name__ == '__main__':
    main()

Solution (Python):

def inpl(): return list(map(int, input().split()))

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


DP = [0]*(5001)
DP[2500] = 1

for x in X:
    DP2 = [0]*(5001)
    for i in range(50, 4950):
        DP2[i+x] += DP[i] + DP[i+x]
    DP = DP2

print(DP[2500] - 1)

Solution (Python):
def larger(x, y):
	if x > y: return x
	else: return y

N, A = map(int, raw_input().split())
x = map(int, raw_input().split())
x = map(lambda a: a-A, x)
max = larger(x[-1], A)
dp = []

for i in range(0, N+1):
	tmp = []
	for j in range(0, 2*N*max+1):
		tmp.append(0)
	dp.append(tmp)

for i in range(0, N+1):
	for j in range(0, 2*N*max+1):
		if i == 0:
			if j == N*max: dp[i][j] = 1
		else:
			if j-x[i-1] < 0 or j-x[i-1] > 2*N*max:
				dp[i][j] = dp[i-1][j]
			else:
				dp[i][j] = dp[i-1][j] + dp[i-1][j-x[i-1]]

print dp[N][N*max]-1

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

dp = [[[0 for k in range(N*A+1)] for j in range(N+1)] for l in range(N+1)]
dp[0][0][0] = 1

for p in range(N):
    for q in range(N):
        for r in range(N*A):
            dp[p+1][q][r] += dp[p][q][r]
            if r+x[p] <= N*A:
                dp[p+1][q+1][r+x[p]] += dp[p][q][r]
                
ans = 0
for k in range(1,N+1):
    ans += dp[N][k][k*A]
print(ans)

Solution (Python):
n,a = [int(i) for i in input().split()]

X = [int(i)-a for i in input().split()]
dp = [[0]*(100*n+1) for i in range(n+1)]

dp[0][50*n]=1

for i in range(n):
    for j in range(50,100*n+1-50):
            dp[i+1][j] = dp[i][j]+dp[i][j-X[i]]
        
ans = dp[n][n*50]-1
    
print(ans)

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