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.



Sample input:
4 8
7 9 8 9


Sample output:
5

Submission status: Wrong Answer

Solution code:
def add2(l):
    ys = []
    for i in range(len(l)):
        ys += [l[i] + x for x in l[i+1:]]
    return ys


def add(n, l):
    if not l:
        return []
    elif n == 2:
        return add2(l)
    else:
        ys = [x for x in add(n, l[1:])]
        ys += [l[0] + x for x in add(n-1, l[1:])]
        return ys


def main():
    n, a = (int(x) for x in input().split())
    xs = [int(x) for x in input().split()]

    # i == 1
    count = len(list(filter(lambda x: x == a, xs)))

    # i == 2 ~ n-2
    for i in range(2, n):
        ys = add(i, xs)
        count += len(list(filter(lambda x: x == a * i, ys)))
    '''
    # i == n-1
    ys = [sum(xs[:i]+xs[i+1:]) for i in range(n)]
    print(ys)
    count += len(list(filter(lambda x: x == a * (n - 1), ys)))
    '''

    # i == n
    if sum(xs) == n*a:
        count += 1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy


def add2(l):
    ys = []
    for i in range(len(l)):
        ys += [l[i] + x for x in l[i+1:]]
    return ys


def add(n, l):
    if not l:
        return []
    elif n == 2:
        return add2(l)
    else:
        ys = [x for x in add(n, l[1:])]
        ys += [l[0] + x for x in add(n-1, l[1:])]
        return ys


def main():
    n, a = (int(x) for x in input().split())
    xs = [int(x) for x in input().split()]

    ys = copy.deepcopy(xs)
    count = len(list(filter(lambda x: x == a, ys)))
    for i in range(2, n-1):
        ys = add(i, xs)
        count += len(list(filter(lambda x: x == a * i, ys)))
    ys = [sum(xs[:i]+xs[i+1:]) for i in range(n)]
    count += len(list(filter(lambda x: x == a * (n - 1), ys)))
    if sum(xs) == n*a:
        count += 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,A=map(int,input().split())
x=list(map(int,input().split()))
x=[i-A for i in x]
dp=[[0]*A for i in range(N+1)]
dp[0][0]=1
for i in range(1,N+1):
    for j in range(A):
        n=(A+j-x[i-1])%A
        dp[i][j]=dp[i-1][j]+dp[i-1][n]
    #else:
        #print(dp[i])
print(dp[N][0]-1)

Submission status: Wrong Answer

Solution code:
import itertools

def avg(ary):
  size = len(ary)
  return sum(i for i in ary)/size

n, a = [int(i) for i in input().split(" ")]
ary = [int(i) for i in input().split(" ")]

ary_list = []
for i in range(len(ary)):
  tmp = list(itertools.combinations(ary, i + 1))
  ary_list[0:0] = tmp

print(len(list(filter(lambda x: avg(x) == n, ary_list))))

Submission status: Wrong Answer

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

for i in range(1, n+1):
    for j in range(i+1):
        for k in range(50*j + 1):
            if j >= 1 and k >= x[j-1]:
                t[i][j][k] = t[i - 1][j - 1][k - x[j-1]] + t[i - 1][j][k]
            else:
                t[i][j][k] = t[i - 1][j][k]
for i in range(1,n+1):
    ans += t[n][i][i*a]
print(ans)

Submission status: Wrong Answer

Solution code:
n,a = map(int,input().split())
x = list(map(int,input().split()))
t = [[0]*5001 for _ in range(n+1)]
ans = 0
for i in range(1, n+1):
  for y in x:
    for j in range(-50*i, 50*i+1):
      t[i][j] += t[i-1][j-y+a]
  ans += t[i][0]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n, a = map(int, input().split())
x = [int(x) for x in input().split()]

x_small = []
x_big = []
count = 0

for v in x:
  if v == a:
    count += 1
  elif v > a:
    x_big.append(v-a)
  else:
    x_small.append(a-v)

key = 0
k = 1
for v in range(count, 0, -1):
  k *= v
  k //= count-v+1
  key += k

if not x_big or not x_small:
  print(key)
  sys.exit()

x_big_size = len(x_big)*(max(x)-a+1)
x_small_size = len(x_small)*a+1
x_big_sub = [0]*(x_big_size)
x_small_sub = [0]*(x_small_size)

for i in range(len(x_big)):
  for j in range(x_big_size-1, -1, -1):
    if j == 0 or x_big_sub[j]:
      if j+x_big[i] <= x_big_size:
        x_big_sub[j+x_big[i]] += 1

for i in range(len(x_small)):
  for j in range(x_small_size-1, -1, -1):
    if j == 0 or x_small_sub[j]:
      if j+x_small[i] <= x_small_size:
        x_small_sub[j+x_small[i]] += 1

sub = []
for i in range(min([len(x_small_sub), len(x_big_sub)])):
  v = x_small_sub[i]*x_big_sub[i]
  if v:
    sub.append(v)

for i in range(len(sub)):
  k = 1
  for j in range(i):
    k += sub[j]
  sub[i] *= k

sub_sum = sum(sub)
ans = (sub_sum+1)*(key+1)-1
print(ans)

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
x=list(map(int,input().split()))
t=[[[0]*((n+1)*a+1)]*(n+1)]*(n+1)
ans=0
for j in range(n+1):
  for k in range(n+1):
    if k>j:
      break
    for s in range((n+1)*a+1):
      if s==0 and k==0 and j==0:
        t[j][k][s]=1
      elif j>=1 and x[j-1]>s:
        t[j][k][s]=t[j-1][k][s]
      elif j>=1 and k>=1 and x[j-1]<=s:
        t[j][k][s]=t[j-1][k][s]+t[j-1][k-1][s-x[j-1]]
      if j==n and k>=1 and s==k*a:
        ans+=t[j][k][s]
print(ans)

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
n,a = map(int,input().split())
l = list(map(int,input().split()))

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

# i 個目までのj個選んで　和のmod aが k

for i in range(n):    
    for j in range(i+1):
        for k in range(a):
                dp[i+1][j][k] += dp[i][j][k]
                x = (k+l[i])%a
                dp[i+1][j+1][x] += dp[i][j][k]

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

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

    dp[0][0] = 1

    for i in range(1, n+1):
        for j in range(-2500, 2501):
            dp[i][j] += dp[i-1][j]
            if -2500 <= j-x[i-1] <= 2500:
                dp[i][j] += dp[i-1][j-x[i-1]]
        print(dp[i][-5:], dp[i][:5])
    print(dp[-1][0]-1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def resolve():
	n, a = map(int, input().split())
	x = list(map(int, input().split()))
	ans = 0
	uni = []
	for i in x:
		if i not in uni:
			uni.append(i)
	if len(uni) == 1:
		print((1 << n) - 1)
		return
	for i in range(1 << n):
		selected = []
		for j in range(n):
			if (i >> j) & 1:
				selected.append(x[j])
		if len(selected) and a == sum(selected) / len(selected):
			ans += 1
	print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
import itertools
from statistics import mean
n, a=map(int, input().split())
x=list(map(int, input().split()))
b=0
for i in range(2,n):
    c = list(itertools.combinations(x, i))
    for j in c:
        mea = mean(j)
        if mea==a:
            b+=1
print(b+x.count(a))

Submission status: Wrong Answer

Solution code:
def search(X, sum):
    dp = [[1 if i == 0 else 0 for i in range(sum + 1)]]
    for i in range(len(X)):
        dp.append(
            [
                dp[-1][j - X[i]] + dp[-1][j] if j >= X[i] else dp[-1][j]
                for j in range(sum + 1)
            ]
        )
    return dp[len(X)][sum]


def resolve():
    N, A = map(int, input().split())
    X = [int(i) for i in input().split()]
    print(sum(search(X, A * (i + 1)) for i in range(N)))


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
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

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
n, a = map(int, input().split())
x = list(map(int, input().split()))
if n == 1:
    if x[0] == a:
        print(1)
    else:
        print(0)
else:
    for i in range(n):
        x[i] -= a
    # x.sort()
    dp = [[0 for j in range(99)] for i in range(n)]
    # print(dp)
    for i in range(n):
        if i == 0:
            dp[i][49] = 1
            dp[i][x[i] + 49] += 1
            continue
        for j in range(99):
            dp[i][j] = dp[i - 1][j]
            if 0 <= j - x[i] <= 98:     
                dp[i][j] += dp[i - 1][j - x[i]]
    ans = dp[-1][49]
    # for i in range(n):
        # print(dp[i])
    print(ans - 1)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
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

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
n, a = map(int, input().split())
x = list(map(int, input().split()))
for i in range(n):
    x[i] -= a
x.sort()
dp = [[0 for j in range(99)] for i in range(n)]
# print(dp)
for i in range(n):
    if i == 0:
        dp[i][49] = 1
        dp[i][x[i] + 49] += 1
        continue
    for j in range(99):
        dp[i][j] = dp[i - 1][j]
        if 0 <= j - x[i] <= 98:     
            dp[i][j] += dp[i - 1][j - x[i]]
ans = dp[-1][49]
# for i in range(n):
    # print(dp[i])
print(ans - 1)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
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

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
n, a = map(int, input().split())
x = list(map(int, input().split()))
for i in range(n):
    x[i] -= a
x.sort()
dp = [[0 for j in range(99)] for i in range(n)]
# print(dp)
for i in range(n):
    if i == 0:
        dp[i][49] = 1
        dp[i][x[i] + 49] = 1
        continue
    for j in range(99):
        dp[i][j] = dp[i - 1][j]
        if 0 <= j - x[i] <= 98: 
            dp[i][j] += dp[i - 1][j - x[i]]
ans = dp[- 1][49]
# for i in range(n):
    # print(@dp[i])
print(ans - 1)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
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

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
n, a = map(int, input().split())
x = list(map(int, input().split()))
for i in range(n):
    x[i] -= a
x.sort()
# print("x =",x)
ans = 0 

# if x[0] == 0 and len(set(x)) == 1:
#     print()

def dfs(i, total, cnt):
    # print(i)
    global ans
    # if i == n and total == 0 and cnt > 0:
    #     ans += 1
    #     return
    # if i == n or total > 0:
    #     return 
    if i == n:
        if total == 0 and cnt > 0:
            ans += 1
        return
    if total > 0:
        return
    if total == 0 and i != 0 and cnt > 0:
        ans += 1
        return 
        # print("total = %d, i = %d, cnt = %d" % (total, i, cnt))
    dfs(i + 1, total + x[i], cnt + 1) or dfs(i + 1, total, cnt)

dfs(0, 0, 0)

print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    x[i]=x[i]-a
    
n2=n//8
n3=n-n2*8

#n2=n//4
#n3=n-n2*4

y1=[]
y2=[]
y3=[]
y4=[]
y5=[]
y6=[]
y7=[]
y8=[]
for i in range(n2):
    y1.append(x[i])
    y2.append(x[i+n2])
    y3.append(x[i+n2*2])
    y4.append(x[i+n2*3])
    y5.append(x[i+n2*4])
    y6.append(x[i+n2*5])
    y7.append(x[i+n2*6])
    y8.append(x[i+n2*7])
y9=[]
for i in range(n3):
    y9.append(x[i+n2*4])
    

# itertools 使用 bit全探索
import itertools

def xdic(n2,xx):
    xsum=dict()
    for i in itertools.product([0,1], repeat=n2):
        isum=0
        for ii in range(n2):
            if i[ii]==0:
                isum=isum+xx[ii]
        if isum in xsum:
            xsum[isum]=xsum[isum]+1
        else:
            xsum[isum]=1
    return xsum

xsum1=xdic(n2,y1)
xsum2=xdic(n2,y2)
xsum3=xdic(n2,y3)
xsum4=xdic(n2,y4)
xsum5=xdic(n2,y5)
xsum6=xdic(n2,y6)
xsum7=xdic(n2,y7)
xsum8=xdic(n2,y8)
xsum9=xdic(n3,y9)
  
#xsum[0]=xsum[0]
#print(xsum)        
    
icnt=0
for xs1 in xsum1.items():
    for xs2 in xsum2.items():
        for xs3 in xsum3.items():
            for xs4 in xsum4.items():
                for xs5 in xsum5.items():
                    for xs6 in xsum6.items():
                        for xs7 in xsum7.items():
                            for xs8 in xsum8.items():
                                for xs9 in xsum9.items():
                                    if xs1[0]+xs2[0]+xs3[0]+xs4[0]+xs5[0]+xs6[0]+xs7[0]+xs8[0]+xs9[0]==0:
                                        icnt=icnt+xs1[1]*xs2[1]*xs3[1]*xs4[1]*xs5[1]*xs6[1]*xs7[1]*xs8[1]*xs9[1]

print(icnt-1)

Submission status: Wrong Answer

Solution code:
import itertools
import math
 
def comb(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)
 
n,a = map(int,input().split())
 
t = list(map(int,input().split()))
 
memo = [0]*51
 
for i in t:
    memo[i] += 1
 
typecount = []
 
ans = 0
 
for i in t:
    if i != a:
        typecount.append(i)
 
for i in range(1,len(typecount)):
    for j in itertools.combinations(typecount,i):
        if sum(j)/len(j)==a:
            #print(j)
            ans += 2**(memo[a])
            
 
if 0 < memo[a]:
    for i in range(1,memo[a]+1):
        ans += comb(memo[a], i)
 
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import math
 
def comb(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)
 
n,a = map(int,input().split())
 
t = list(map(int,input().split()))
 
memo = [0]*51
 
for i in t:
    memo[i] += 1
 
typecount = []
 
ans = 0
 
for i in t:
    if i != a:
        typecount.append(i)
 
for i in range(1,len(typecount)):
    for j in itertools.combinations(typecount,i):
        if int((sum(j)/len(j))*100) == int(sum(j)/len(j))*100:
            if int(sum(j)/len(j))==a:
                #print(j)
                ans += 2**(memo[a])
            
 
if 0 < memo[a]:
    for i in range(1,memo[a]+1):
        ans += comb(memo[a], i)
 
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import collections

def comb(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)

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

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

memo = [0]*51

for i in t:
    memo[i] += 1

typecount = []

ans = 0

for i in t:
    if i != a:
        typecount.append(i)


            

if 0 < memo[a]:
    for i in range(1,memo[a]+1):
        ans += comb(memo[a], i)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
 
n, a = map(int, input().split())
x = np.array(list(map(int, input().split())))
 
dp = {0:1}
for y in x-a:
    for k, v in dp.copy().items():
        print("before",dp)
        dp[y+k] = dp.get(y+k, 0) + v
        print("after",dp)
 
print(dp[0]-1)

Submission status: Wrong Answer

Solution code:
n, a = map(int,input().split())
l = list(map(int, input().split()))
l = [_-a for _ in l]

from itertools import combinations

temp = []
for i in range(1, n):
    temp += list(combinations(l, i))

x = 0
for j in temp:
    if sum(j) == 0:
        x += 1

print(x)

Submission status: Wrong Answer

Solution code:
n, a = map(int,input().split())
l = list(map(int, input().split()))

from itertools import combinations

temp = []
for i in range(1, n):
    temp += list(combinations(l, i))

x = 0
for j in range(len(temp)):
    if sum(temp[j]) / len(temp[j]) == a:
        x += 1

print(x)

Submission status: Wrong Answer

Solution code:
import itertools
from statistics import mean

N,A = list(map(int, input().split()))
x = list(map(int, input().split()))
cnt = 0
for i in range(N):
    for y in itertools.combinations(x, i):
        z = list(y)
        
        if len(z) > 0 and A == mean(z):
            cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
input_data1 = input()
input_data2 = input()
na_list = input_data1.split(" ")
n = int(na_list[0])
a = int(na_list[1])

x_list = [int(num) for num in input_data2.split(" ")]

def count_func(sum_count,a_count,list):
    list_len = len(list)
    sum = 0
    if list_len == 0:
        return 0
    for i in range(list_len):
        if a_count-list[i] == 0 and sum_count == 1:
            sum += 1
        elif a_count-list[i] == 0 or sum_count == 1:
            pass
        else:
            sum += count_func(sum_count-1,a_count-list[i],list[i+1:])
    return sum

result = 0
for i in range(n):
    if x_list[i] == a:
        result += 1
for i in range(2,n):
    result += count_func(i,i*a,x_list)
print(result)

Submission status: Wrong Answer

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

B = 0
#組み合わせの出力
import itertools
import numpy as np

for i in range(1, N + 1):
    print(list(itertools.combinations(X, i)))
    #平均の出力
    for j in itertools.combinations(X, i):
        #print(np.mean(j))
        if np.mean(j) == A:
            B += 1
print(B)

Submission status: Wrong Answer

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

B = 0
#組み合わせの出力
import itertools
import numpy as np

for i in range(N):
    #print(list(itertools.combinations(X, i)))
    #平均の出力
    for j in itertools.combinations(X, i):
        #print(np.mean(j))
        if np.mean(j) == A:
            B += 1

print(B)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def array(*args, initial=0):
    pre = "["*len(args)
    post = ""
    for a in args[::-1]:
        post += " for _ in range("+str(a)+")]"
    S = pre + str(initial) + post
    return eval(S)


def solve(N: int, A: int, x: "List[int]"):
    M = sum(x)
    # Nまで考慮, 使用した個数（Nまで）, 合計値
    DP = array(N+1, N+1, M+1)
    DP[0][0][0] = 1

    for i, a in enumerate(x, start=1):
        for j in range(N+1):
            for tot in range(M+1):
                DP[i][j][tot] = DP[i-1][j][tot]  # 使わない時
                if tot - a >= 0:                 # 使う時
                    DP[i][j][tot] += DP[i-1][j-1][tot-a]

    ans = 0
    for j in range(1, N+1):
        for tot in range(M+1):
            if abs(tot / j-A) < 0.1:
                ans += DP[-1][j][tot]
    print(ans)
    # print(*DP[-1], sep="\n")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, x)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
dp = [[-1] * 10000] * 110

N,A = [int(i) for i in input().split()]
x = [int(i)-A for i in input().split()]
x = [0] + x
#print(x)

def dpf(n, cum):
    #print([n, cum])
    if dp[n][cum]>=0:
        pass
    elif n==1:
        dp[n][cum] = 0
        if cum == x[n]:
            dp[n][cum] += 1
        if cum == 0:
            dp[n][cum] += 1
    else:
        tmp = dpf(n-1, cum) + dpf(n-1, cum - x[n])
        dp[n][cum] = dp[n-1][cum]+dp[n-1][cum-x[n]]
    #print([n, cum] + [dp[n][cum], dp[n-1][cum]+dp[n-1][cum-x[n]]])
    return dp[n][cum]

#print(dpf(3, -1))
#print(dpf(3, -1))
print(dpf(N, 0)-1)

Submission status: Wrong Answer

Solution code:
import itertools

n, a = map(int, input().split())
cards = list(map(int, input().split()))
combi = []
m = len(cards)
if m > a:
  m = a
for i in range(2, m + 1):
  combi += itertools.combinations(cards, i)
r = 0
for i in range(len(cards)):
    if cards[i] == a:
        r += 1
for i in range(len(combi)):
  if sum(combi[i]) / len(combi[i]) == a:
    r += 1
print(r)

Submission status: Wrong Answer

Solution code:
import itertools

n, a = map(int, input().split())
cards = list(map(int, input().split()))
combi = []
for i in range(len(cards)):
  combi += itertools.combinations(cards, i)
r = 0
for i in range(len(combi)):
  if sum(combi[i]) == a:
    r += 1
print(r)