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

Solution (Python):
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))
N, A = inpl()
x = inpl()
y = [ X-A for X in x ]
cur = defaultdict(int)
cur[0] = 1
cur[y[0]] += 1
for i in range(1,N):
    prev = cur
    cur = defaultdict(int)
    for k in prev.keys():
        cur[k] += prev[k]
        cur[k+y[i]] += prev[k]
print(cur[0]-1)

Solution (Python):

import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7

def main():
    N,A = cin.mapInt()
    X = cin.mapInt()
    dp = [[[0 for k in range(3000)] for j in range(51)]  for i in range(51)]
    dp[0][0][0] = 1
    ans = 0
    for i in range(N):
        for j in range(i + 1):
            for k in range(2500):
                dp[i + 1][j][k] += dp[i][j][k]  
                dp[i + 1][j + 1][k + X[i]] += dp[i][j][k]
    for j in range(1,N + 1):
        ans += dp[N][j][j * A]
    print(ans)
    return

if __name__ == "__main__":
    main()

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


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

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


if __name__ == '__main__':
    main()

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(5001)] for i in range(N+1)]
dp[0][2500] = 1
u = 2500
d = 2500
for i in range(1,N+1):
    x = X[i-1]
    if x <= 0:
        d += x
    else:
        u += x
    for j in range(d,u+1):
        dp[i][j] += dp[i-1][j-x] + dp[i-1][j]
print(dp[N][2500]-1)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
minans = inf ;ans = 0 ;count = 0 ;pro = 1

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


A=[0]*2600
B=[0]*2600
for xi in X:
    xi-=K
    if xi>0:
        for i in range(2599-xi,-1,-1):
            A[i+xi]+=A[i]
        A[xi]+=1
    elif xi==0:count+=1
    else:
        xi=-xi
        for i in range(2599-xi,-1,-1):
            B[i+xi]+=B[i]
        B[xi]+=1
count=2**count
for i in range(2600):
    ans+=A[i]*B[i]*(count)
ans+=count-1
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n,a=map(int,input().split())
    dp=defaultdict(int)
    dp[0]=1

    for x in map(int,input().split()):
        x-=a
        ndp=dp.copy()
        for key,val in dp.items():
            ndp[key+x]+=val
        dp=ndp

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

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
from copy import copy
def resolve():
    n,a=map(int,input().split())
    X=list(map(lambda x:int(x)-a,input().split()))
    dp=defaultdict(int)
    dp[0]=1
    for x in X:
        ndp=copy(dp)
        for key,val in dp.items():
            ndp[key+x]+=val
        dp=ndp

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

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n,a=map(int,input().split())
    X=list(map(lambda x:int(x)-a,input().split()))
    dp=defaultdict(int)
    dp[0]=1
    for x in X:
        ndp=defaultdict(int)
        for key,val in dp.items():
            ndp[key]+=val
            ndp[key+x]+=val
        dp=ndp

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,a = LI()
    x = LI()
    m = 2501
    d = [[0]*m for i in range(n+1)]
    d[0][0] = 1
    for xi in x:
        for i in range(n)[::-1]:
            ni = i+1
            for j in range(m):
                if not d[i][j]:
                    continue
                k = j+xi
                if k >= m:
                    break
                d[ni][k] += d[i][j]
    ans = 0
    for i in range(1,n+1):
        k = a*i
        if k < m:
            ans += d[i][k]
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
n,a=map(int,input().split())
l=list(map(int,input().split()))
for i in range(n):
    l[i]-=a
u=[0]*(3001)
d=[0]*(3001)
ul=[]
dl=[]
z=0
for i in l:
    if i==0:
        z+=1
    elif i<0:
        dl.append(-i)
    else:
        ul.append(i)
        
for i in ul:
    for j in range(3000,-1,-1):
        if u[j]>0 or j==0:
            u[j+i]+=max(1,u[j])
for i in dl:
    for j in range(3000,-1,-1):
        if d[j]>0 or j==0:
            d[j+i]+=max(1,d[j])
ans=0
for i in range(3001):
    ans+=u[i]*d[i]
if ans==0 and z==0:
    print(0)
elif z==0:
    print(ans)
elif ans==0:
    print(2**z-1)
else:
    print((1+ans)*(2**z)-1)

Solution (Python):

n,a = map(int,input().split())
dp = [[[0 for _ in range(3000)] for _ in range(n+1)] for _ in range(n+1)]
l = list(map(int,input().split()))
dp[0][0][0] = 1
s = 0
for i in range(n):
    for j in range(i+1):
        for k in range(s+1):
            if dp[i][j][k]!=0:
                dp[i+1][j][k]+=dp[i][j][k]
                dp[i+1][j+1][k+l[i]]+=dp[i][j][k]
    s+=l[i]
res = 0
for i in range(1,n+1):
    res+=dp[n][i][a*i]
print(res)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, X):
    ans = 0
    Y = [x - A for x in X]
    M = 2*N*50 + 1
    dp = [[0]*M for _ in range(N+1)]

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


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


def main():
    N, A = read_int_n()
    X = read_int_n()
    print(slv(N, A, X))


if __name__ == '__main__':
    main()

Solution (Python):
N, A = map(int,input().split())
x = list(map(int,input().split()))
MOD = 5500
DP = [[0]*(MOD) for i in range(N+1)]
DP[0][0] = 1
for i in range(N):
    for j in range(MOD):
        DP[i+1][j] = DP[i][j] + DP[i][(j-A+x[i])%MOD]
print(DP[-1][0] - 1)

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

p=[];z=0;n=[]
for xi in x:
    if xi>A:
        p.append(xi-A)
    elif xi==A:
        z+=1
    elif xi<A:
        n.append(A-xi)

K=min(sum(p),sum(n))

Pa=[0 for j in range(K+1)];Pa[0]=1
Na=[0 for j in range(K+1)];Na[0]=1

for pi in p:
    for j in range(K,pi-1,-1):
        Pa[j]+=Pa[j-pi]
for ni in n:
    for j in range(K,ni-1,-1):
        Na[j]+=Na[j-ni]

ans=2**z-1 
for j in range(1,K+1):
    ans+=2**z*Pa[j]*Na[j]

print(ans)

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

for i in range(n+1):
    for j in range(n+1):
        for k in range(n*a+1):
            if  i>=1 and k<x[i]:
                dp[i][j][k]=dp[i-1][j][k]
            elif i>=1 and j>=1 and k>=x[i]:
                dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]]

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=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 i in range(n+1):
        for j in range(i+1):
            for k in range(50*j+1):
                if i>0 and k<x[i-1]:
                    dp[i][j][k]=dp[i-1][j][k]
                elif i>0 and j>0 and k>=x[i-1]:
                    dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]]
    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=[x-A for x in map(int,input().split())]
dp=[0]*(N*100+1)
dp[0]=1
for x in X:
    if x>0:
        for i in range(N*50,-N*50-1,-1):
            if dp[i]>0:
                dp[i+x]+=dp[i]
    else:
        for i in range(-N*50,N*50+1):
            if dp[i]>0:
                dp[i+x]+=dp[i]
print(dp[0]-1)

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

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()))
x.insert(0, 0)

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

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

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

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

for j in range(N+1):
  for k in range(N+1):
    for s in range(N*xx+1):
      if j==k==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:
        pass
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 = [int(_) - A for _ in input().split()]

dic = {0: 1}


for x in X:
    for i, j in list(dic.items()):
        
        
        dic[x + i] = dic.get(x+i, 0) + j
print(dic[0] - 1)

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

MAXSUM = sum(X)+5
dp = [[[0 for _ in range(MAXSUM)] for _ in range(N+5)] for _ in range(N+5)]
for i in range(N):
  dp[i+1][1][X[i]] += 1
  for k in range(N):
    for j in range(MAXSUM):
      dp[i+1][k][j] += dp[i][k][j]
      if X[i]+j < MAXSUM:
        dp[i+1][k+1][X[i]+j] += dp[i][k][j]

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

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

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


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

Y = [x - A for x in X]

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

for m in range(1, N + 1):
    for s in range(-5000, 5001):
        if s + 5000 < 10000:
            dp[m][s + 5000] += dp[m - 1][s + 5000]
            if 0 <= s - Y[m - 1] + 5000 < 10000:
                dp[m][s + 5000] += dp[m - 1][s - Y[m - 1] + 5000]

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

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

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

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

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

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

def main():
    N, A = map(int, input().split())
    x = np.array(list(map(int, input().split())))
    x -= A
    MAX_ = max(1, max(x))

    dp = np.zeros((N+1, MAX_ * N * 2), dtype=int)
    dp[0][MAX_ * N] = 1

    for i in range(N):
        dp[i+1] += dp[i]
        if x[i] > 0:
            dp[i+1][x[i]:] += dp[i][:-x[i]]
        elif x[i] < 0:
            dp[i+1][:x[i]] += dp[i][-x[i]:]
        else:
            dp[i+1] += dp[i]
    
    print(dp[N][MAX_ * N] - 1)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
	n,a=map(int,input().split())
	y=[a-int(x) for x in input().split()]
	dp={0:1}
	for i in y:
		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):
n,a=map(int,input().split())
y=[a-int(x) for x in input().split()]
dp={0:1}
for i in y:
	for k,v in list(dp.items()):
		dp[i+k]=dp.get(i+k,0)+v
print(dp[0]-1)

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

Solution (Python):
n,a,*x=map(int,open(0).read().split());dp={0:1}
for i in x:
	for k,v in set(dp.items()):
		dp[i+k-a]=dp.get(i+k-a,0)+v
print(dp[0]-1)

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

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

Solution (Python):
N, A = tuple(map(int, input().split()))
X = list(map(lambda x: int(x) - A, input().split()))
D = {0:0}

for item in X:
  for k,v in list(D.items()):
    D[k+item]=D.get(k+item,0)+v
  D[item]=D.get(item,0)+1

print(D[0])

Solution (Python):
N,A=map(int,input().split())
x=list(map(int,input().split()))
cnt=x.count(A)
B=[]
for i in x:
  if i != A:
    B.append(i-A)


plus=[0]*2501
minus=[0]*2501

for i in B:
  if i>0:
    for j in range(2500,0,-1):
      if plus[j]>0 and j+i<=2500:
        plus[j+i]+=plus[j]
    plus[i]+=1
  if i<0:
    i=-i
    for j in range(2500,0,-1):
      if minus[j]>0 and j+i<=2500:
        minus[j+i]+=minus[j]
    minus[i]+=1



    
ans=0
for i in range(2501):
  ans+=plus[i]*minus[i] if plus[i]>0 and minus[i]>0 else 0

ans*=2**cnt
ans+=2**cnt-1

print(ans)

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

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

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

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


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


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

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

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

print(ans)

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

table = [[[0]*(N*A+1) for i in range(N+1)] for j in range(N+1)]
table[0][0][0] = 1

for j in range(1,N+1):
  for k in range(j+1):
    for s in range(N*A+1):
      c = x[j-1]
      if s-c<0:
        table[j][k][s] = table[j-1][k][s]
      elif s-c>=0 and k>=1:
        table[j][k][s] = table[j-1][k][s] + table[j-1][k-1][s-c]
      
ans = 0
for i in range(1,N+1):
  ans += table[N][i][i*A]
print(ans)

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

table = [[[0]*(N*A+1) for i in range(N+1)] for j in range(N+1)]
table[0][0][0] = 1

for j in range(1,N+1):
  for k in range(N+1):
    for s in range(N*A+1):
      c = x[j-1]
      if s-c<0:
        table[j][k][s] = table[j-1][k][s]
      elif s-c>=0 and k>=1:
        table[j][k][s] = table[j-1][k][s] + table[j-1][k-1][s-c]
      
ans = 0
for i in range(1,N+1):
  ans += table[N][i][i*A]
print(ans)

Solution (Python):
N, A = map(int, input().split())
X = list(map(int, input().split()))
X = list(map(lambda x: x - A, X))
maxx = max(max(X), -min(X))

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

Solution (Python):

def main():
    N, A = tuple(map(int, input().split()))
    X = tuple(map(int, input().split()))
    
    dp = [[[0] * (N * 50 + 1) for _ in range(N + 1)] for _ in range(N + 1)]
    dp[0][0][0] = 1
    for i in range(N):
        for j in range(N):
            for k in range(N * 50 + 1):
                if dp[i][j][k]:
                    dp[i + 1][j][k] += dp[i][j][k]
                    dp[i + 1][j + 1][k + X[i]] += dp[i][j][k]
    ans = sum(dp[N][i][i * A] for i in range(1, N + 1))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from collections import defaultdict


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


if __name__ == "__main__":
    main()

Solution (Python):

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


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N, A = tuple(map(int, input().split()))
    X = tuple(map(int, input().split()))
    
    dp = [[[0] * (N * 50 + 1) for _ in range(N + 1)] for _ in range(N + 1)]
    dp[0][0][0] = 1
    for i in range(N):
        for j in range(N):
            for k in range(N * 50 + 1):
                if dp[i][j][k]:
                    dp[i + 1][j][k] += dp[i][j][k]
                    dp[i + 1][j + 1][k + X[i]] += dp[i][j][k]
    ans = sum(dp[N][i][i * A] for i in range(1, N + 1))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N, A = tuple(map(int, input().rstrip().split()))
    X = tuple(map(int, input().rstrip().split()))
    x = max(X)
    
    dp = [[[0] * (N * 50 + 1) for _ in range(N + 1)] for _ in range(N + 1)]
    dp[0][0][0] = 1
    for i in range(N):
        for j in range(N):
            for k in range(N * 50 + 1):
                if dp[i][j][k]:
                    dp[i + 1][j][k] += dp[i][j][k]
                    dp[i + 1][j + 1][k + X[i]] += dp[i][j][k]
    ans = sum(dp[N][i][i * A] for i in range(1, N + 1))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n,a = map(int,input().split())
x = list(map(int,input().split()))
dp = []
for i in range(n+1):
    dp.append([[] for j in range(i+1)])
    for k in range(i+1):
        dp[i][k] = [0 for y in range(50*k)]
for i in range(n+1):
        dp[i][0].append(0)
for i in range(1,n+1):
    for j in range(1,i+1):
        if j == 1:
                dp[i][j][x[i-1]-1] += 1
        for k in range(50*(j-1)):
                dp[i][j][k+x[i-1]] += dp[i-1][j-1][k]
                dp[i][j-1][k] += dp[i-1][j-1][k]
count = 0
for j in range(1,i+1):
        for k in range(len(dp[i][j])):
                if k + 1 == j*a:
                        count += dp[n][j][k]
print(count)

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

N,A = inpl()
aa = inpl()

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


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


for i in range(N):
    a = aa[i]
    for j in range(1,i+2):
        for k in range(50*j+5):
            dp[i][j][k] = dp[i-1][j][k]
            if k >= a:
                dp[i][j][k] += dp[i-1][j-1][k-a]

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

print(ans-1)

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

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

def bias(n):
    return n + 5000

dp[0][bias(0)] = 1

for i in range(N):
    for s in range(-5000, 5000):
        dp[i + 1][bias(s)] += dp[i][bias(s)]
        dp[i + 1][bias(s + Y[i])] += dp[i][bias(s)]

print(dp[N][bias(0)] - 1)

Solution (Python):
N,A=map(int,input().split())
X=list(map(int,input().split()))
dp=[[0]*5001 for _ in range(N+1)]
dp[0][2500]=1
for i in range(N):
    for j in range(5001):
        if dp[i][j]>0:
            dp[i+1][j]+=dp[i][j]
            dp[i+1][j+X[i]-A]+=dp[i][j]
print(dp[N][2500]-1)

Solution (Python):

n, a = [ int(v) for v in input().split() ]
num_list = [ int(v) for v in input().split() ]
max_num = max(num_list)
field = [ [ 0 for i in range(5000) ] for i in range(n+1) ]
field[0][0] = 1

b = num_list[0]
for i in num_list:
    for j in range(n,0,-1):
        for k in range(5000):
            if k >= i:
                field[j][k] += field[j-1][k-i]



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

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

dp = [[[0 for _ in range(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):
        for t in range(2501):
            dp[i + 1][j][t] += dp[i][j][t]
            dp[i + 1][j + 1][t + X[i]] += dp[i][j][t]

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

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

plus = []
minus = []
num_zero = 0
for i in range(N):
    xi_A = x[i] - A
    if xi_A > 0:
        plus.append(xi_A)
    elif xi_A < 0:
        minus.append(xi_A)
    else:
        num_zero += 1

dp_plus = [[0 for _ in range(2501)] for _ in range(len(plus) + 1)]
dp_minus = [[0 for _ in range(2501)] for _ in range(len(minus) + 1)]
dp_plus[0][0] = 1
dp_minus[0][0] = 1
for i in range(1, len(plus) + 1):
    for j in range(2501):
        dp_plus[i][j] += dp_plus[i-1][j]
        if j + plus[i-1] <= 2500:
            dp_plus[i][j + plus[i-1]] += dp_plus[i-1][j]
for i in range(1, len(minus) + 1):
    for j in range(2501):
        dp_minus[i][j] += dp_minus[i-1][j]
        if j - minus[i - 1] <= 2500:
            dp_minus[i][j - minus[i-1]] += dp_minus[i-1][j]

ans = 0
for i in range(2501):
    ans += dp_plus[-1][i] * dp_minus[-1][i] * (2 ** num_zero)
print(ans - 1)

Solution (Python):
n,a=[int(_) for _ in input().split()]
x=[int(_) for _ in input().split()]
dp=[[[0 for k in range(2551)] for j in range(51)] for i in range(n)]
dp[0][1][x[0]]=1;dp[0][0][0]=1
for i in range(n-1):
    for j in range(50):
        for k in range(2501):
            dp[i+1][j+1][k+x[i+1]] += dp[i][j][k]
            dp[i+1][j][k] += dp[i][j][k]
ans=0
for j in range(1,n+1):ans += dp[-1][j][j*a]
print(ans)

Solution (Python):




import sys
write = sys.stdout.write

N, A = map(int,input().split())
x = list(map(int,input().split()))
x.insert(0,0)
ssize = N*A+1
jsize = N+1
dp = [[[0 for s in range(ssize)] for k in range(jsize)] for j in range(jsize)]
for j in range(jsize):
    for k in range(jsize):
        for s in range(ssize):
            if j == 0 and k == 0 and s == 0:
                dp[j][k][s] = 1
            elif j >= 1 and s - x[j] < 0:
                dp[j][k][s] = dp[j-1][k][s]
            elif j >= 1 and k >= 1 and s - x[j] >= 0:
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j]]
            else:
                dp[j][k][s] = 0
sum = 0
for k in range(1, N+1):
    sum += dp[N][k][k*A]
print(str(sum))

Solution (Python):
N,K=map(int,input().split())
A=list(map(lambda x:int(x),input().split()))
memo=[[0 for _ in [0]*(50*i)] for i in range(1,N+1)]
for i in range(N):
    a=A[i]
    for j in range(i,0,-1):
        for k in range(50*j):
            memo[j][k+a]+=memo[j-1][k]
    memo[0][a-1]+=1
cnt=0
for i in range(N):
    cnt+=memo[i][(i+1)*K-1]
print(cnt)

Solution (Python):
import numpy as np

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

dp = np.zeros((N + 1, 2 * NX + 1), dtype=int)

dp[0][NX] = 1

for j in range(1, N + 1):
    y = X[j] - A
    for t in range(2 * NX + 1):
        if 0 <= t - y < 2 * NX:
            dp[j][t] = dp[j - 1][t] + dp[j - 1][t - y]
        else:
            dp[j][t] = dp[j - 1][t]

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

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

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

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

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

ma = max(X)

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

ans = 0

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

print(ans)

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

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

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

print(ans)