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):
from collections import Counter

X, A = map(int, input().split())
x = [i - A for i in map(int, input().split())]
x.sort()
dp = Counter()

for i in x:
    for j, k in list(dp.items()):
        dp[j + i] = dp[j + i] + k
    dp[i] += 1

print(dp[0])

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

XX = sum(X) + 1

dp = [[[0 for i in range(XX * 2)] for i in range(N + 3)] for i in range(N + 3)]

dp[0][0][0] = 1

for i in range(N):
    for j in range(N + 1):
        for n in range(XX):
            dp[i + 1][j][n] += dp[i][j][n]
            dp[i + 1][j + 1][n + X[i]] += dp[i][j][n]

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

print(ans)

Solution (Python):
import collections

n, a = map(int, input().split())
ls = sorted([x - a for x in map(int, input().split())])
counter = collections.Counter()
for x in ls:
    for k, v in list(counter.items()):
        counter[k + x] = counter[k + x] + v
    counter[x] += 1
print(counter[0])

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



dp = [[[0] * 2700 for _ in range(52)]
      for __ in range(52)]

dp[0][0][0] = 1
for i in range(0, n):
    for j in range(0, n + 1):
        for k in range(n * max(X) + 1):
            dp[i + 1][j][k] += dp[i][j][k]  
            dp[i + 1][j + 1][k + X[i]] += dp[i][j][k]  

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

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

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

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

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

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

mx = 0
for i in range(n):
    mx += abs(x[i])
mx +=1

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

for i in range(1,n) :
    for j in range(-mx,mx):
        dp[i][j] += dp[i-1][j-x[i]]
        dp[i][j] += dp[i-1][j]
    
print(dp[n-1][0]-1)

Solution (Python):
n, a = map(int, input().split())
x = [0] + list(map(int, input().split()))
nx = 2501


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

for j in range(1, n+1):
    for k in range(n+1):
        for s in range(nx+1):
            if x[j] > s:
                dp[j][k][s] = dp[j-1][k][s]
            elif k >= 1:
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j]]

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

print(ans)

Solution (Python):

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

L = sum(X)

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

for i in range(N):
    for j in range(L+10):
        for k in range(N):
            dp[i+1][j][k] += dp[i][j][k]
            if j >= X[i]:
                dp[i+1][j][k+1] += dp[i][j-X[i]][k]
            
ans = 0
for k in range(1,N+1):
    if A*k > L:break
    ans += dp[N][A*k][k]
                
print(ans)

Solution (Python):
def f(n,x,i):
    if n == 0:
        if x != 0:
            if x / i == a:
                return 1
        return 0
    if memo[i][n][x] != -1:
        return memo[i][n][x]
    memo[i][n][x] = f(n-1,x,i)+f(n-1,x+ary[n-1],i+1)
    return memo[i][n][x]
n,a = map(int,input().split())
ary = list(map(int,input().split()))
memo = [[[-1 for _ in range(sum(ary)+1)] for _ in range(n+1)] for _ in range(n+1)]
print(f(n,0,0))

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

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

def rep(j,k,s):
    if(dp[j][k][s]==-1):
        if(s==j==k==0):
            dp[j][k][s] = 1
        elif(j>=1 and s<x[j-1]):
            dp[j][k][s] = rep(j-1,k,s)
        elif(j>=1 and k>=1 and s>=x[j-1]):
            dp[j][k][s] = rep(j-1,k,s) + rep(j-1,k-1,s-x[j-1])
        else:
            dp[j][k][s] = 0
    return dp[j][k][s]

ans = 0
for k in range(1,N+1):
    ans += rep(N,k,k*A)
print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce



sys.setrecursionlimit(2147483647)
INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, a = LI()
L = LI()
L = [i - a for i in L]
dp = defaultdict(int)
dp[0] = 1
for i in range(n):
    if L[i] <= 0:
        for j in range(-2500, 2501):
            dp[j] += dp[j - L[i]]
    else:
        for j in range(2500, -2501, -1):
            dp[j] += dp[j - L[i]]


print(dp[0] - 1)

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

Solution (Python):
n, a = map(int, input().split(" "))
list_x = [int(x) - a for x in input().split(" ")]
counts = [{} for i in range(n + 1)]
counts[0][0] = 1
for i, x in enumerate(list_x):
  for v in counts[i]:
    c = counts[i][v]
    if v not in counts[i + 1]:
      counts[i + 1][v] = 0
    counts[i + 1][v] += c
    if v + x not in counts[i + 1]:
      counts[i + 1][v + x] = 0
    counts[i + 1][v + x] += c
print(counts[n][0] - 1)

Solution (Python):
import numpy as np
import sys
input = sys.stdin.readline

def main():
    N, A = map(int, input().split())
    x = np.array(list(map(int, input().split())))
    X = max(A, max(x))
    x -= A
    
    dp = np.zeros((N+1, 2*N*X+1), dtype=int)
    
    dp[0][N*X] = 1
    for i in range(N):
        dp[i+1] += dp[i]
        if x[i] > 0:
            dp[i+1][x[i]:] += dp[i][:-x[i]]
        elif x[i] < 0:
            dp[i+1][:x[i]] += dp[i][-x[i]:]
        else:
            dp[i+1] += dp[i]
    
    
    
    print(dp[-1][N*X] - 1)

if __name__ == "__main__":
    main()

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

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

dp[0][0][0] = 1  

for i in range(N):
    for j in range(N+1):
        for k in range(50*N+1):
            
            if k+X[i] < 50*N+2:
                dp[i+1][j][k] += dp[i][j][k]
                dp[i+1][j+1][k+X[i]] += 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())  
X = tuple(map(int, input().split()))  

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

dp[0][0][0] = 1  

for i in range(N):
    for j in range(N+1):
        for k in range(50*N+1):
            if dp[i][j][k]:  
                dp[i+1][j][k] += dp[i][j][k]
                dp[i+1][j+1][k+X[i]] += 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())  
X = tuple(map(int, input().split()))  

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

dp[0][0][0] = 1  

for i in range(N):
    for j in range(N+1):
        for k in range(50*N+1):
            if dp[i][j][k]:  
                dp[i+1][j][k] += dp[i][j][k]
                dp[i+1][j+1][k+X[i]] += dp[i][j][k]
ans = 0
for i in range(1, N+1):
    ans += dp[N][i][i*A]
print(ans)

Solution (Python):

def main():
    N, A, *X = map(int, open(0).read().split())
    X, D = [i - A for i in X], {0: 1}
    for i in X:
        for j, k in list(D.items()):
            D[i + j] = D.get(i + j, 0) + k
    ans = D[0] - 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from collections import defaultdict


def main():
    N, A, *X = map(int, open(0).read().split())
    X, D = [i - A for i in X], defaultdict(int)
    D[0] = 1
    for i in X:
        for j, k in list(D.items()):
            D[i + j] += k
    ans = D[0] - 1
    print(ans)
    


if __name__ == "__main__":
    main()

Solution (Python):


import itertools

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

max_x = max(max(x_list), A)
dp = [[[0 for s in range(N * max_x + 1)] for k in range(N + 1)] for j in range(N + 1)]
dp[0][0][0] = 1
ka_list = []

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

ans = sum([dp[N][k][k * A] for k in range(1, N + 1)])
print(ans)

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

X.sort()
ii = 0
while ii < n and X[ii] < a:
    ii += 1
jj = ii
while jj < n and X[jj] == a:
    jj += 1

aa = jj-ii
A = [[a-i for i in X[:ii]], [j-a for j in X[jj:]]]



mm = min(sum(A[0]), sum(A[1]))

AA = [[0] * (mm + 1) for i in range(2)]
for k in range(2):
    AA[k][0] = 1
    for i in range(len(A[k])):
        for j in range(len(AA[k])-1, -1, -1):
            if j - A[k][i] >= 0:
                AA[k][j] += AA[k][j-A[k][i]]
                
                



ans = 0
for i in range(1, mm + 1):
    ans += AA[0][i] * AA[1][i]

ans *= 2 ** aa

print(ans + (2 ** aa - 1))

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

temp = x + [A]

X = max(temp)

m = N * X

dp = [[[0 for s in range(m+1)] for k in range(N+1)] for j in range(N+1)]

dp[0][0][0] = 1

res = 0

for j in range(N):
    for k in range(N):
        for s in range(m):
            if dp[j][k][s]:
                dp[j+1][k][s] += dp[j][k][s]
                dp[j+1][k+1][s+x[j]] += dp[j][k][s]

for k in range(1,N+1):
    res += dp[N][k][k*A]

print(res)

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

"""
普通にやると最大で2**50通りなのでTLE
i枚選んだ時に合計がi*Aになる物を考えるとよい
prd_xxxさんの解答に自分向けのコメントつけただけ
https://atcoder.jp/contests/abc044/submissions/3018277
"""


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

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

ans = 0
for i, C in enumerate(dp):
    if i >= 1:
        ans += C[i*A]
print(ans)

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

"""
普通にやると最大で2**50通りなのでTLE
i枚選んだ時に合計がi*Aになる物を考えるとよい

"""


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

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

ans = 0
for i, C in enumerate(dp):
    if i >= 1:
        ans += C[i*A]
print(ans)

Solution (Python):
n,*x=map(int,open(0).read().split());y=[x[0]-i for i in x];m=n*max(x);d=[[0]*m*2 for _ in[0]*-~n];d[0][0]=1
for i in range(1,n+1):
	for s in range(-m,m):d[i][s]=d[i-1][s]+d[i-1][s-y[i]]
print(d[n][0]-1)

Solution (Python):
n,*x=map(int,open(0).read().split())
y=[x[0]-i for i in x]
m=n*max(x)
dp=[[0]*(m*2+1) for _ in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
	for s in range(-m,m):
		dp[i][s]=dp[i-1][s]+dp[i-1][s-y[i]]
print(dp[n][0]-1)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,A = inpl()
x = inpl()
nx = n * max(max(x),A)
dp = [[[0 for _ in range(n+5)] for i in range(nx+1)] for j in range(n+5)]
dp[0][0][0] = 1
for i in range(n):
    for j in range(nx+1):
        for k in range(n):
            if j >= x[i]:
                dp[i+1][j][k+1] = dp[i][j-x[i]][k] + dp[i][j][k+1]
            else:
                dp[i+1][j][k] = dp[i][j][k]

ans = 0
for j in range(1,nx+1):
    for k in range(1,n+1):
        if j/k == A:
            ans += dp[n][j][k]
print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,A = inpl()
x = inpl()
dp = [[[0 for _ in range(n+5)] for i in range(3005)] for j in range(n+5)]
dp[0][0][0] = 1
for i in range(n):
    for j in range(sum(x)+1):
        for k in range(n):
            if j >= x[i]:
                dp[i+1][j][k+1] = dp[i][j-x[i]][k] + dp[i][j][k+1]
            else:
                dp[i+1][j][k] = dp[i][j][k]


ans = 0
for j in range(1,sum(x)+1):
    for k in range(1,n+1):
        if j/k == A:
            ans += dp[n][j][k]
print(ans)

Solution (Python):

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

lis = []

for i in range(51):
    lis.append([0] * 2501)

lis[0][0] = 1

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


for x in X:

    nlis = []
    for k in range(51):
        new = lis[k].copy()
        nlis.append(new)

    for i in range(51):

        for j in range(2501):

            if i+1 <= 50 and j+x <= 2500 and nlis[i][j] > 0:

                lis[i+1][j+x] += nlis[i][j]

ans = 0
for i in range(51):

    for j in range(2501):

        if i != 0 and j % i == 0 and j // i == A:
            
            ans += lis[i][j]

print (ans)

Solution (Python):
n,a =map(int,input().split())
X=list(map(int,input().split()))
X=list(map(lambda x:x-a, X))
dp={0:1}
for i in X:
  for k,v in list(dp.items()):
    dp[i+k]=dp.get(i+k,0)+v
print(dp[0]-1)

Solution (Python):
def f(n,x,i):
    if n == 0:
        if i != 0:
            if x/i == m:
                return 1
        return 0
    if memo[n-1][i][x] != -1 :
        return memo[n-1][i][x]
    memo[n-1][i][x] = f(n-1,x,i)+f(n-1,x+a[n-1],i+1)
    return memo[n-1][i][x]

n, m= map(int,input().split())
a = list(map(int,input().split()))
memo = [[[-1 for _ in range(sum(a)+1)]for i in range(n)]for i in range(n)]
print(f(n,0,0))

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

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

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




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

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

X = max(x + [A])

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

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

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

Solution (Python):
import numpy as np
N,A = map(int,input().split())
X = [int(x) for x in input().split()]
dp = np.zeros((N+1,3000),dtype=np.int64) 
dp[0,0] = 1

for x in X:
  dp[1:,x:] += dp[:-1,:-x].copy()
  
answer = 0
for n in range(1,N+1):
  answer += dp[n,n*A]
  
print(answer)

Solution (Python):

n,a = map(int,input().split())
x = list(map(int,input().split()))
dp0 = [[0 for s in range(n*a+1)] for k in range(n+1)]
dp0[0][0] = 1
dp = dp0
for j in range(n):
  now = []
  for k in range(n+1):
    add = []
    for s in range(n*a+1):
      t = s-x[j]
      if t >= 0 and k >= 1:
        add.append( dp[k][s] + dp[k-1][t] )
      else:
        add.append( dp[k][s] )
    now.append(add)
  dp = now
ans = 0
for k in range(1,n+1):
  ans += dp[k][k*a]
print(ans)

Solution (Python):
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, a = na()
x = na()
x = [0] + x
dp = [[[0] * (50 * n + 1) for i in range(n+1)] for j in range(n+1)]

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

Solution (Python):
N, A = map(int, input().split())
xs = list(map(int, input().split()))
dp = [{} for i in range(N+1)]
dp[0][0] = 1
for i in range(N):
  x = xs[i]-A
  for s in dp[i]:
    n = dp[i][s]
    if s not in dp[i+1]: dp[i+1][s] = 0
    dp[i+1][s] += n
    if s+x not in dp[i+1]: dp[i+1][s+x] = 0
    dp[i+1][s+x] += n
r = dp[N][0]-1
print(r)

Solution (Python):
def main():
    N,A = map(int,input().split())
    X = [int(x) for x in input().split()]
    dp = [[[0 for _ in range(2501)] for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0][0] = 1
    for j in range(N):
        now = X[j]
        for k in range(N+1):
            for s in range(2501):
                if now>s:
                    dp[j+1][k][s] = dp[j][k][s]
                else:
                    dp[j+1][k][s] = dp[j][k][s] + dp[j][k-1][s-now]
    ans = 0

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

            

if __name__=="__main__":
    main()

Solution (Python):

def main():
    N, A = tuple(map(int, input().split()))
    X = tuple(map(lambda x: int(x) - A, input().split()))
    D = {0: 1}
    for i in X:
        for j, k in list(D.items()):
            D[i + j] = D.get(i + j, 0) + k
    ans = D[0] - 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N, A = [int(x) for x in input().split()]
X = [int(x) for x in input().split()]
mat = {}
def dp(i: int, x: list) -> int:
  sumx = sum(x)
  lenx = len(x)
  if i == N:
    if lenx and sumx == A * lenx:
      return 1
    else:
      return 0
  if (i, sumx, lenx) in mat:
    return mat[(i, sumx, lenx)]
  ret = dp(i + 1, x[:]) + dp(i + 1, x[:] + [X[i]])
  mat[(i, sumx, lenx)] = ret
  return ret

print(dp(0, []))

Solution (Python):
N, A = map(int, input().split())
x = [int(i) for i in input().split()]
DP = [[[0] * (2501) for i in range(N+1)] for j in range(N+1)]
ans = 0
DP[0][0][0] = 1

for i in range(N):
  for j in range(N):
    for k in range(2501):
      if DP[i][j][k]:
        DP[i+1][j+1][k+x[i]] += DP[i][j][k]
        DP[i+1][j][k] += DP[i][j][k]
for i in range(N):
  ans += DP[N][i+1][(i+1)*A]
print(ans)

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

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

for i in range(n+1):
    for j in range(n+1):
        for k in range(n*x_max+1):
            if i == 0 and j == 0 and k == 0:
                dp[i][j][k] = 1
            elif i >= 1 and k < x[i-1]:
                dp[i][j][k] = dp[i-1][j][k]
            elif i >= 1 and j >= 1 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 k in range(1, n+1):
    if k * a <= n*x_max:
        ans += dp[n][k][k*a]
print(ans)

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

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

dp[0][0][0] = 1
for j in range(1, N + 1):
    for k in range(N + 1):
        for s in range(N * X + 1):
            if s < x[j - 1]:
                dp[j][k][s] = dp[j - 1][k][s]
            elif 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]]

count = 0
for k in range(1, N + 1):
    
    count += dp[N][k][k * A]
print(count)

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

ma=max(max(y),-1*min(y))*n
ny=ma*2
dp=[[0]*(ny+1) for _ in range(n+1)]
for i in range(n+1):
  for j in range(ny+1):
    if i==0 and j==ma:
      dp[i][j]=1
    elif i>=1:
      sa=j-y[i-1]
      if sa<0 or sa>ny:
        dp[i][j]=dp[i-1][j]
      else:
        dp[i][j]=dp[i-1][j]+dp[i-1][sa]
print(dp[n][ma]-1)

Solution (Python):

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

dp = [[[0 for _ in range(3010)] for __ in range(N+1)] for ___ in range(N+1)]

dp[0][0][0] = 1

for i in range(N):
    for j in range(N):
        for k in range(2500+1):
            if dp[i][j][k]:
                dp[i+1][j][k] += dp[i][j][k]
                dp[i+1][j+1][k+X[i]] += dp[i][j][k]

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

print(ans)

Solution (Python):
N, A = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
dp = dict()
for cur in x:
    dp2 = dict()
    dp2[cur-A] = 1
    for val in dp:
        dp2[cur+val-A] = dp2.get(cur+val-A, 0) + dp[val]
    for val in dp2:
        dp[val] = dp.get(val, 0) + dp2[val]
print(dp.get(0, 0))

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

    cur = dict()
    cur[X[0]-A] = 1
    for i in range(1, N):
        temp = dict()
        temp[X[i]-A] = 1
        for v in cur:
            temp[v+X[i]-A] = temp.get(v+X[i]-A, 0) + cur[v]
        for v in temp:
            cur[v] = cur.get(v, 0) + temp[v]
    return cur.get(0, 0)

if __name__ == '__main__':

    print(main())

Solution (Python):
n,a=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]
y=[i-a for i in x]
m=sum(x)+1
dp=[[0 for j in range(m*2+1)] for i in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
    for j in range(-m,1+m):
        if j-y[i-1]>=-m and j-y[i-1]<=1+m:
            dp[i][j]=dp[i-1][j]+dp[i-1][j-y[i-1]]
        else:
            dp[i][j]=dp[i-1][j]

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

Solution (Python):

import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n, a = map(int, input().split())
    xl = list(map(int, input().split()))
    dp = [[[0] * 2501 for _ in range(n + 1)] for _ in range(n + 1)]
    dp[0][0][0] = 1
    for i in range(n):
        for j in range(n):
            for k in range(2501):
                if dp[i][j][k] > 0:
                    dp[i + 1][j][k] += dp[i][j][k]
                    dp[i + 1][j + 1][k + xl[i]] += dp[i][j][k]
    ans = 0
    for i in range(1,n+1):
        ans += dp[n][i][i*a]
    print(ans)


if __name__ == '__main__':
    main()

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

xn=[x[i]-A for i in range(len(x)) if x[i]<A]
xn.reverse()
x0=[0 for i in range(len(xn),len(x)) if x[i]==A]
xp=[x[i]-A for i in range(len(xn)+len(x0),len(x)) if x[i]>A]

sxn=[0]
sxn_n=[1]
for x in xn:
  sxn_add=[]
  sxn_n_i=[]
  for j in range(len(sxn)):
    sxn_tmp=sxn[j]+x
    for k in range(len(sxn)):
      if sxn[k]==sxn_tmp or k==len(sxn)-1:
        if sxn[k]==sxn_tmp:
          sxn_n_i.append([k,sxn_n[j]])
        else:
          sxn_add.append([sxn_tmp,sxn_n[j]])
        break
  for l in sxn_n_i:
    sxn_n[l[0]]+=l[1]  
  for k in sxn_add:
    sxn.append(k[0])
    sxn_n.append(k[1])
  

sxp=[0]
sxp_n=[1]
for x in xp:
  sxp_add=[]
  sxp_n_i=[]
  for j in range(len(sxp)):

    sxp_tmp=sxp[j]+x

    for k in range(j,len(sxp)):
      if sxp[k]==sxp_tmp or k==len(sxp)-1:

        if sxp[k]==sxp_tmp:
          sxp_n_i.append([k,sxp_n[j]])
        else:
          sxp_add.append([sxp_tmp,sxp_n[j]])
        break
  for l in sxp_n_i:
    sxp_n[l[0]]+=l[1]
  for k in sxp_add:
    sxp.append(k[0])
    sxp_n.append(k[1])




an=0
for i in range(1,len(sxp)):
  for j in range(1,len(sxn)):

    if sxp[i]==-sxn[j]:
      an+=sxp_n[i]*sxn_n[j]
      break


print(2**len(x0)-1+an*2**(len(x0)))

Solution (Python):
N, A = map(int, input().split())
X = sorted([int(x) for x in input().split()])
from collections import defaultdict , Counter
dp = defaultdict(Counter)

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

for i in range(1, N+1):
    x = X[i-1]
    k = 0
    update = []
    for s, counter in list(dp.items()):
        for nCard, count in counter.items():
            update.append((s+x, nCard+1, count))

    for key, value, diff in update:
        dp[key][value] += diff

def printCounter(counter):
    if len(counter) == 0:
        return ""
    return dict(counter)
if False:
    for s in range(0, max(X)*N):
        print("%2d" % s, "|", printCounter(dp[s]))

answer = 0
for s, counter in dp.items():
    q, r = divmod(s, A)
    if r != 0:
        continue
    answer += counter[q]
print(answer-1)

Solution (Python):
def C_TakandCards():
    from collections import Counter
    from collections import defaultdict
    N, A = map(int, input().split())
    x = list(map(int, input().split()))
    
    Y = [z - A for z in x]
    d = defaultdict(int)
    
    d[0] = 1
    
    for y in Y:
        for k, v in list(d.items()):
            d[k+y] += v
    print(d[0]-1)
    
if __name__ == "__main__":
    C_TakandCards()

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

dp = np.zeros((51, 5001), np.int64)  
dp[0, 2500] = 1   

for i in range(N):
    for j in range(5001):
        if dp[i, j] != 0:
            dp[i+1, j] += dp[i, j]
            dp[i+1, j+x[i]-A] += dp[i, j]
print(dp[N, 2500] - 1)

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


total = sum(x)
dp = [[[0] * (total + 1) for _ in range(n + 1)] for _ in range(n + 1)]
dp[0][0][0] = 1

for i in range(n):
    for j in range(n):
        for k in range(total + 1):
            if k + x[i] <= total:
                dp[i + 1][j + 1][k + x[i]] += dp[i][j][k]
            dp[i + 1][j][k] += dp[i][j][k]

ans = 0
for j in range(1, n + 1):
    for k in range(total + 1):
        if k / j == a:
            ans += dp[n][j][k]
print(ans)

Solution (Python):
num,ave = map(int,input().split())
numx = list(map(int,input().split()))

L = len(numx)
numy = [0] * L
for i in range(L):
    numy[i] = numx[i] - ave

if abs(min(numy)) < abs(max(numy)):
    maxX = max(numy)
else:
    maxX = abs(min(numy))

dp = [[0]*(2*maxX*L+1) for _ in range(L+1)]
dp[0][maxX*L] = 1
for i in range(L):
    for j in range(2*maxX*L+1):
        if (j-numy[i]) < 0 or (j - numy[i]) > 2*maxX*L:
          dp[i+1][j] = dp[i][j]
        else:
          dp[i+1][j] = dp[i][j] + dp[i][j-numy[i]]
print(dp[L][maxX*L]-1)

Solution (Python):
n,a = map(int,input().split())
*l, = map(int,input().split())
l = [i-a for i in l] 
dp_ll = [[0]*5001 for _ in range(n+1)] 
dp_ll[0][2500] = 1 
for i in range(0,n):
  for j in range(0,5001):
    if j-l[i] >= 0 and j-l[i] < 5001: 
      dp_ll[i+1][j] = dp_ll[i][j-l[i]]+dp_ll[i][j] 
print(dp_ll[n][2500]-1)

Solution (Python):
from collections import defaultdict

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

y = []
for xi in x:
    yi = xi - A
    y.append(yi)
X = max(x + [A])
NX = N * X

dp = defaultdict(int)
dp[(0, 0)] = 1
for i in range(N):
    for t in range(-NX, NX + 1):
        dp[(i + 1, t)] = dp[(i, t)] + dp[(i, t - y[i])]
print(dp[(N, 0)] - 1)

Solution (Python):
from collections import defaultdict

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

y = []
for xi in x:
    yi = xi - A
    y.append(yi)
X = max(x + [A])
NX = N * X

dp = defaultdict(int)
dp[(0, 0)] = 1
for i in range(N):
    for t in range(-NX, NX + 1):
        dp[(i + 1, t)] = dp[(i, t)] + dp[(i, t - y[i])]
print(dp[(N, 0)] - 1)

Solution (Python):


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

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

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

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


if __name__ == "__main__":
    solve()