Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
N, A = map(int, input().split())
X = [int(x) for x in input().split()]

@lru_cache(1000000000, False)
def solve(i, n, s):
    if s < 0:
        return -1
    if N-i+1 < n:
        return -1
    if n == 0:
        if s == 0:
            return 1
        else:
            return -1
    if i == N:
        return -1
    s1 = solve(i+1, n-1,s-X[i])
    s2 = solve(i+1, n, s)
    if s1 == -1 and s2 == -1:
        return -1
    if s1 == -1:
        return s2
    if s2 == -1:
        return s1
    return s1 + s2


answer = 0
for n in range(1, N+1):
    s = solve(0, n, n*A)
    if s != -1:
        #print(n, s)
        answer += s
print(answer)

def test():
    import itertools
    for a in itertools.combinations(X,3):
        if sum(a) == A*3:
            print(a)

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

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

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

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

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

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

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache
N, A = map(int, input().split())
X = [int(x) for x in input().split()]

@lru_cache(1000000000, False)
def solve(i, n, s):
    if s < 0:
        return -1
    if N-i+1 < n:
        return -1
    if n == 0:
        if s == 0:
            return 1
        else:
            return -1
    if i == N:
        return -1
    s1 = solve(i+1, n-1,s-X[i])
    s2 = solve(i+1, n, s)
    if s1 == -1 and s2 == -1:
        return -1
    if s1 == -1:
        return s2
    if s2 == -1:
        return s1
    return s1 + s2


answer = 0
for n in range(1, N+1):
    s = solve(0, n, n*A)
    if s != -1:
        #print(n, s)
        answer += s
print(answer)

def test():
    import itertools
    for a in itertools.combinations(X,3):
        if sum(a) == A*3:
            print(a)

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

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

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

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

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

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