Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache

N, A = map(int, input().split())
X = tuple(int(x) for x in input().split())

# 平均を出すのに選んだ個数が必要
@lru_cache(maxsize=None)
def rec(x, a, k):
    """
    :param x: tuple
        数列
    :param a: int
        総和
    :param k: int
        選ぶ個数
    :return: int
        通り数
        Number of patterns
    """
    if k == 0:
        if a == 0:
            return 1
        else:
            return 0

    if a < 0 or len(x) < k:
        return 0

    ret = rec(x[1:], a, k)
    ret += rec(x[1:], a - x[0], k - 1)
    return ret
X = tuple(sorted(X))
m = (rec(X, k * A, k) for k in range(1, N + 1))
print(sum(m))

Fixed submission:
from functools import lru_cache

N, A = map(int, input().split())
X = tuple(int(x) for x in input().split())

# 平均を出すのに選んだ個数が必要
@lru_cache(maxsize=None)
def rec(i, a, k):
    """
    :param i: int 
        数列の長さ
    :param a: int
        総和
    :param k: int
        選ぶ個数
    :return: int
        通り数
        Number of patterns
    """
    if k == 0:
        if a == 0:
            return 1
        else:
            return 0

    if a < 0 or i < k:
        return 0

    ret = rec(i - 1, a, k)
    ret += rec(i - 1, a - X[i - 1], k - 1)
    return ret

i = len(X)
m = (rec(i, k * A, k) for k in range(1, N + 1))
print(sum(m))

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache

N, A = map(int, input().split())
X = tuple(int(x) for x in input().split())

# 平均を出すのに選んだ個数が必要
@lru_cache(maxsize=None)
def rec(x, a, k):
    """
    :param x: tuple
        数列
    :param a: int
        総和
    :param k: int
        選ぶ個数
    :return: int
        通り数
        Number of patterns
    """
    if k == 0:
        if a == 0:
            return 1
        else:
            return 0

    if a < 0 or len(x) < k:
        return 0

    ret = rec(x[1:], a, k)
    ret += rec(x[1:], a - x[0], k - 1)
    return ret

m = (rec(X, k * A, k) for k in range(1, N + 1))
print(sum(m))

Fixed submission:
from functools import lru_cache

N, A = map(int, input().split())
X = tuple(int(x) for x in input().split())

# 平均を出すのに選んだ個数が必要
@lru_cache(maxsize=None)
def rec(i, a, k):
    """
    :param i: int 
        数列の長さ
    :param a: int
        総和
    :param k: int
        選ぶ個数
    :return: int
        通り数
        Number of patterns
    """
    if k == 0:
        if a == 0:
            return 1
        else:
            return 0

    if a < 0 or i < k:
        return 0

    ret = rec(i - 1, a, k)
    ret += rec(i - 1, a - X[i - 1], k - 1)
    return ret

i = len(X)
m = (rec(i, k * A, k) for k in range(1, N + 1))
print(sum(m))

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache

N, A = map(int, input().split())
X = tuple(int(x) for x in input().split())

# 平均を出すのに選んだ個数が必要
@lru_cache()
def rec(x, a, k):
    """
    :param x: tuple
        数列
    :param a: int
        総和
    :param k: int
        選ぶ個数
    :return: int
        通り数
        Number of patterns
    """
    if k == 0:
        if a == 0:
            return 1
        else:
            return 0

    if a < 0 or len(x) < k:
        return 0

    ret = rec(x[:-1], a, k)
    ret += rec(x[:-1], a - x[-1], k - 1)
    return ret

m = [rec(X, k * A, k) for k in range(1, N + 1)]
print(sum(m))

Fixed submission:
from functools import lru_cache

N, A = map(int, input().split())
X = tuple(int(x) for x in input().split())

# 平均を出すのに選んだ個数が必要
@lru_cache(maxsize=None)
def rec(i, a, k):
    """
    :param i: int 
        数列の長さ
    :param a: int
        総和
    :param k: int
        選ぶ個数
    :return: int
        通り数
        Number of patterns
    """
    if k == 0:
        if a == 0:
            return 1
        else:
            return 0

    if a < 0 or i < k:
        return 0

    ret = rec(i - 1, a, k)
    ret += rec(i - 1, a - X[i - 1], k - 1)
    return ret

i = len(X)
m = (rec(i, k * A, k) for k in range(1, N + 1))
print(sum(m))