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

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools, random
from collections import deque
from heapq import heappush, heappop
sys.setrecursionlimit(10 ** 7)
ans = 0
tmp = 0
inf = 10 ** 20
INF = float("INF")
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
ddn9 = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n, a = wi()
x = wi()
X = max(x)
dp = [[[0] * (n + 1) for j in range(X * n + 2)] for i in range(n)]
dp[0][0][0] = 1
dp[0][x[0]][1] = 1

for p in range(1, n):
    for k in range(X * n + 2):
        for usenum in range(n):
            dp[p][k][usenum] += dp[p - 1][k][usenum]
            if k - x[p] >= 0:
                dp[p][k][usenum + 1] += dp[p - 1][k - x[p]][usenum]

for k in range(X * n + 2):
    for usenum in range(n + 1):
        if usenum != 0:
            if k / usenum == a:
                ans += dp[n - 1][k][usenum]
print(ans)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools, random
from collections import deque
from heapq import heappush, heappop
sys.setrecursionlimit(10 ** 7)
ans = 0
tmp = 0
inf = 10 ** 20
INF = float("INF")
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
ddn9 = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n, a = wi()
x = wi()
X = max(x)
dp = [[[0] * (n + 1) for j in range(X * n + 2)] for i in range(n)]
dp[0][0][0] = 1
dp[0][x[0]][1] = 1

for p in range(1, n):
    for k in range(X * n + 2):
        for usenum in range(p + 1):
            dp[p][k][usenum] += dp[p - 1][k][usenum]
            if k - x[p] >= 0:
                dp[p][k][usenum + 1] += dp[p - 1][k - x[p]][usenum]

for k in range(X * n + 2):
    for usenum in range(n + 1):
        if usenum != 0:
            if k / usenum == a:
                ans += dp[n - 1][k][usenum]
print(ans)

Solution (Python):
N,A = map(int,input().split())
*X, = map(int,input().split())
dp=[[[0]*2510 for _ in [0]*(N+10)] for _ in [0]*(N+10)]
for n in range(0,N+1):dp[n][0][0] = 1
for n in range(1,N+1):
    x = X[n-1]
    for k in range(1,n+1):
        for s in range(2501):
            dp[n][k][s] = dp[n-1][k][s]
            if s>=x:
                dp[n][k][s] += dp[n-1][k-1][s-x]
print(sum(dp[N][k][k*A] for k in range(1,N+1)))

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

max_num = max(x)
max_num = max(A, max_num)

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

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

for j in range(N+1):
  for k in range(j+1):
    for s in range(max_num * k + 1):
      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]]
 

ans = 0

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

Solution (Python):
def main():
	N, A = map(int, input().split())
	x = list(map(int, input().split()))
	X = A
	for xi in x:
		X = max(X, xi)
	y = [xi-A for xi in x]
	dp = [[0 for _ in range(2*N*X+1)] for _ in range(N+1)]
	dp[0][N*X] = 1
	for j in range(1, N+1):
		for t in range(2*N*X):
			if t - y[j-1] < 0 or t - y[j-1] > 2*N*X:
				dp[j][t] = dp[j-1][t]
			else:
				dp[j][t] = dp[j-1][t] + dp[j-1][t-y[j-1]]
	print(dp[N][N*X]-1)


if __name__ == '__main__':
	main()

Solution (Python):
def solve():
  n,a = (int(i) for i in input().split())
  x = list(int(i) for i in input().split())
  tp = max(x)
  if tp < a:
    print(0)
    exit()
  
  dp = [[[0 for i in range(n*tp +1)] for j in range(n+1)] for k in range(n+1)]
  query = a*n
  dp[0][0][0] = 1
  for i in range(1,n+1):
    for j in range(n+1):
      for k in range(n*tp +1):
        
        dp[i][j][k] = dp[i-1][j][k]
        if x[i-1] <= k and j > 0:
         dp[i][j][k] += dp[i-1][j-1][k-x[i-1]]
        
  ans = 0
  for j in range(1,n+1):
    ans += dp[n][j][j*a]
  
  print(ans)
  
  
  
  
  
  
solve()

Solution (Python):
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    N, A = map(int, input().split())
    X = [int(c) - A for c in input().split()]
    d = defaultdict(lambda: 0)

    for x in X:
        d_ = defaultdict(lambda: 0)
        for key in d.keys():
            d_[key + x] += d[key]

        for key in d_.keys():
            d[key] += d_[key]

        d[x] += 1

    return d[0]


if __name__ == '__main__':
    print(main())

Solution (Python):
N,A=map(int, input().split())
x=list(map(int, input().split()))
dp = [[[0]*(51*51) for _ in range(N+1)] for _ in range(N+1)]

for j in range(N+1):
    for k in range(j+1):
        for s in range(51*51):
            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 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()))
dp = [[[0]*(51*51) 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(51*51):
            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 i in range(1, N+1):
    ans+= dp[N][i][i*A]
print(ans)

Solution (Python):
def main():
    N, A = map(int, input().split())
    *X, = map(int, input().split())

    ans = editorial_3d(N, A, X)
    ans2 = editorial_2d(N, A, X)
    assert ans == ans2
    if N <= 16:
        ans3 = part(N, A, X)
        assert ans == ans3

    print(ans)


def editorial_3d(N, A, X):
    """
    dp[N][N][sum]
    N枚の選択肢, N枚選ぶ, 合計値
    """
    max_sum = N * A
    dp = [[None] for _ in range(N+1)]
    for i in range(N+1):
        tmp = [[0] * (2 * max_sum + 1) for _ in range(N+1)]
        dp[i] = tmp
    
    dp[0][0][0] = 1

    for i in range(1, N+1):
        for j in range(0, N+1):
            for k in range(max_sum + 1):
                v = dp[i-1][j][k]
                if k >= X[i-1] and j >= 1:
                    v += dp[i-1][j-1][k - X[i-1]]

                dp[i][j][k] = v

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

    return ans


def editorial_2d(N, A, X):
    """
    dp[N][sum]
    N枚の選択肢, 合計値
    """
    
    
    max_sum = 2 * (N * 50)
    dp = [[0] * (max_sum + 1) for _ in range(N+1)]
    
    dp[0][max_sum // 2] = 1

    for i in range(1, N+1):
        for k in range(max_sum + 1):
            v = dp[i-1][k]
            s = k - (X[i-1] - A)
            if 0 <= s <= max_sum:
                v += dp[i-1][s]

            dp[i][k] += v

    
    
    
    
    
    ans = dp[N][max_sum // 2] - 1

    return ans


def part(N, A, X):
    import sys
    sys.setrecursionlimit(10 ** 7)
    a = [0] * N

    def rec(i, n):
        ans = 0
        if i == n:
            s = 0
            c = 0
            
            for j, b in enumerate(a):
                if b == 1:
                    s += X[j]
                    c += 1

            if c == 0:
                return 0
            if s / c == A:
                return 1
            else:
                return 0

        a[i] = 0
        ans += rec(i + 1, n)
        a[i] = 1
        ans += rec(i + 1, n)

        return ans

    ans = rec(0, N)
    return ans


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N, A = map(int, input().split())
    *X, = map(int, input().split())

    ans = editorial_3d(N, A, X)
    
    
    if N <= 16:
        ans3 = part(N, A, X)
        assert ans == ans3

    print(ans)


def editorial_3d(N, A, X):
    """
    dp[N][N][sum]
    N枚の選択肢, N枚選ぶ, 合計値
    """
    max_sum = N * A
    dp = [[None] for _ in range(N+1)]
    for i in range(N+1):
        tmp = [[0] * (max_sum + 1) for _ in range(N+1)]
        dp[i] = tmp
    dp[0][0][0] = 1

    for i in range(1, N+1):
        for j in range(0, N+1):
            for k in range(max_sum + 1):
                v = dp[i-1][j][k]
                if k >= X[i-1] and j >= 1:
                    v += dp[i-1][j-1][k - X[i-1]]

                dp[i][j][k] = v

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

    return ans


def editorial_2d(N, A, X):
    """TODO
    dp[N][sum]
    N枚の選択肢, 合計値
    """
    max_sum = N * A
    dp = [[0] * (2 * max_sum + 1) for _ in range(N+1)]
    dp[0][0] = 1

    for i in range(1, N+1):
        for k in range(max_sum, 2 * max_sum + 1):
            v = dp[i-1][k]
            if k >= X[i-1] - A:
                v += dp[i-1][k - X[i] - A]

            dp[i][k] = v

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

    return ans


def part(N, A, X):
    import sys
    sys.setrecursionlimit(10 ** 7)
    a = [0] * N

    def rec(i, n):
        ans = 0
        if i == n:
            s = 0
            c = 0
            
            for j, b in enumerate(a):
                if b == 1:
                    s += X[j]
                    c += 1

            if c == 0:
                return 0
            if s / c == A:
                return 1
            else:
                return 0

        a[i] = 0
        ans += rec(i + 1, n)
        a[i] = 1
        ans += rec(i + 1, n)

        return ans

    ans = rec(0, N)
    return ans


if __name__ == '__main__':
    main()

Solution (Python):
n,a=map(int,input().split())
x=list(map(int,input().split()))
X=max(max(x),a)
dp=[[[0]*(X*n+1)for j in range(n+1)]for i in range(n+1)]
dp[0][0][0]=1
for i in range(1,n+1):
  xi=x[i-1]
  for j in range(i+1):
      for h in range(j*X+1):
        if h<xi:dp[i][j][h]=dp[i-1][j][h]
        if xi<=h and j>=1:dp[i][j][h]=dp[i-1][j][h]+dp[i-1][j-1][h-xi]
ans=0
for j in range(1,n+1):ans+=dp[n][j][j*a]
print(ans)

Solution (Python):

N,A=map(int,input().split())
x=[int(i) for i in input().split()]
dp=[[[0]*(50*N+1) for i in range(N+1)]for k in range(N+1)]
ans=0
dp[0][0][0]=1
for made,i in enumerate(dp):
    if made>N:break
    for maisu,j in enumerate(i):
        for wa,k in enumerate(j):
            if k and made<N:
                dp[made+1][maisu][wa]+=k
                newwa=wa+x[made]
                if newwa<=A*N:
                    dp[made+1][maisu+1][newwa]+=k
for mai in range(1,N+1):
    a=dp[N][mai][mai*A]
    if a:
        ans+=a
print(ans)

Solution (Python):
def tak_and_cards(N: int, A: int, X: list) -> int:
    
    
    
    
    
    
    
    
    
    

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

    for k, x in enumerate(X):
        for t in range(2 * max_X * N + 1):
            y = x - A

            dp[k + 1][t] = dp[k][t]
            if 0 <= t - y and t - y <= 2 * max_X * N:
                dp[k + 1][t] += dp[k][t - y]

    return dp[N][max_X*N] - 1


if __name__ == "__main__":
    N, A = map(int, input().split())
    x = [int(s) for s in input().split()]
    ans = tak_and_cards(N, A, x)
    print(ans)

Solution (Python):
n,a=map(int,input().split())
x=list(map(int,input().split()))
stack=[0]*5001
stack[2500]=1
for i in range(len(x)):
  x[i]-=a
for i in x:
  stack2=[i for i in stack]
  for j in range(5001):
    if 0<=j+i<=5000:
      stack2[j+i]+=stack[j]
  stack=[i for i in stack2]
print(stack[2500]-1)

Solution (Python):
n,a=map(int,input().split())
x=list(map(int,input().split()))
stack=[0]*5001
stack[2500]=1
ans=0
for i in range(len(x)):
  x[i]-=a
for i in x:
  ans+=stack[2500-i]
  stack2=[i for i in stack]
  for j in range(5001):
    if 0<=j+i<=5000:
      stack2[j+i]+=stack[j]
  stack=[i for i in stack2]
print(stack[2500]-1)

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

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

X = max(max(x), A)

















dp = [[0]*(2*N*X+1) for _ in range(N+1)]
y = [0] * len(x)
for i in range(len(x)):
	y[i] = x[i]-A

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

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

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

X = max(max(x), A)

















dp = [[0]*(2*N*X+1) for _ in range(N+1)]
y = [0] * len(x)
for i in range(len(x)):
	y[i] = x[i]-A

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 0 <= 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 = map(int,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]]

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

Solution (Python):
from functools import reduce

def main():
    
    
    
    
    

    
    
    N, A = [int(_) for _ in input().split()]
    X = [int(_) for _ 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 n in range(N+1):
        for k in range(n+1):
            for s in range(50*k+1):
                if(n>=1 and s<X[n-1]):
                    dp[n][k][s] = dp[n-1][k][s]
                if(n>=1 and s>=X[n-1]):
                    dp[n][k][s] = dp[n-1][k][s] + dp[n-1][k-1][s-X[n-1]]

    Ans = 0
    for i in range(1,N+1):
        Ans += dp[N][i][i*A]
 
    print(Ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
from scipy.ndimage import shift

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

dp = [np.array([[0]*(N*A+1) for _ in range(N+1)])]


for x in X:
  new_dp = dp[-1].copy()
  new_dp += shift(dp[-1], [1,x])
  if x<=N*A:
    new_dp[1, x] += 1
  
  dp.append(new_dp)

  
print(sum([dp[-1][i, i*A] for i in range(1, N+1)]))

Solution (Python):
import numpy as np

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

dp = [np.array([[0]*(N*A+1) for _ in range(N+1)])]


for x in X:
  new_dp = dp[-1].copy()
  new_dp[1:, x:] += dp[-1][0:N, 0:N*A+1-x]
  if x<=N*A:
    new_dp[1, x] += 1
  
  dp.append(new_dp)

  
print(sum([dp[-1][i, i*A] for i in range(1, N+1)]))

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


if __name__ == "__main__":
    main()

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

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

xs = {0: 1}

for n in X:
    
    kv = list(xs.items())
    for k, v in kv:
        nk = k + n - A
        xs[nk] = xs.get(nk, 0) + v



result = xs[0] - 1

print(result)

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


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

for i in range(0,n):
  j = x[i]%a
  kuwaeru = x[i]//a
  num = 0
  while num<=i:
    for k in range(a):
      for l in range(sho+1):
        if k+j<a and l+kuwaeru <= sho:
          dp[i+1][num+1][(k+j)%a][l+kuwaeru] += dp[i][num][k][l]  
        elif k+j>=a and l+kuwaeru+1 <= sho:
          dp[i+1][num+1][(k+j)%a][l+kuwaeru+1] += dp[i][num][k][l]  
  
        dp[i+1][num][k][l] += dp[i][num][k][l]  
    num +=1

ans = 0
for i in range(1,min(sho+1,n+1)):
  ans +=  dp[n][i][0][i]
print(ans)

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007






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

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

    sum_max = (n)*(max(x))+1

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

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


if __name__ == "__main__":
    main()

Solution (Python):
N, A = map(int, input().split())
X = list(map(int, input().split()))
X.insert(0, 0)
dp = [[[0 for _ in range(N+1)] for _ in range(N+1)] for _ in range(sum(X)+1)]

dp[0][0][0] = 1
for i in range(sum(X) + 1):
    for j in range(1, N + 1):
        for k in range(N + 1):
            if i - X[j] >= 0 and k >= 1:
                dp[i][j][k] = dp[i][j - 1][k] + dp[i - X[j]][j - 1][k - 1]
            else:
                dp[i][j][k] = dp[i][j - 1][k]
                
res = 0

for k in range(1, N + 1):
    if A * k <= sum(X):
        res += dp[A*k][N][k]
                
print(res)

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

maxx = max(x)
maxx = max(maxx, a)

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

for j in range(n + 1):
    for k in range(j + 1):
        for s in range(maxx * k + 1):
            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]]

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()))
res=[[0  for i in range(max(1+a*n,1+sum(x)))] for j in range(n+1)]
res[0][0]+=1
for i in range(n):
    for k in range(sum(x),0,-1):
        if k-x[i]<0:continue
        for j in range(1,i+2):
            res[j][k]+=res[j-1][k-x[i]]
ans=0
for i in range(1,n+1):
    ans+=res[i][a*i]
print(ans)

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

X = [int(x) - A for x in input().split()]
dp = [[0 for _ in range(100*N+1)] for _ 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)

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 k,v in ans.items():
    tmp[k+x]+=v
  ans+=tmp
print(ans[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]

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

print(c[0]-1)

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




s_max = 2500
dp = [[[0]*(s_max+1) for k in range(N+1)] for i in range(N+1)]
dp[0][0][0] = 1
for i in range(1,N+1):
    for k in range(N+1):
        for s in range(s_max+1):
            dp[i][k][s] += dp[i-1][k][s]
            if k != 0 and 0 <= s-X[i-1] <= s_max:
                dp[i][k][s] += dp[i-1][k-1][s-X[i-1]]
ans = 0
for k in range(1,N+1):
    s = k*A
    ans += dp[N][k][s]
print(ans)

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




s_max = 5001
dp = [[0]*(s_max+1) for i in range(N+1)]
dp[0][2500] = 1
for i in range(1,N+1):
    for s in range(s_max+1):
        if 0 <= s-X[i-1] <= s_max:
            dp[i][s] += dp[i-1][s-X[i-1]]
        dp[i][s] += dp[i-1][s]

ans = dp[N][2500] - 1
print(ans)

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

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

for i in range(1, N + 1):
    dp[i][y[i - 1] + X*N] += 1
    for j in range(len(dp[0])):
        dp[i][j] += dp[i - 1][j]
        diff = j + y[i - 1]
        if 0 <= diff and diff <= 2*X*N:
            dp[i][diff] += dp[i - 1][j]

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

Solution (Python):
N, A = map(int, input().split())
num_base = list(map(int, input().split()))
num_li = [n - A for n in num_base]

import collections as cols
C = cols.Counter([0])

for n in num_li:
  adcols = cols.Counter()
  for idx, count in C.items():
    adcols[n+idx] += count
  C += adcols
print(C[0]-1)

Solution (Python):
import collections as co
n,a=map(int,input().split())
X=[int(x)-a for x in input().split()]
C=co.Counter([0])
for x in X:
  itiji=co.Counter()
  for i,c in C.items():
    itiji[i+x]+=c
  C+=itiji
print(C[0]-1)

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

Solution (Python):
n,a=map(int,input().split())
*x,=map(int,input().split())
dp=[[[0]*(n*50+1) for i 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*50+1):
            if i==0 and j==0 and k==0:
                dp[i][j][k]=1
            elif i and k<x[i-1]:
                dp[i][j][k]=dp[i-1][j][k]
            elif i and j and k>=x[i-1]:
                dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]]

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

Solution (Python):
n,a=map(int,input().split())
*x,=map(int,input().split())
dp=[[[None]*(n*50+1) for i 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*50+1):
            if i==0 and j==0 and k==0:
                dp[i][j][k]=1
            elif i and k<x[i-1]:
                dp[i][j][k]=dp[i-1][j][k]
            elif i and j 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

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

Solution (Python):
n,a=map(int,input().split())
*x,=map(int,input().split())
dp=[[[0]*(n*50+1) for i 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*50+1):
            if i==0 and j==0 and k==0:
                dp[i][j][k]=1
            elif i and k<x[i-1]:
                dp[i][j][k]=dp[i-1][j][k]
            elif i and j 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

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

Solution (Python):
n,a=map(int,input().split())
x=list(map(int,input().split()))
m=max(x)
L3=[]
for i3 in range(n+1):
  L2=[]
  for i2 in range(n+1):
    L1=[0 for i1 in range(n*m+1)]
    L2.append(L1)
  L3.append(L2)
for i3 in range(n+1):
  for i2 in range(n+1):
    for i1 in range(m*n+1):
      if i1==0 and i2==0 and i3==0:
        L3[i3][i2][i1]=1
      elif i3>0 and i1<x[i3-1]:
        L3[i3][i2][i1]=L3[i3-1][i2][i1]
      elif i3>0 and i2>0 and i1>=x[i3-1]:
        L3[i3][i2][i1]=L3[i3-1][i2][i1]+L3[i3-1][i2-1][i1-x[i3-1]]
      else:
        L3[i3][i2][i1]=0
ct=0
for i2 in range(n+1):
  for i1 in range(1,m*n+1):
    if i1==i2*a:
      ct+=L3[n][i2][i1]
print(ct)

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

Solution (Python):
n,a,*x=map(int,open(0).read().split())
x=[0]+x
dp=[[[0]*(50*n+1)for j in range(n+1)]for i in range(n+1)]
dp[0][0][0]=1
for i in range(1,n+1):
  dp[i][0]=dp[i-1][0]
  for j in range(1,n+1):
    for k in range(1,50*n+1):
      dp[i][j][k]=dp[i-1][j][k]
      if k-x[i]>=0:
        dp[i][j][k]+=dp[i-1][j-1][k-x[i]]
ans=0
for i in range(1,n+1):
  j=i*a
  if j<50*n+2:
    ans+=dp[-1][i][j]
print(ans)

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

for i in range(N):
    x[i]=int(x[i])
X=max(max(x),A)
for i in range(N):
    x[i]=x[i]-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:
            if t-x[j-1]<0 or t-x[j-1]>2*N*X:
                dp[j][t]=dp[j-1][t]
            elif t-x[j-1]>=0 and t-x[j-1]<=2*N*X:
                dp[j][t]=dp[j-1][t]+dp[j-1][t-x[j-1]]
print(dp[N][N*X]-1)

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

if __name__ == "__main__":
    N, A = map(int, input().split())
    x = [i-A for i in map(int, input().split())]
    X = max(x + [A])
    dp = [[0] * (2*N*X + 1) for _ in range(N+1)]
    for row in range(N+1):
        for column in range(2*N*X):
            if row == 0 and column == N*X:
                dp[row][column] = 1
            elif row >=1 and (column - x[row-1] < 0 or column - x[row-1] > 2*N*X):
                    dp[row][column] = dp[row-1][column]
            elif row >=1 and 0 <= column - x[row-1] <= 2*N*X:
                dp[row][column] = dp[row-1][column] + dp[row-1][column-x[row-1]]
            else:
                dp[row][column] = 0
    print(dp[N][N*X]-1)