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):

import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') 
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(sys.stdin.readline()) 
def ifn(): return float(sys.stdin.readline()) 
def isn(): return sys.stdin.readline().split() 
def imn(): return map(int, sys.stdin.readline().split()) 
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) 
def fmn(): return map(float, sys.stdin.readline().split()) 
def iln(): return list(map(int, sys.stdin.readline().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, sys.stdin.readline().split())) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime







N,A=imn()
x = iln()

X = 50



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

for j in range(N):
    for k in range(N):
        for s in range(N*X+1):
            
            if s-x[j] < 0:
                
                dp[j+1][k][s] = dp[j][k][s]
            else:
                
                
                
                dp[j+1][k+1][s] = dp[j][k+1][s] + dp[j][k][s-x[j]]


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

Solution (Python):

import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') 
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(sys.stdin.readline()) 
def ifn(): return float(sys.stdin.readline()) 
def isn(): return sys.stdin.readline().split() 
def imn(): return map(int, sys.stdin.readline().split()) 
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) 
def fmn(): return map(float, sys.stdin.readline().split()) 
def iln(): return list(map(int, sys.stdin.readline().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, sys.stdin.readline().split())) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,A=imn()
x = iln()
X = 50

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

for j in range(N):
    for k in range(N):
        for s in range(N*X+1):
            
            if s-x[j] < 0:
                dp[j+1][k][s] = dp[j][k][s]
            else:
            
                dp[j+1][k+1][s] = dp[j][k+1][s] + dp[j][k][s-x[j]]


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

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

dp = [[0 for t 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-1] < 0 or t-y[j] > 2*N*X):  
            dp[j][t] = dp[j-1][t]
        elif j >= 1 and 0 <= t-y[j-1] <= 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())
A=list(map(int,input().split()))
for i in range(n):
  A[i]=A[i]-a
B=[]
c=0
for i in range(n):
  if A[i]==0:
    c=c+1
  else:
    B.append(A[i])
n=len(B)
dp=[[0]*5010 for i in range(n+1)]
for i in range(1,n+1):
  dp[i]=dp[i-1][0:5010]
  dp[i][2505+B[i-1]]+=1
  for j in range(5010):
    if 0<=j+B[i-1] and j+B[i-1]<=5009:
      dp[i][j+B[i-1]]+=dp[i-1][j]
ans=dp[n][2505]
print((ans+1)*2**c-1)

Solution (Python):
from collections import defaultdict
import io

nim, mike = map(int, input().split())
kite = list(map(int, input().split()))
for i in range(nim):
    kite[i] -= mike
qwe = defaultdict(int)
qwe[0] = 1
for o in kite:
    for j, c in list(qwe.items()):
        qwe[j + o] += c
print(qwe[0]-1)

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

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



for i in range(n):    
    for j in range(i+1):
        for k in range(2501):

            dp[i+1][j][k] += dp[i][j][k]
            if k+l[i] < 2501:
                dp[i+1][j+1][k+l[i]] += dp[i][j][k]


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

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n,a = map(int, input().split())
    x = list(map(int, input().split()))
    for i in range(n):
        x[i] -= a
    dp = [[0]*5001 for _ in range(n+1)]

    dp[0][0] = 1

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

if __name__ == '__main__':
    main()

Solution (Python):
N, A = map(int, input().split())
x = list(map(int, input().split()))
dp = [[[0]*3000 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(3000):
            dp[i+1][j][k] += dp[i][j][k]
            
            if j+1<=N and k+x[i]<3000:
                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):
import sys
from collections import defaultdict

n, a, *x = map(int, sys.stdin.read().split())
for i in range(n): x[i] -= a

def main():
  dp = defaultdict(int); dp[0] = 1
  for i in range(n):
    ndp = dp.copy()
    for k, v in dp.items():
      ndp[k+x[i]] += v
    dp = ndp
  print(dp[0] - 1)
  
if __name__ == '__main__':
  main()

Solution (Python):
import sys
import numpy as np

n, a, *x = map(int, sys.stdin.read().split())

def main():
    dp = np.zeros((n + 1, 2501), dtype=np.int64)
    dp[0, 0] = 1
    for i in range(n):
        dp[1:, x[i]:] += dp[:-1, :-x[i]].copy()
    i = np.arange(1, n + 1)
    print(dp[i, i * a].sum())

if __name__ ==  '__main__':
    main()

Solution (Python):
import sys
import numpy as np

n, a, *x = map(int, sys.stdin.read().split())

def main():
    m = 2500
    dp = np.zeros((n + 1, m + 1), dtype=np.int64)
    dp[0, 0] = 1
    for i in range(n):
        dp[1:, x[i]:] += dp[:-1, :-x[i]].copy()
    i = np.arange(1, n + 1)
    print(dp[i, i * a].sum())

if __name__ ==  '__main__':
    main()

Solution (Python):
import sys
import numpy as np

n, a, *x = map(int, sys.stdin.read().split())

def main():
    m = 2500
    dp = np.zeros((n + 1, m + 1), dtype=np.int64)
    dp[0, 0] = 1
    for i in range(n):
        ndp = np.copy(dp)
        ndp[1:, x[i]:] += dp[:-1, :m-x[i]+1]
        dp = ndp
    i = np.arange(1, n + 1)
    print(np.sum(dp[i, i * a]))

if __name__ ==  '__main__':
    main()

Solution (Python):
import sys
import numpy as np

n, a, *x = map(int, sys.stdin.read().split())

def main():
    m = 2500
    dp = np.zeros((n + 1, m + 1), dtype=np.int64)
    dp[0, 0] = 1
    for i in range(n):
        ndp = np.copy(dp)
        for j in range(1, n + 1):
            ndp[j][x[i]:] += dp[j-1][:m-x[i]+1]
        dp = ndp
    i = np.arange(1, n + 1)
    print(np.sum(dp[i, i * a]))

if __name__ ==  '__main__':
    main()

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

xmax=max(max(x),a)
    
nx=n*xmax
dp=[[[0]*(nx+1) for ii in range(n+1)] for i in range(n+1)]

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

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


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

Solution (Python):
n,a = map(int, input().split())
X = list(map(int, input().split()))
x = [i-a for i in X]
dp = [[0]*5201 for i in range(n+1)]
dp[0][2600] = 1 
for i,xi in enumerate(x):
  for k in range(99,5101):
    dp[i+1][k+xi] += dp[i][k] 
    dp[i+1][k] += dp[i][k]
ans = dp[n][2600] - 1
print(ans)

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

for i in range(n):
    x[i]=x[i]-a
    
nx=n*n
dp=[[0]*(2*nx+1) for i in range(n+1)]



dp[0][nx]=1

for j in range(1,n+1):
    jj=j-1
    for t in range(2*nx+1):
        if t-x[jj]<0 or 2*nx<t-x[jj]:
            dp[j][t]=dp[j-1][t]
        elif 0<t-x[jj] and  t-x[jj]<2*nx:
            dp[j][t]=dp[j-1][t]+dp[j-1][t-x[jj]]
        else:
            dp[j][t]=0

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

Solution (Python):










def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:
    return a
  return gcd_(a,a % b) 
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


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

def main():
  n,a = readInts()
  
  X = readInts()
  
  X = list(map(lambda i: i-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)
  
if __name__ == '__main__':
  main()

Solution (Python):
from collections import defaultdict

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

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

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

print(d[0]-1)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,a = map(int,readline().split())
lst1 = list(map(int,readline().split()))

import numpy as np

dp = np.zeros((n+1,3000),dtype=np.int64) 
dp[0,0] = 1

for x in lst1:
  dp[1:,x:] += dp[:-1,:-x].copy()
  
ans = 0
for i in range(1,n+1):
  ans += dp[i,i*a]
  
print(ans)

Solution (Python):
def solve(n, a, lst):
  m = max(max(lst), a)
  ans = [[[0]*(n*m+1) for i in range(n+1)] for j in range(n+1)]
  
  for i in range(n+1):
    for j in range(n+1):
      for k in range(n*m+1):
        if i == 0 and j == 0 and k == 0:
          ans[i][j][k] = 1
        elif i >= 1 and k < lst[i-1]:
          ans[i][j][k] = ans[i-1][j][k]
        elif i >= 1 and lst[i-1] <= k and j >= 1:
          ans[i][j][k] = ans[i-1][j-1][k-lst[i-1]] + ans[i-1][j][k]
        else:
          ans[i][j][k] = 0
  ret = 0
  for i in range(1,n+1):
    ret += ans[-1][i][i*a]
  return int(ret)

if __name__ == "__main__":
  n, a = map(int,input().split())
  x_list = [int(i) for i in input().split()]
  ans = solve(n,a,x_list)
  print(ans)

Solution (Python):

import sys
input = sys.stdin.readline









N,A = map(int,input().split())
X = [0] + list(map(int,input().split())) 


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

for n in range(N+1):
    for k in range(n+1):
        for d in range(50*k+1):
            
            if d < X[n]:
                dp[n][k][d] = dp[n-1][k][d]
            
            else:
                
                if k >= 1:
                    dp[n][k][d] = dp[n-1][k][d] + dp[n-1][k-1][d-X[n]]
                    
                    

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

print(ans)

Solution (Python):
from collections import defaultdict

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

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

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

Solution (Python):
import numpy as np
 
n, a = map(int, input().split())
x = np.array(list(map(int, input().split())))
 
dp = {0:1}
for y in x-a:
    for k, v in dp.copy().items():
        dp[y+k] = dp.get(y+k, 0) + v 
print(dp[0]-1)

Solution (Python):
import numpy as np

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

dp = {0:1}
for y in x-a:
    for k, v in dp.copy().items():
        dp[y+k] = dp.get(y+k, 0) + v

print(dp[0]-1)

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

dp = {0 : 1}

for n in nums:
	for k, v in list(dp.items()):
		dp[k+n] =dp.get(k+n, 0) + v
print(dp[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]*5000
dp[2500] = 1

for i in range(N):
    pre = dp[:]
    for j in range(max(0,-x[i]),min(4999,4999-x[i])):
        dp[j+x[i]] += pre[j]
    
    


print(dp[2500]-1)

Solution (Python):


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


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

            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]
ans = 0
for k in range(1,n+1):
    ans += dp[n][k][k*a]

print(ans)

Solution (Python):


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


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

            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]
ans = 0
for k in range(1,n+1):
    ans += dp[n][k][k*a]

print(ans)

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

dp = [[[0]*(n*X+1) for _ in range(n+1)] for i 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 < 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
ans = 0
for k in range(1,n+1):
    ans += dp[n][k][k*a]
print(ans)

Solution (Python):
N,A=map(int,input().split())
x=list(map(int,input().split()))
dp=[[[0]*2600 for j in range(N+10)] for i in range(N+10)]
dp[0][0][0]=1
for i in range(N):
    for j in range(N+1):
        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+x[i]]+=dp[i][j][k]
print(sum(dp[N][i][i*A] for i in range(1,N+1)))

Solution (Python):



'''
解説満点解法1
もしもk枚選んだとき、合計がsになる通りの数がわかったら？→s=k*Aとなる場合の数の合計をすれば良い

k枚選んだとき、合計がsになる通りの数は典型的なDP！
dp(j,k,s)... X[0:j]からk枚選んで、その合計をsにするような選び方の総数
と定義すると、

更新則
dp(j+1,k,s) = X[j]を選んだ結果sになったときの通りの数 + X[j]を選ばずにsになっている通りの数 なので
すなわち
dp(j+1,k,s) = dp(j,k-1,s-X[j]) + dp(j,k,s)

あとは初期条件と境界条件と伝播条件を付け加える。
境界条件 dp(j,k,0)=0 (数枚選んで合計が0になるのはありえない)
初期条件 dp(j,0,0)=1 (ただし、0枚選んだときは1通りとなる)(s-X[j]=0のときに1通りとなってほしいという気持ちもある)
伝播条件 s-X[j]<0に関しては dp(j,k-1,s-X[j])が必ず0通りとなる(ありえないので)
'''

import sys
read = sys.stdin.readline
from itertools import product


def read_ints():
    return list(map(int, read().split()))


N, A = read_ints()
X = read_ints()























'''
満点解法2
平均値の特性からXから差っ引けば、選んだカードの合計が0になれば良くなる。Y=X-Aと定義する。
→そしたらYからいくつか選んで合計tをつくる総数をdpで求めれば良い。(ナップザックDPとコインDPの中間！)

0枚以上選んだときに合計がtに成るかどうか考える

dp(j,t)...Y[:j]の中から0枚以上選んで、その合計を(t-NX)(負になる可能性もあるだけ)にするような選び方の総数
dp(j,t+NX)...Y[:j]の中から0枚以上選んで、その合計をtにするような選び方の総数 この定義のほうがいいかな

更新則
dp(j+1,t+NX) = Y[j]を選んで合計がtになる総和 + Y[j]を選ばずに合計がtになっている総和
つまり
dp(j+1,t+NX) = dp(j,t+NX - Y[j]) + dp(j,t+NX)

境界条件
dp(0,t+NX)=0  一つも考慮しない状態では必ずスコアは作れない
初期条件
dp(0,0+NX)=1 ∵ただし一つも考慮しないならば合計が0になるのは当然1通り
伝播条件
0<=t+NX-Y[j]<=2NXとなる範囲外の場合はdp(j,t+NX - Y[j])を無視 
'''




S = sum(X)

Y = []
for x in X:
    Y.append(x - A)
dp = [[0] * (2 * S + 1) for _ in range(N + 1)]


dp[0][S] = 1

for j, t in product(range(N), range(-S, S + 1)):
    ts = t + S
    dp[j + 1][ts] = dp[j][ts]
    dp[j + 1][ts] += dp[j][ts - Y[j]] if 0 <= ts - Y[j] <= 2 * S else 0

print(dp[N][S] - 1)

Solution (Python):



'''
解説満点解法1
もしもk枚選んだとき、合計がsになる通りの数がわかったら？→s=k*Aとなる場合の数の合計をすれば良い

k枚選んだとき、合計がsになる通りの数は典型的なDP！
dp(j,k,s)... X[0:j]からk枚選んで、その合計をsにするような選び方の総数
と定義すると、
dp(j+1,k,s) = X[j]を選んだ結果sになったときの通りの数 + X[j]を選ばずにsになっている通りの数 なので
dp(j+1,k,s) = dp(j,k-1,s-X[j]) + dp(j,k,s)

あとは初期条件と境界条件と伝播条件を付け加える。
境界条件 dp(j,k,0)=0 (数枚選んで合計が0になるのはありえない)
初期条件 dp(j,0,0)=1 (ただし、0枚選んだときは1通りとなる)(s-X[j]=0のときに1通りとなってほしいという気持ちもある)

伝播条件 s-X[j]<0に関しては dp(j-1,k-1,s-X[j])が必ず0通りとなる(ありえないので)
'''

import sys
read = sys.stdin.readline
from itertools import product


def read_ints():
    return list(map(int, read().split()))


N, A = read_ints()
X = read_ints()
S = sum(X)


dp = [[[0] * (S + 1) for _ in range(N + 1)] for _ in range(N + 1)]
for j in range(N + 1):  
    dp[j][0][0] = 1  


for j, k, s in product(range(N), range(1, N + 1), range(S + 1)):
    dp[j + 1][k][s] = dp[j][k][s] + \
        (0 if s - X[j] < 0 else dp[j][k - 1][s - X[j]])


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


print(ans)


'''
満点解法2


'''

Solution (Python):
"""
kari1 = '4 8'
kari2 = '7 9 8 9' 






n, a = map(int, kari1.split())
x_a = list(map(lambda x: int(x) - a, kari2.split()))
"""
n, a = map(int, input().split())
x_a = list(map(lambda x: int(x) - a, input().split()))
dic = dict()
dic[0] = 1

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

print(dic[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 = [[0]*(2*n*X+1) for _ in range(n+1)]

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

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

Solution (Python):
from collections import Counter
n,a=map(int,input().split())
X=sorted(list(map(lambda x:int(x)-a,input().split())))
ans=Counter([0])
for x in X:
    tmp=Counter()
    for i,j in ans.items():
        tmp[i+x]+=j
    ans+=tmp
print(ans[0]-1)

Solution (Python):
import sys
input=sys.stdin.readline
n,a=map(int,input().split())
x=[0]+list(map(int,input().split()))
su=sum(x)
maxi=max(x)
dp=[[[0 for k in range(maxi*n+1)] for j in range(51)] for i in range(51)]
dp[0][0][0]=1
for i in range(1,n+1):
    for j in range(i+1):
        for k in range(maxi*j+1):
            if k<x[i]:
                dp[i][j][k]=dp[i-1][j][k]
            if k>=x[i] and j>=1:
                dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]]
ans=0
for t in range(1,n+1):
    if a*t<=su:
        ans+=dp[n][t][a*t]
    else:
        break
print(ans)

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

m = a * n


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


for xk in x:
    
    dpk = [dp[i][:] for i in range(m+1)]
    for i in range(m+1):
        if i - xk >= 0:
            for j in range(1,n+1):
                dpk[i][j] += dp[i-xk][j-1]
    dp = dpk

ans = 0

for i in range(1,m+1):
    for j in range(1,n+1):
        if i / j == a:
            ans += dp[i][j]

print(ans)

Solution (Python):
N,A=map(int,input().split())
l=list(map(int,input().split()))
d={}
def func(n,s,i):
	if n<0:
		return
	if (n,s,i) in d:
		return
	if n==0:
		if s==0:
			d[(n,s,i)]=1
		else:
			d[(n,s,i)]=0
		return
	if i>=N:
		if s==0 and n==0:
			d[(n,s,i)]=1
		else:
			d[(n,s,i)]=0

		return
	else:
		func(n-1,s-l[i],i+1)
		func(n,s,i+1)
		d[(n,s,i)]=d[(n-1,s-l[i],i+1)]+d[(n,s,i+1)]
ans=0
for j in range(1,N+1):
	func(j,j*A,0)
	ans+=d[(j,j*A,0)]
print(ans)

Solution (Python):
N,A=map(int, input().split())
X=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+1):
    for k in range(2501):
      if not dp[i][j][k]:
        continue
      dp[i+1][j][k]+=dp[i][j][k]
      if j<N:
        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=list(map(int,input().split()))
ans=0
dp=[[[0]*(sum(x)+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0]=1
for i in range(n+1):
  for j in range(i+1):
    for k in range(sum(x)+1):
      if i>=1 and k>=x[i-1] and j>=1:
        dp[i][j][k]=dp[i-1][j-1][k-x[i-1]]+dp[i-1][j][k]
      elif i>=1:
        dp[i][j][k]=dp[i-1][j][k]
for j in range(1,n+1):
  for k in range(sum(x)+1):
    if k%j==0 and k//j==a:
      ans+=dp[n][j][k]
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
INF = 10**10
MOD = 10**9 + 7
sys.setrecursionlimit(100000000)
from functools import lru_cache
from itertools import permutations
from math import factorial


def main():
    n,a = map(int,input().split())
    x = list(map(int,input().split()))
    dp = [[[0] * (n * a + 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(n):
        num = x[i]
        for j in range(1,n + 1):
            for s in range(n * a + 1):
                if s - num >= 0:
                    dp[i + 1][j][s] = dp[i][j][s] + dp[i][j - 1][s - num]
                else:
                    dp[i + 1][j][s] = dp[i][j][s]
    
    ans = 0
    for i in range(1,n + 1):
        ans += dp[-1][i][i * a]
    print(ans)
    

if __name__=='__main__':
    main()

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

x.sort()
x = [i - a for i in x]

D = {0 : 1}
for i in x:
    for j, k in list(D.items()):
        D[i+j] = D.get(i+j, 0) + k

    
print(D[0] - 1)

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

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

for i, x_i in enumerate(x):
    for p in dp[i].keys():
        pk = p + a - x_i
        dp[i+1][pk] += dp[i][p]
        dp[i+1][p] += dp[i][p]

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

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,A=MI()
    x=LI()
    M=max(x)
    
    
    dp=[[[0]*(N*M+1) for j in range(N+1)] for _ in range(N+1)]
    dp[0][0][0]=1
    
    for i in range(N):
        for j in range(i+1):
            for k in range(N*M+1-x[i]):
                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 j in range(1,N+1):
        if j*A<=N*M:     
            ans+=dp[-1][j][j*A]
        
    print(ans)
 

                
    
        
            
            
    
            
        
        
            

main()

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

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

for i, x_i in enumerate(x):
    for p in dp[i].keys():
        
        pk = p + a - x_i
        dp[i+1][pk] += dp[i][p]
        
        dp[i+1][p] += dp[i][p]

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

Solution (Python):
import sys
import numpy as np
N, A = map(int, input().split())
X = np.array(list(map(int, input().split())))
x = X - A
R = 5001
dp = np.zeros([N, R], np.int64)
dp[0][(R-1)//2] += 1
dp[0][(R-1)//2 + x[0]] += 1

for i in range(1,N):
	for j in range(R):
		if 0 <= j-x[i] <= R-1:
			dp[i][j] = dp[i-1][j] + dp[i-1][j-x[i]]
		else:
			dp[i][j] = dp[i-1][j]
print(dp[N-1][(R-1)//2]-1)

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

x.sort()
x = [i - A for i in x]
D = {0 : 1}
for i in x :
    for j, k in list(D.items()) :
        D[i+j] = D.get(i+j, 0) + k

print(D[0] - 1)

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

x.sort()
x = [v - A for v in x]

dp = [0] * 5001
for v in x:
    for i in range(2501) if v < 0 else range(5000, -1, -1):
        if dp[i] == 0:
            continue
        dp[i + v] += dp[i]
    dp[2500 + v] += 1
print(dp[2500])

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

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

for i in range(1, N):
  for s in range(2*OFS+1):
    t = s-(X[i]-A)
    if t < 0 or t > 2*OFS:
      dp[i][s] = dp[i-1][s]
    else:
      dp[i][s] = dp[i-1][s] + dp[i-1][t]

      
print(dp[N-1][OFS]-1)

Solution (Python):
n,a=map(int,input().split())
x=list(map(int,input().split()))
l=max(max(x)*n+3,a*n+3)
dp=[[l*[0]for _ 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(l):dp[i][j][k]=dp[i-1][j][k]
  for j in range(1,i+1):
    for k in range(x[i-1],l):dp[i][j][k]+=dp[i-1][j-1][k-x[i-1]]
ans=0
for j in range(1,n+1):
  ans+=dp[-1][j][j*a]
print(ans)

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

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

'''
辞書がめっちゃ書きやすい！ただし、3次元配列でdpやりたい時むずいかも。
x = [i-a for i in x]
dp = {0:1}
print(dp)
for item in x:
    print('--------for item:{}-----------'.format(item))
    for key, value in list(dp.items()):
        print('key:{},value:{}'.format(key,value))
        dp[item + key] = dp.get(item + key, 0) + value
        print(dp)
print(dp[0]-1)
'''

diff = [i-a for i in x]
ma = max(max(x),a)

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





dp[0][n*ma] = 1


for l in range(0,n):
    
    
    for m in range(2*n*ma+1):
        if abs(m - diff[l]) > 2*n*ma:
            dp[l+1][m] = dp[l][m]
            
        else:
            dp[l+1][m] = dp[l][m] + dp[l][m - diff[l]]
print(dp[n][n*ma]-1)



'''
countzero = len([i for i in diff if i == 0])

over = sorted([i for i in diff if i > 0])
under = sorted([i for i in diff if i < 0])


countover = [0 for i in range(50)]
countunder = [0 for i in range(50)]
for item in set(over):
    countover[item-1] = over.count(item)
for item in set(under):
    countunder[item] = under.count(item)
countunder = sorted(countunder)

valover = [countover[0]]
valunder = [countunder[0]]

for i in range(1,2500):
    plus = 0
    minus = 0
    if i%2 == 0:
        plus = countover[int(i/2)]*(countover[int(i/2)]-1)/2
        minus = countunder[int(i/2)]*(countunder[int(i/2)]-1)/2
    for j in range(int(i/2)):
        plus += countover[i]*countover[-i]
        minus += countunder[i]*countunder[-i]
    valover.append(plus)
    valunder.append(minus)

plusminus = 0
for i in range(2500):
    plusminus += valover[i]*valunder[i]

print((plusminus+1)*2**(countzero)-1)
'''

Solution (Python):
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7

N, A = MI()
X = LMI()


dp = [[[0] * 2502 for _ in range(N + 2)] for _ in range(N + 1)]
for i in range(N):
    dp[i][0][0] = 1
dp[0][1][X[0]] = 1
for i in range(1, N):
    for j in range(1, i + 2):
        for s in range(A * N + 1):
            if s - X[i] < 0:
                dp[i][j][s] = dp[i - 1][j][s]
            else:
                dp[i][j][s] = dp[i - 1][j][s] + dp[i - 1][j - 1][s - X[i]]

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

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

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

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

for i in range(1, N + 1):
    for j in range(-2500, 2501):
        if 5000 >= j + 2500 - x[i - 1] >= 0:
            dp[i][j + 2500] = dp[i - 1][j + 2500 - x[i - 1]] + dp[i - 1][j + 2500]
        else:
            dp[i][j + 2500] = dp[i - 1][j + 2500]

print(dp[N][0 + 2500] - 1)