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 factorial(n):
    k = 1
    for i in range(n): k *= (i + 1)
    return k

def binomial(a, b):
    return factorial(a) // (factorial(a - b) * factorial(b))

cache = {}

def s(x, a, k, i):
    key = (a, k, i)
    if key in cache: return cache[key]
    if i == 51: return 0
    if a < 0: return 0
    if k < 0: return 0
    if k == 0:
        if a == 0: return 1
        else: return 0
    if i > a: return 0
    c = s(x, a, k, i + 1)
    for j in range(1, x[i] + 1):
        c += binomial(x[i], j) * s(x, a - i * j, k - j, i + 1)
    cache[key] = c
    return c

n, a = map(int, input().split())
x = [0] * 51
for k in input().split():
    x[int(k)] += 1

c = 0
for i in range(1, n + 1):
    c += s(x, a * i, i, 0)
print(c)

Submission status: Wrong Answer

Solution code:
def c_Tak_and_Cards(N, A, S):
    X = max(S + [A])
    y = [x - A for x in S]
    dp = [[0 for _ in range(2 * N * X + 1)] for _ in range(N + 1)]
    dp[0][N * X] = 1
    for j in range(N):
        for t in range(X, (2 * N - 1) * X):
            dp[j + 1][t] = dp[j][t] + dp[j][t - y[j]]
    return dp[N][N * X] - 1
N,A = [int(i) for i in input().split()]
S = [int(i) for i in input().split()]
print(c_Tak_and_Cards(N, A, S))

Submission status: Wrong Answer

Solution code:
from itertools import combinations as C
N, A = map(int, input().split())
x = list(map(int, input().split()))
ans = 0
for i in range(1, N+1):
    tmp = list(C(x, i))
    for t in tmp:
        ans += (sum(t) // len(t)) == A
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, A = map(int, raw_input().split())
x = map(int, raw_input().split())
dp = np.full((55, 55, 55**2), -1)
def dfs(i, t, W):
    if t == 0:
        return int(W == 0)
    if i < 0:
        return 0
    if dp[i, t, W] > -1:
        return dp[i, t, W]
    dp[i, t, W] = dfs(i-1, t, W) + dfs(i-1, t-1, W-x[i])
    return dp[i, t, W]

ans = 0
for T in range(1, N+1):
    ans += dfs(N-1, T, T*A)
print ans

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import itertools

n,a = map(int,raw_input().split())
x = map(int,raw_input().split())
ans = 0
for p in itertools.product([True, False], repeat = n):
    tmp = 0
    for i in range(n):
        tmp += x[i] if p[i] else 0
    average = 1.0*tmp/sum(p) if sum(p)>0 else 0 
    if(average == int(average) and average == a):
        ans += 1 
    print(p)
print (ans)

Submission status: Wrong Answer

Solution code:
n, a = input().split()                                                      
n, a = int(n), int(a)                                                       
x_ = input().split()                                                        
for i in range(len(x_)):                                                    
    x_[i] = int(x_[i])                                                      
#x = [i-a for i in x_]                                                      
cnt = 0                                                                     
dp = [ [ [ 0 for s in range(n*a)] for k in range(n+1)] for j in range(n+1)] 
def solve(j, k, s):                                                         
    if j == 0 and k == 0 and s == 0:                                        
        #dp[j][k][s] = 1                                                    
        return 1                                                            
    elif j >= 1 and s < x_[j-1]:                                            
        #dp[j][k][s] = solve(j-1, k, s)                                     
        return solve(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]]                  
        #dp[j][k][s] = solve(j-1, k, s)+solve[j-1][k-1][s-x_[j]]            
        return solve(j-1, k, s)+solve(j-1, k-1, s-x_[j-1])                  
    else:                                                                   
        #dp[j][k][s] = 0                                                    
        return 0                                                            
    #return dp[j][k][s]                                                     
                                                                            
total = 0                                                                   
for i in range(n):                                                          
    dp[n-1][i][i*a] = solve(n, i, i*a)                                      
                                                                            
for i in range(n):                                                          
    total += dp[n-1][i][i*a]                                                
if total -1 < 0:                                                            
    print(0)                                                                
else:                                                                       
    print(total-1)

Submission status: Wrong Answer

Solution code:
n, a = input().split()                                                      
n, a = int(n), int(a)                                                       
x_ = input().split()                                                        
for i in range(len(x_)):                                                    
    x_[i] = int(x_[i])                                                      
#x = [i-a for i in x_]                                                      
cnt = 0                                                                     
dp = [ [ [ 0 for s in range(n*a)] for k in range(n+1)] for j in range(n+1)] 
def solve(j, k, s):                                                         
    if j == 0 and k == 0 and s == 0:                                        
        #dp[j][k][s] = 1                                                    
        return 1                                                            
    elif j >= 1 and s < x_[j-1]:                                            
        #dp[j][k][s] = solve(j-1, k, s)                                     
        return solve(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]]                  
        #dp[j][k][s] = solve(j-1, k, s)+solve[j-1][k-1][s-x_[j]]            
        return solve(j-1, k, s)+solve(j-1, k-1, s-x_[j-1])                  
    else:                                                                   
        #dp[j][k][s] = 0                                                    
        return 0                                                            
    #return dp[j][k][s]                                                     
                                                                            
total = 0                                                                   
for i in range(n):                                                          
    dp[n-1][i][i*a] = solve(n, i, i*a)                                      
                                                                            
for i in range(n):                                                          
    total += dp[n-1][i][i*a]                                                
print(total-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 火 11/ 8 17:04:53 2016

# Usage
#
"""

from itertools import repeat
from itertools import combinations
import sys

from statistics import mean

def read_input():
    first = input().split(" ")
    N = int(first[0])
    A = int(first[1])

    x_list = [int(i) for i in input().split(" ")]

    return N, A, x_list


def naive_checker(num_list, target_mean):
    """
    >>> naive_checker([7,9,8,9], 8)
    5
    >>> naive_checker([6,6,9], 8)
    0
    >>> naive_checker([3,6,2,8,7,6,5,9], 5)
    19
    """
    ans = 0
    for i in range(1, len(num_list)):
        for n in combinations(num_list, i):
            if mean(n) == target_mean:
                ans += 1
    print(ans)

if __name__ == '__main__':
    # import doctest
    # doctest.testmod()

    N, A, x_list = read_input()

    naive_checker(x_list, A)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, A = [int(t) for t in input().split()]
x = [int(i) for i in input().split()]

K = max(x) * A
dp = np.zeros((51, 51, 2601))
dp[0, 0, 0] = 1

for i in range(N):
    for j in range(N):
        for k in range(sum(x)):
            if dp[i, j, k] == 0:
                continue
            dp[i+1, j+1, k+x[i]] += dp[i, j, k]
            dp[i+1, j, k] += dp[i, j, k]

print(sum(dp[N, j, j*A] for j in range(1, N+1)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    n, a = reads()
    x = reads()
    dp = defaultdict(lambda: 0)
    dp[(0,0,0)] = 1
    for i in range(n):
        for j in range(n):
            for k in range(n*50):
                dp[(i,j+1,k)] += dp[(i,j,k)]
                dp[(i+1,j+1,k+x[i])] += dp[(i,j,k)]
    r = 0
    for i in range(1, n+2):
        r += dp[(i,n,i*a)]
    print(r)

main()

Submission status: Wrong Answer

Solution code:
line = raw_input()
n = int(line.split(' ')[0])
a = int(line.split(' ')[1])

cards = [int(x) for x in raw_input().split(' ')]

memo = [0] * (1 << n)

for i in range(0, n):
    idx = 1 << i
    for j in range(0, idx):
        memo[idx + j] = (cards[i] + memo[j]) % a

print memo.count(0) - 1

Submission status: Wrong Answer

Solution code:
line = raw_input()
n = int(line.split(' ')[0])
a = int(line.split(' ')[1])

cards = [int(x) for x in raw_input().split(' ')]

memo = [0]

for i in range(0, n):
    idx = 1 << n
    for j in range(0, 1 << i):
        memo.append((cards[i] + memo[j]) % a)

print memo.count(0) - 1

Submission status: Wrong Answer

Solution code:
import itertools
N, A = [int(i) for i in input().split()]
x = [int(i) - A for i in input().split()] 
# card num
count = 0
for i in range(1, N):
    # combination
    for element in itertools.combinations(x, i):
        #print(element)
        if sum(element) == 0:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
def app(numlist, A ):
  counter = 0
  N = len(numlist)
  for i in range(1,N):
    counter += f(numlist, i, A*i)
  return int(counter)

def f(numlist, rest, sum):
  result = 0
  numset = set(numlist)
  if rest == 1:
    return numlist.count(sum)

  elif rest == 2:
    for big in numset:
      if (sum - big in numset) and (big >= sum - big):
        result += counter(numlist, big, sum-big)
    return result
  else:
    for i in range(len(numlist)):
      result += f(numlist[i+1:], rest-1, sum-numlist[i] )
    # for i in numset:
    #   i_place = numlist.index(i)
    #   result += f(numlist[i_place+1:], rest-1, sum-i)
    return result


def counter(numlist, big, small):
  hist = mkhist(numlist)
  if big == small:
    N = hist[big]
    return N * (N - 1) / 2
  else: 
    big_N = hist[big]
    small_N = hist[small]
    return big_N * small_N

def mkhist(numlist):
  hist = dict()   
  for char in numlist:
    if not char in hist.keys():
      hist[char] = 1
    else:
      hist[char] += 1
  return hist

 
N, A = map(int, input().split(' '))
inputs = input()
 
inputnum = map(int, inputs.split(' '))
inputnum = sorted(list(inputnum))
 
print (app(inputnum, A))

Submission status: Wrong Answer

Solution code:

def app(numlist, A ):
  counter = 0
  N = len(numlist)
  for i in range(1,N):
    counter += f(numlist, i, A*i)
  return int(counter)
 
def f(numlist, rest, sum):
  result = 0
  numset = set(numlist)
  if rest == 1:
    return numlist.count(sum)
 
  elif rest == 2:
    for big in numset:
      if (sum - big in numset) and (big >= sum - big):
        result += counter(numlist, big, sum-big)
    return result
  else:
    for i in numset:
      i_place = numlist.index(i)
      result += f(numlist[i_place+1:], rest-1, sum-i)
    return result
 
 
def counter(numlist, big, small):
  hist = mkhist(numlist)
  if big == small:
    N = hist[big]
    return N * (N - 1) / 2
  else: 
    big_N = hist[big]
    small_N = hist[small]
    return big_N * small_N
 
def mkhist(numlist):
  hist = dict()   
  for char in numlist:
    if not char in hist.keys():
      hist[char] = 1
    else:
      hist[char] += 1
  return hist
 
 
 
 
N, A = map(int, input().split(' '))
inputs = input()
 
inputnum = map(int, inputs.split(' '))
inputnum = sorted(list(inputnum))
 
print (app(inputnum, A))

Submission status: Wrong Answer

Solution code:
def app(numlist, A ):
  counter = 0
  N = len(numlist)
  for i in range(1,N):
    counter += f(numlist, i, A*i)
  return counter

def f(numlist, rest, sum):
  result = 0
  numset = set(numlist)
  if rest == 1:
    return numlist.count(sum)

  elif rest == 2:
    for big in numset:
      if (sum - big in numset) and (big >= sum - big):
        result += counter(numlist, big, sum-big)
    return result
  else:
    for i in numset:
      i_place = numlist.index(i)
      result += f(numlist[i_place+1:], rest-1, sum-i)
    return result


def counter(numlist, big, small):
  hist = mkhist(numlist)
  if big == small:
    N = hist[big]
    return N * (N - 1) / 2
  else: 
    big_N = hist[big]
    small_N = hist[small]
    return big_N * small_N

def mkhist(numlist):
  hist = dict()   
  for char in numlist:
    if not char in hist.keys():
      hist[char] = 1
    else:
      hist[char] += 1
  return hist




N, A = map(int, input().split(' '))
inputs = input()

inputnum = map(int, inputs.split(' '))
inputnum = sorted(list(inputnum))

print (app(inputnum, A))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import itertools

if __name__ == '__main__':
    n, a = (int(i) for i in input().split())  
    xs = input().split()
    ans = 0
    for i in range(16):
        for element in itertools.combinations(xs, i):
            for e in element:
                sum += int(e)
            if a * i == sum:
                ans += 1
            sum = 0
    print(ans)

Submission status: Wrong Answer

Solution code:
N, A = map(int, input().split())
x = list(map(int, input().split()))
y = [n - A for n in x]
p = [k for k in y if k > 0]
n = [k for k in y if k < 0]
z = y.count(0)
a = 2**z - 1

def c(n):
	i = n
	a = 0
	b = 0
	while i != 0:
		a += (i%2)*10**b
		b += 1
		i = int(i/2)
	return(a)

s = []
t = []
for i in range(1,2**len(p)):
	s.append(str(c(i)))

for i in range(1,2**len(n)):
	t.append(str(c(i)))

e = 0
for i in s:
	c = 0
	for u, j in enumerate(i):
		if j == "1":
			c += p[u]
	for k in t:
		d = c
		for m, l in enumerate(k):
			if l == "1":
				d += n[m]
		if d == 0:
			e += 1
a = a + e*(a+1)
print(a)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n,a=map(int,raw_input().split())
x=map(int,raw_input().split())

el_plus = []
el_minus = []
sum_plus_dict = {"def":None}
sum_minus_dict = {"def":None}

x = [el - a for el in x]
count_zero = 0
count = 0

for i in range(len(x)):
    if x[i] > 0:
       el_plus.append(x[i])
    elif x[i] < 0:
        el_minus.append(x[i])
    else:
        count_zero += 1

if (el_plus == [] or el_minus == []):
    if count_zero==0:
        print 0
    else:
        print pow(2, count_zero) - 1
else:
    for i in range(len(el_minus)):
        el_minus[i] = el_minus[i] * (-1)
    dict_max = max(sum(el_plus), sum(el_minus))
    dict_min = min(sum(el_plus), sum(el_minus))
    for i in range(1, dict_max+1):
        sum_plus_dict.update({i:0})
        sum_minus_dict.update({i:0})

Submission status: Wrong Answer

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

# dp := x1, ... ,xjからk枚選んでxiの合計をｓにするような選び方の総数
dp = [[[0 for s in range(n * a + 1)] for k in range(n + 1)] for j in range(n + 1)]

for j in range(n + 1):
    dp[j][0][0] = 1

for j in range(1, n + 1):
    for k in range(1, j + 1):
        for s in range(1, n * a):
            if s < x[j - 1]:
                # 新たに加えることができない場合
                dp[j - 1][k][s] = dp[j - 2][k][s]
            elif s >= x[j - 1]:
                tmp_s = s - x[j - 1]
                dp[j - 1][k][s] = dp[j - 2][k][s] + dp[j - 2][k - 1][tmp_s]

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

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n,a=map(int,raw_input().split())
x=map(int,raw_input().split())

el_plus = []
el_minus = []
sum_plus_dict = {"def":None}
sum_minus_dict = {"def":None}

x = [el - a for el in x]
count_zero = 0
count = 0

for i in range(len(x)):
    if x[i] > 0:
       el_plus.append(x[i])
    elif x[i] < 0:
        el_minus.append(x[i])
    else:
        count_zero += 1
print count_zero
if (el_plus == [] or el_minus == []):
    if count_zero==0:
        print 0
    else:
        print pow(2, count_zero) - 1
else:
    for i in range(len(el_minus)):
        el_minus[i] = el_minus[i] * (-1)
    dict_max = max(sum(el_plus), sum(el_minus))
    dict_min = min(sum(el_plus), sum(el_minus))
    for i in range(1, dict_max+1):
        sum_plus_dict.update({i:0})
        sum_minus_dict.update({i:0})

    for i in range(1, len(el_plus)+1,):
        comb_sum_plus = combinations(el_plus, i)
        for comb in comb_sum_plus:
            sum_plus = sum(list(comb))

            sum_plus_dict[sum_plus] += 1
    for i in range(1, len(el_minus)+1):
        comb_sum_minus = combinations(el_minus, i)
        for comb in comb_sum_minus:
            sum_minus = sum(list(comb))
            sum_minus_dict[sum_minus] += 1

    for key in range(1, dict_min+1):
        if sum_plus_dict[key] > 0 and sum_minus_dict[key] > 0:
            count += sum_plus_dict[key] * sum_minus_dict[key] * pow(2, count_zero)
    count += pow(2, count_zero)-1
    print count

Submission status: Wrong Answer

Solution code:
from itertools import combinations
 
n,a=map(int,raw_input().split())
x=map(int,raw_input().split())
 
el_plus = []
el_minus = []
sum_plus_dict = {"def":None}
sum_minus_dict = {"def":None}
 
x = [el - a for el in x]
count_zero = 0
count = 0
 
for i in range(len(x)):
    if x[i] > 0:
       el_plus.append(x[i])
    elif x[i] < 0:
        el_minus.append(x[i])
    else:
        count_zero += 1
 
if el_plus == [] or el_minus == []:
    print 0
else:
    for i in range(len(el_minus)):
        el_minus[i] = el_minus[i] * (-1)
    for i in range(1, sum(el_plus)+1):
        sum_plus_dict.update({i:0})
 
    for i in range(1, sum(el_minus)+1):
        sum_minus_dict.update({i:0})
 
    for i in range(1, len(el_plus)+1,):
        comb_sum_plus = combinations(el_plus, i)
        for comb in comb_sum_plus:
            sum_plus = sum(list(comb))
            sum_plus_dict[sum_plus] += 1
    for i in range(1, len(el_minus)+1):
        comb_sum_minus = combinations(el_minus, i)
        for comb in comb_sum_minus:
            sum_minus = sum(list(comb))
            sum_minus_dict[sum_minus] += 1
 
    for key in range(1, min(sum(el_plus), sum(el_minus))+1):
        if sum_plus_dict[key] > 0 and sum_minus_dict[key] > 0:
            count += sum_plus_dict[key] * sum_minus_dict[key] * pow(2, count_zero)
    count += pow(2, count_zero)-1
    print count

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n,a=map(int,raw_input().split())
x=map(int,raw_input().split())

el_plus = []
el_minus = []
sum_plus_dict = {"def":None}
sum_minus_dict = {"def":None}

x = [el - a for el in x]
count_zero = 0
count = 0

for i in range(len(x)):
    if x[i] > 0:
       el_plus.append(x[i])
    elif x[i] < 0:
        el_minus.append(x[i])
    else:
        count_zero += 1

if el_plus == [] or el_minus == []:
    print 0
else:

    for i in range(1, sum(el_plus)+1):
        sum_plus_dict.update({i:0})

    for i in range(1, sum(el_minus)+1):
        sum_minus_dict.update({i:0})

    for i in range(1, len(el_plus)+1):
        sum_plus = sum(combinations(el_plus, i))
        sum_plus_dict[sum_plus] += 1
    for i in range(1, len(el_minus)+1):
        sum_minus = sum(combinations(el_minus, i))
        sum_minus_dict[sum_minus] += 1
    for key in sum_plus.keys():
        if sum_plus[key] > 0 and sum_minuus[key] > 0:
            count += sum_plus[key] * sum_minus[key] * pow(2, count_zero)
    print count

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, A = map(int, input().split(' '))
lst = tuple(map(int, input().split(' ')))

count = 0
for i in range(1, N+1):
    num = itertools.combinations(lst, i)
    
    for j in num:
        result = sum(list(j)) / i
        if result == A:
            count +=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
from datetime import date

def main():
	
	line = input().split()
	n = int(line[0])
	k = int(line[1])

	a = [int(x) for x in input().split()]
	ans = 0
	for mask in range(2**n):
		sum = 0
		cnt = 0
		for i in range(n):
			if (mask & (1 << i)) != 0:
				sum += a[i]
				cnt += 1

		if sum == cnt * k:
			ans += 1

	print(ans - 1)

main()

Submission status: Time Limit Exceeded

Solution code:
def dfs(i,k,goukei):
    global ans
    if i==n:
        if k != 0 and a * k == goukei:
            ans += 1
        return
    dfs(i+1,k,goukei)
    dfs(i+1,k+1,goukei+x[i])

n,a = map(int,input().split())
x = list(map(int,input().split()))
ans = 0
dfs(0,0,0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, A = MAP()
x = LIST()

dp = [[] for _ in range(sum(x)+1)]
dp[0].append(0)

for y in x:
	for i in range(sum(x)-y, -1, -1):
		if dp[i]:
			for z in dp[i]:
				dp[i+y].append(z+1)

ans = 0
for i in range(1, sum(x)//A + 1):
	ans += Counter(dp[i*A])[i]

print(ans)

Submission status: Time Limit Exceeded

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

arr = list(map(int, input().split()))
from itertools import  combinations
res = 0
for i in range(1, n+1):
    for j in combinations(arr, i):
        if sum(j) / i == a:
            res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
n,a=map(int,input().split())
l=list(map(int,input().split()))
ans=0
for p in product((0,1),repeat=n):
    s=0
    c=0
    for i,b in enumerate(p):
        if b==1:
            s+=l[i]
            c+=1
    if c!=0 and s/c==a:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def dfs(i,kazu,ans):
    global cnt
    if i==n:
        if kazu * a == ans and ans != 0:
            cnt += 1
        return
    else:
        #使わない場合
        dfs(i+1,kazu,ans)
        #使う場合
        dfs(i+1,kazu+1,ans + x[i])
    
    
cnt = 0
n,a = map(int,input().split())
x = list(map(int,input().split()))

dfs(0,0,0)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools
N, A = map(int, input().split())
x_array = np.array([int(x) for x in input().split()])
array = x_array - A
count = 0

# arrayのうち和が0となる組の数を数えればよい
for i in range(1, len(array)+1):
    for x_tuple in itertools.combinations(array, i):
        if sum(x_tuple) == 0:
            count += 1
        
print(count)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(2 ** N):
    check = []
    for j in range(N):
        if ((i >> j) & 1):
            check.append(X[j])
    # print(check)
    if len(check) > 0 and (sum(check) / len(check)) == A:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N, A = map(int, input().split())
from itertools import combinations, permutations
lst = list(map(int, input().split()))

def main():
    count = 0
    for i in range(1, N+1):
        for j in combinations(lst, i):
            if sum(j) / i == A:
                count += 1 
    print(count)
        

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N, A = map(int, input().split())
from itertools import combinations
lst = list(map(int, input().split()))

def main():
    count = 0
    for i in range(1, N+1):
        for j in combinations(lst, i):
            if sum(j) / i == A:
                count += 1 
    print(count)
        

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N, A = map(int, input().split())
from itertools import combinations
lst = list(map(int, input().split()))

count = 0
for i in range(1, N+1):
    for j in combinations(lst, i):
        if sum(j) / i == A:
            count += 1 
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
N,A = (int(T) for T in input().split())
X = [int(T) for T in input().split()]
Count = 0
for TB in product([0,1],repeat=N):
    Card = list(TB)
    UseN = sum(Card)
    if A*UseN==sum(TX*TC for TX,TC in zip(X,Card)) and UseN>=1:
        Count += 1
print(Count)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

		
#階乗#
lim = 50  #必要そうな階乗の限界を入力
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1]

def C(n, r):
	return fact[n]//fact[r]//fact[n-r]

N, A = LIST()
x = LIST()

x_sum = sum(x)
x_cnt = Counter(x)
p = [[] for _ in range(x_sum+1)]  #p[i]はiを作ることが可能な数字の組み合わせ
p[0].append([])

for v in x:
	for i in range(x_sum, v-1, -1):
		if p[i-v]:
			for u in p[i-v]:
				y = u.copy()
				y.append(v)
				y.sort()
				if not y in p[i]:
					p[i].append(y)

ans = 0
for i in range(1, N+1):
	if x_sum < A*i:
		break
	for a in p[A*i]:
		if len(a) == i:
			cnt = 1
			for key, value in Counter(a).items():
				cnt *= C(x_cnt[key], value)
			ans += cnt


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

		
#階乗#
lim = 50  #必要そうな階乗の限界を入力
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1]

def C(n, r):
	return fact[n]//fact[r]//fact[n-r]

N, A = LIST()
x = LIST()


x_cnt = Counter(x)
p = [[] for _ in range(sum(x)+1)]  #p[i]はiを作ることが可能な数字の組み合わせ
p[0].append([])

for v in x:
	for i in range(sum(x), v-1, -1):
		if p[i-v]:
			for u in p[i-v]:
				y = u.copy()
				y.append(v)
				y.sort()
				if not y in p[i]:
					p[i].append(y)

ans = 0
for i in range(1, N+1):
	if sum(x) < A*i:
		break
	for a in p[A*i]:
		if len(a) == i:
			cnt = 1
			for key, value in Counter(a).items():
				cnt *= C(x_cnt[key], value)
			ans += cnt


print(ans)

Submission status: Time Limit Exceeded

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

all_perms = []

def per(index, perm):
    if index == n:
        all_perms.append(perm)
        return
    perm1 = [i for i in perm]
    per(index+1, perm1)

    perm2 = [i for i in perm]
    perm2.append(x[index])
    per(index+1, perm2)


per(0, [])
cnt = 0
for perm in all_perms:
    if len(perm) == 0:
        continue
    average = sum(perm) / len(perm)
    if average == a:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
L = list(map(int,input().split()))

cnt = 0
for i in range(1<<n):
    sum1 = 0
    l = 0
    for j in range(n):
        if i>>j&1:
            sum1 +=L[j]
            l +=1
    if l != 0:
        if sum1/l == k:
            cnt +=1
            
print(cnt)