Problem:
 Score : 300 points    Problem Statement Tak has N cards. On the i -th (1 \leq i \leq N) card is written an integer x_i .
He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A .
In how many ways can he make his selection?      Constraints  1 \leq N \leq 50  1 \leq A \leq 50  1 \leq x_i \leq 50  N,\,A,\,x_i are integers.       Partial Score  200 points will be awarded for passing the test set satisfying 1 \leq N \leq 16 .         Input The input is given from Standard Input in the following format:  N  A  x_1  x_2  ...  x_N       Output Print the number of ways to select cards such that the average of the written integers is exactly A .        Sample Input 1 4 8
7 9 8 9      Sample Output 1 5   The following are the 5 ways to select cards such that the average is 8 :  Select the 3 -rd card.  Select the 1 -st and 2 -nd cards.  Select the 1 -st and 4 -th cards.  Select the 1 -st, 2 -nd and 3 -rd cards.  Select the 1 -st, 3 -rd and 4 -th cards.          Sample Input 2 3 8
6 6 9      Sample Output 2 0       Sample Input 3 8 5
3 6 2 8 7 6 5 9      Sample Output 3 19       Sample Input 4 33 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3      Sample Output 4 8589934591   The answer may not fit into a 32 -bit integer.

Solution (Python):
n,a=map(int,input().split())
x=list(map(int,input().split()))
dp=[[[0]*(2501) for i in range(51)] for j in range(51)]

for i in range(n+1):
    dp[i][0][0]=1
for i in range(n):
    for j in range(1,i+2):
        for k in range(1,2501):
            if k-x[i]>=0:
                dp[i+1][j][k]=dp[i][j-1][k-x[i]]+dp[i][j][k]
            else:
                dp[i+1][j][k] = dp[i][j][k]
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())
arr = list(map(int , input().split()))
dp = [ [[ 0 for j in range(0 , a*(n+2))] for k in range(0 , n+2)] for i in range(0,n+2)]
dp[0][0][0]=1
b=[0 for i in range(0 , n+1)]
for i in range(0 , n):
	b[i+1]=arr[i]
for i in range(1 , n+1):	
	for j in range(0 , i+1):
		for k in range(0 , a*(n)+2):
			if k<b[i]:
				dp[i][j][k]=dp[i-1][j][k]
			else:
				dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-b[i]]
tot = 0
for i in range(1 , n+1):
	tot = tot + dp[n][i][(i)*a]
print(tot)

Solution (Python):
n , a= map(int , input().split())
arr = list(map(int , input().split()))
dp = [ [[ 0 for j in range(0 , a*(n+2))] for k in range(0 , n+2)] for i in range(0,n+2)]
dp[0][0][0]=1
b=[0 for i in range(0 , n+1)]
for i in range(0 , n):
	b[i+1]=arr[i]
for i in range(1 , n+1):
	for j in range(0 , i+1):
		for k in range(0 , a*(n)+2):
			if k<b[i]:
				dp[i][j][k]=dp[i-1][j][k]
			else:
				dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-b[i]]
tot = 0
for i in range(1 , n+1):
	tot = tot + dp[n][i][(i)*a]
print(tot)

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

dpp = [0]*3000
dpm = [0]*3000

p = []
m = []
n0 = 0

for i in range(n):
    x1 = x[i] - a
    if x1 == 0:
        n0 += 1
    elif x1 > 0:
        p.append(x1)
    else:
        m.append(-x1)

for i in p:
    for j in range(2600,0,-1):
        if dpp[j] >= 1:
            dpp[j+i] += dpp[j]
    dpp[i] += 1

for i in m:
    for j in range(2600,0,-1):
        if dpm[j] >= 1:
            dpm[j+i] += dpm[j]
    dpm[i] += 1

ans = 0

for i in range(3000):
    ans += dpp[i] * dpm[i]

ans *= pow(2,n0)
ans += pow(2,n0) - 1

print(ans)

Solution (Python):

N, A = map(int, input().split())
X = sorted(list(map(int, input().split())))
xm = max(X)
xm = max(xm, A)
for i in range(N):
  X[i] -= A 

dp = [[0] * (2 * N * xm + 1) for i in range(N + 1)]
dp[0][N * xm] = 1

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

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

    X = [x - A for x in X]

    neg = pos = 0
    for x in X:
        if x > 0:
            pos += x
        else:
            neg += x

    M = pos - neg
    base = -neg

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

    for i in range(N):
        for s in range(M + 1):
            dp[i + 1][s] = dp[i][s]
            if 0 <= s - X[i] <= M:
                dp[i + 1][s] += dp[i][s - X[i]]

    print(dp[N][base] - 1)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

    X = [x - A for x in X]

    neg = pos = 0
    for x in X:
        if x > 0:
            pos += x
        else:
            neg += x

    M = pos - neg
    base = -neg

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

    for i in range(N):
        for s in range(M + 1):
            dp[i + 1][s] = dp[i][s]
            if 0 <= s - X[i] <= M:
                dp[i + 1][s] += dp[i][s - X[i]]

    print(dp[N][base] - 1)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

    X = [x - A for x in X]
    base = 2500
    dp = [[0] * 5001 for _ in range(N + 1)]
    dp[0][base] = 1

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

    print(dp[N][base] - 1)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

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

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

    ans = 0
    for j in range(1, min(N, M // A) + 1):
        ans += dp[j][A * j]

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

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

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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

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

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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

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

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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

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

dp[0][0] = 1

for i in range(0, N):
    for cnt in range(N, 0, -1):
        for val in range(N * A, -1, -1):
            if val - X[i] >= 0:
                dp[cnt][val] += dp[cnt - 1][val - X[i]]

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

print(ans)

Solution (Python):
N,A = map(int,input().split())
X = list(map(int,input().split()))
Y = [x-A for x in X]
dp = {0:1}

for y in Y:
  for k,v in list(dp.items()):
    dp[k+y]=dp.get(k+y,0)+v

print(dp[0]-1)

Solution (Python):
import numpy as np
n,a=map(int,input().split())
x=list(map(int,input().split()))
s=sum(x)
dp=np.zeros((n,s+1),dtype=np.int64)
for i in range(n):
    for j in range(i)[::-1]:
        dp[j+1][x[i]:]+=dp[j][:-x[i]]
    dp[0][x[i]]+=1
t=0
for k in range(n):
    if (k+1)*a<=s:
        t+=dp[k][(k+1)*a]
print(t)

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

Solution (Python):
import sys

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

integers=[x-a for x in cards]
cards.append(a)
f=max(cards)*n


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

for y in range(n+1):
    for x in range(2*f+1):
        if y==0 and x==f:
            dp[x][y]=1
        elif y>0 and (x-integers[y-1]<0 or x-integers[y-1]>2*f):
            dp[x][y]=dp[x][y-1]
        elif y>0 and x-integers[y-1]>=0 and x-integers[y-1]<=2*f:
            dp[x][y]=dp[x-integers[y-1]][y-1]+dp[x][y-1]
        else:
            dp[x][y]=0
print(dp[f][n]-1)

Solution (Python):
n, a = map(int, input().split())
X = tuple(map(int, input().split()))
dp = [[[0] * (2550) 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 s in range(n*a+1):
            
            if dp[i][j][s] == 0:
                continue
            
            dp[i+1][j][s] += dp[i][j][s]
            
            dp[i+1][j+1][s+X[i]] += dp[i][j][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()))
sumX = 2501

dp = [[[0 for _ in range(sumX)] 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(sumX):
            if dp[j][k][s]==0:
                continue
            dp[j+1][k][s] += dp[j][k][s]
            dp[j+1][k+1][s+X[j]] += dp[j][k][s]
ans = 0

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

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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter

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

    ans = 0
    counter = Counter()

    counter[0] += 1
    for i in range(n):
        cur = a - x[i]
        counter_next = Counter()
        for key, val in counter.items():
            counter_next[key] += val
            counter_next[cur + key] += val
        counter = counter_next

    print(counter[0] - 1)


if __name__ == '__main__':
    main()

Solution (Python):
N,A = map(int,input().rstrip().split(" "))
X = list(map(int,input().rstrip().split(" ")))
DPq = [0 for _ in range(1300)]
DPp = [0 for _ in range(1300)]
DPp[0] = 1
DPm = [0 for _ in range(1300)]
DPm[0] = 1
just = 0
ans = 0
for i in X:
    if i > A:
        for i2 in range(1250,-1,-1):
            DPp[i2 + (i - A)] += DPp[i2]
    elif i < A:
        for i2 in range(1250,-1,-1):
            DPm[i2 + (A - i)] += DPm[i2]
    else:
        just += 1
for i in range(1250):
    ans += DPp[i] * DPm[i]
ans *= 2 ** just
ans -=1
print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7






N, A = getNM()
Q = getList()
for i in range(N):
    Q[i] -= A

dp = [[0] * 5002 for i in range(N + 1)]
dp[0][2501] = 1

for i in range(1, N + 1):
    for j in range(5002):
        dp[i][j] += dp[i - 1][j]
        if 0 <= j - Q[i - 1] <= 5001:
            dp[i][j] += dp[i - 1][j - Q[i - 1]]

print(dp[-1][2501] - 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 k in range(N):
        for i in reversed(range(k+1)):
            for j in range(50 * N + 1 -x[k]):
                dp[i+1][j+x[k]] += dp[i][j]
    r = 0
    for i in range(1, N+1):
        r += dp[i][i*A]
    return r
print(main())

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 k in range(N):
        for i in reversed(range(k+1)):
            for j in range(50 * N + 1 -x[k]):
                dp[i+1][j+x[k]] += dp[i][j]
    r = 0
    for i in range(1, N+1):
        r += dp[i][i*A]
    return r
print(main())

Solution (Python):
import copy
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 k in range(N):
        dpn = copy.deepcopy(dp)
        for i in range(k+1):
            for j in range(50 * N + 1 -x[k]):
                dpn[i+1][j+x[k]] += dp[i][j]
        dp = dpn
    r = 0
    for i in range(1, N+1):
        r += dp[i][i*A]
    return r
print(main())

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

    dp = [[0] * (A * N + 1) for _ in range(N + 1)]
    dp[0][0] = 1
    for i, x in enumerate(X):
        for j in reversed(range(1, i + 2)):
            for a in range(x, A * N + 1):
                dp[j][a] += dp[j - 1][a - x]
    return sum(dp[i][A * i] for i in range(1, N + 1))

print(main())

Solution (Python):
N, A = map(int, input().split())
X = list(map(int, input().split()))
dp = [[[0] * 6000 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(5000):
            if dp[i][j][k] == 0:
                continue
            dp[i + 1][j][k] += dp[i][j][k]
            dp[i + 1][j + 1][k + X[i]] += dp[i][j][k]
C = 0
for i in range(N + 1):
    C += dp[N][i][i * A]
print(C - 1)

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

s = sum(x)
dp = np.zeros((n, s+1), dtype = np.int64)
for i in range(n):
  for j in range(i)[::-1]:
    dp[j+1][x[i]:] += dp[j][:-x[i]]
  dp[0][x[i]] += 1
ans = 0
for i in range(n):
  if (i+1)*a <= s:
    ans += dp[i][(i+1)*a]
print(ans)

Solution (Python):
import numpy as np
n,a = map(int,input().split())
x = list(map(int,input().split()))
"""
平均がa <=> 集合をlとして, len(l)a = sum(l)
dp[i][j][k] := i番目までのカードを選んだとき, 選んだ枚数がkでの総和がちょうどjになる場合の数.
これだとメモリが足りないので, iを省略する.
"""
sumx = sum(x)
dp = np.zeros((n, sumx+1), dtype=np.int64)
for i in range(n):
	for j in range(i)[::-1]:
		dp[j+1][x[i]:] += dp[j][:-x[i]]
	dp[0][x[i]] += 1
ans = 0
for i in range(n):
	if (i+1)*a <= sumx:
		ans += dp[i][(i+1)*a]
print(ans)

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[i][j][k] - sum is i, j number of elements, first k elements
    OPT[i][j][k] = OPT[i-x[k]][j-1][k-1] if j-th element is taken
                   OPT[i][j][k-1]

    OPT[A*j][j][k] for all k
    """
    N, A = read_ints()
    x = read_ints()
    OPT = [[[0 for _ in range(N+1)] for _ in range(N+1)] for _ in range(N*max(x)+1)]
    for k in range(N+1):
        OPT[0][0][k] = 1
    for i in range(len(OPT)):
        for j in range(1, N+1):
            for k in range(j, N+1):
                if i-x[k-1] >= 0:
                    OPT[i][j][k] += OPT[i-x[k-1]][j-1][k-1]
                OPT[i][j][k] += OPT[i][j][k-1]
    T = 0
    for j in range(1, N+1):
        if A*j < len(OPT):
            T += OPT[A*j][j][N]
    return T


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

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[i][j][k] - sum is i, j number of elements, first k elements
    OPT[i][j][k] = OPT[i-x[k]][j-1][k-1] if j-th element is taken
                   OPT[i][j][k-1]

    OPT[A*j][j][k] for all k
    """
    N, A = read_ints()
    x = read_ints()
    OPT = [[[0 for _ in range(51)] for _ in range(51)] for _ in range(2501)]
    for k in range(N+1):
        OPT[0][0][k] = 1
    for i in range(len(OPT)):
        for j in range(1, N+1):
            for k in range(1, N+1):
                if i-x[k-1] >= 0:
                    OPT[i][j][k] += OPT[i-x[k-1]][j-1][k-1]
                OPT[i][j][k] += OPT[i][j][k-1]
    T = 0
    for j in range(1, N+1):
        T += OPT[A*j][j][N]
    return T


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

Solution (Python):
from sys import stdin
import numpy as np
from numba import njit

@njit("i8(i8[:,:,:],i8[:],i8,i8,i8)",cache=True)
def f(dp,x,con,n,a):
    for i in range(n):
        for k in range(n):
            for j in range(con+1-50):
                
                dp[i+1][j+x[i]][k+1]+=dp[i][j][k]

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

    return ans

def main():
    
    readline=stdin.readline
    con=2500
    n,a=map(int,readline().split())
    x=list(map(int,readline().split()))
    x=np.array(x,dtype=np.int64)

    dp=[[[0]*(n+1) for _ in range(con+1)] for _ in range(n+1)]
    dp[0][0][0]=1
    dp=np.array(dp,dtype=np.int64)

    print(f(dp,x,con,n,a))

if __name__=="__main__":
    main()

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    con=2500
    n,a=map(int,readline().split())
    x=list(map(int,readline().split()))

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

                
                dp[i+1][j][k]+=dp[i][j][k]

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

if __name__=="__main__":
    main()

Solution (Python):
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n, a = LI()
	x_list = np.array(LI())
	nx = n*max(x_list+[a])
	y_list = x_list - a
	dp = np.full((n+1,2*nx+1),INF)

	def dfs(j,t):
		dp_value = dp[j,t]
		if dp_value == INF:
			if j == 0 and t == nx:
				dp_value = 1
			elif j >= 1 and (y_list[j-1] < t - 2*nx or y_list[j-1] > t):
				dp_value = dfs(j-1, t)
			elif j >= 1 and 0 <= t - y_list[j-1] <= 2*nx:
				dp_value = dfs(j-1, t) + dfs(j-1, t-y_list[j-1])
			else:
				dp_value = 0
			dp[j,t] = dp_value
		return int(dp_value)

	print(dfs(n, nx) -1)


if __name__ == '__main__':
    main()

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

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

dp = [[[0]*(50*(N+1)+1) for _ 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 s in range(50*N+1):
            dp[i+1][k][s] += dp[i][k][s]
            dp[i+1][k+1][s+X[i]] += dp[i][k][s]

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

print(ans)

Solution (Python):
R=range;(N,A),(*X,)=(map(int,input().split())for _ in R(2));C=[51*N*[0]for _ in R(N+1)];C[0][0]=1
for I in R(N):
	for J in R(N)[::-1]:
		for K in R(50*N)[::-1]:
			if C[J][K]:C[J+1][K+X[I]]+=C[J][K]
print(sum(C[I][I*A]for I in R(1,N+1)))

Solution (Python):
n,a=map(int,input().split())
x=list(map(int,input().split()))
import numpy as np
dp=np.zeros((n+1,2501),int)
dp[0,0]=1
for xi in x:
  for i in range(n-1,-1,-1):
    dp[i+1][xi:]+=dp[i,:-xi]
ans=0
for i in range(1,n+1):
  ans+=dp[i,i*a]
print(ans)

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

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

for i in range(n):
    for use in range(n):
        for total in range(n * a):
            if dp[i][use][total]:
                dp[i + 1][use][total] += dp[i][use][total]
                dp[i + 1][use + 1][total + x[i]] += dp[i][use][total]

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

print(ans)

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

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

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

print(dic[0] - 1)

Solution (Python):
N, A = map(int, input().split())
lst = [int(x) - A for x in input().split()]
dp = [[0] * (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 - lst[i]]
print(dp[N][50 * N] - 1)

Solution (Python):
N,A = map(int,input().split())
Y = list(map(lambda x:int(x)-A,input().split()))
dp = {0:1}

for y in Y:
	for k,v in list(dp.items()):
		dp[k+y]=dp.get(k+y,0)+v

print(dp[0]-1)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N,A = IL()
X = IL()
X = [x-A for x in X]
X.sort()
pl = bisect.bisect_left(X,0)
pr = bisect.bisect_right(X,0)
MINUS = X[:pl]
ZERO = X[pl:pr]
PLUS = X[pr:]

dpM = [[0 for j in range(3000)] for i in range(len(MINUS)+1)]
dpP = [[0 for j in range(3000)] for i in range(len(PLUS)+1)]
dpM[0][0] = 1
dpP[0][0] = 1
for i in range(len(MINUS)):
  x = abs(MINUS[i])
  for j in range(3000):
    if j+x < 3000:
      dpM[i+1][j+x] = dpM[i][j]
    dpM[i+1][j] += dpM[i][j]
      
for i in range(len(PLUS)):
  x = abs(PLUS[i])
  for j in range(3000):
    if j+x < 3000:
      dpP[i+1][j+x] = dpP[i][j]
    dpP[i+1][j] += dpP[i][j]

ans = 0
for i in range(1,3000):
  ans += dpM[-1][i] * dpP[-1][i]

print(ans*pow(2,len(ZERO))+pow(2,len(ZERO))-1)

Solution (Python):



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

    ret={0: 1}
    for xi in X:
        for y, cnt in list(ret.items()):
            ret[xi+y] = ret.get(xi+y, 0) + cnt
    print(ret[0]-1)

if __name__ == '__main__':
    main()

Solution (Python):



def main():
    N, A = map(int, input().split())
    x = list(map(int, input().split()))
    X = 50
    dp = [[[0]*(N*X +1) for _ in range(N+1)] for _ 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] and k >= 1:
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]
                else:
                    dp[j][k][s] = dp[j-1][k][s]
    ans = 0
    for i in range(N):
        ans += dp[N][i+1][(i+1)*A]
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N, A = map(int, input().split())
X = list(map(int, input().split()))
n = N * 50
dp = [[[0]*(n+1) for j in range(N+1)] for i in range(N+1)]
dp[0][0][0] = 1

for i, a in enumerate(X, 1):
  for j in range(N+1):
    for s in range(n+1):
      dp[i][j][s] = dp[i-1][j][s]
      if a <= s:
        dp[i][j][s] += dp[i-1][j-1][s-a]

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

print(ans)

Solution (Python):
N,A = map(int,input().split())
Y = list(map(lambda x:int(x)-A,input().split()))
dp = {0:1}

for y in Y:
	for k,v in list(dp.items()):
		dp[k+y]=dp.get(k+y,0)+v

print(dp[0]-1)

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

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

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

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