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: Time Limit Exceeded

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

for i in range(n):
    x[i]=x[i]-a
    
# itertools 使用 bit全探索
import itertools
icnt=0
for i in itertools.product([0,1], repeat=n):
    isum=0
    for ii in range(n):
        if i[ii]==0:
            isum=isum+x[ii]
    if isum==0:
        icnt=icnt+1

print(icnt-1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def solve(n, a, lst):
  m = max(max(lst), a)
  ans = np.zeros((n+1, n+1, n*m+1))
  #ans[i][j][k] : lst[:i]までの中からj枚選んで合計kにする選び方
  for i in range(n+1):
    for j in range(n+1):
      for k in range(n*m+1):
        if i == 0 and j == 0 and k == 0:
          ans[i][j][k] = 1
        elif i >= 1 and k < lst[i-1]:
          ans[i][j][k] = ans[i-1][j][k]
        elif i >= 1 and lst[i-1] <= k and j >= 1:
          ans[i][j][k] = ans[i-1][j-1][k-lst[i-1]] + ans[i-1][j][k]
        else:
          ans[i][j][k] = 0
  ret = 0
  for i in range(1,n+1):
    ret += ans[-1][i][i*a]
  return int(ret)

if __name__ == "__main__":
  n, a = map(int,input().split())
  x_list = [int(i) for i in input().split()]
  ans = solve(n,a,x_list)
  print(ans)

Submission status: Time Limit Exceeded

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

result=0

for i in range(2**N):
    list2 =[]
    for j in range(N):
        if (i >> j) &1 == 1:
            list2.append(cards[j])
    if len(list2)!=0:
        ave =sum(list2)/len(list2)
        if ave==A:
            result+=1

print(result)

Submission status: Time Limit Exceeded

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

from statistics import mean

result=0

for i in range(2**N):
    list2 =[]
    for j in range(N):
        if (i >> j) &1 == 1:
            list2.append(cards[j])
    if len(list2)!=0:
        if mean(list2)==A:
            result+=1

print(result)

Submission status: Time Limit Exceeded

Solution code:
N,A=map(int,input().split())
X=list(map(int,input().split()))
ans=0
for b in range(1,2**N):
  s=0
  c=0
  for i in range(N):
    if b&(1<<i):
      s+=X[i]
      c+=1
  if s==A*c: ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,A = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
ans = 0
for i in range(2 ** n):
    wa = 0
    kazoeru = 0
    for j in range(n):
        if ((i >> j)&1):
            wa += l[j]
            kazoeru += 1
    if kazoeru * A == wa:
      ans += 1
print(ans-1)

Submission status: Time Limit Exceeded

Solution code:
#44c
N,A = map(int, input().split()) #N<=50
x_list = [int(e) for e in input().split()]

ans = 0

#bit全探索
for i in range(1,2**(N)):
    bit_array = str(bin(i)[2:]).zfill((N))
    #print(bit_array)

    total = 0
    devide_by = 0
    
    for j in range(len(bit_array)):

        if bit_array[j]=="0":
            #OFF時の処理
            pass
        elif bit_array[j]=="1":
            #ON時の処理
            total += x_list[j]
            devide_by += 1
            
    #ON・OFFの状態設定後の処理
    if total/devide_by == A:
        #print("!")
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
n,a=map(int,input().split())
x=[0]+list(map(int,input().split()))
su=sum(x)
dp=[[[0 for k in range(su+1)] for j in range(51)] for i in range(51)]
dp[0][0][0]=1
for i in range(1,n+1):
    for j in range(i+1):
        for k in range(su+1):
            if k<x[i]:
                dp[i][j][k]=dp[i-1][j][k]
            if k>=x[i] and j>=1:
                dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]]
ans=0
for t in range(1,n+1):
    if a*t<=su:
        ans+=dp[n][t][a*t]
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
n,a=map(int,input().split())
x=[0]+list(map(int,input().split()))
dp=[[[0 for k in range(2501)] for j in range(51)] for i in range(51)]
dp[0][0][0]=1
for i in range(1,n+1):
    for j in range(i+1):
        for k in range(n*a+1):
            if k<x[i]:
                dp[i][j][k]=dp[i-1][j][k]
            if k>=x[i] and j>=1:
                dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]]
ans=0
for t in range(1,n+1):
    ans+=dp[n][t][a*t]
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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+1):
    temp += list(combinations(l, i))

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

print(x)

Submission status: Time Limit Exceeded

Solution code:
n,a=map(int,input().split())
x=list(map(int,input().split()))
ans=0
dp=[[[0]*(sum(x)+1) for i in range(n+1)] for j 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(sum(x)+1):
      if i>=1 and k>=x[i-1] and j>=1:
        dp[i][j][k]=dp[i-1][j-1][k-x[i-1]]+dp[i-1][j][k]
      elif i>=1:
        dp[i][j][k]=dp[i-1][j][k]
for j in range(1,n+1):
  for k in range(sum(x)+1):
    if k%j==0 and k//j==a:
      ans+=dp[n][j][k]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
INF = 10**10
MOD = 10**9 + 7
sys.setrecursionlimit(100000000)
from functools import lru_cache
from itertools import permutations
from math import factorial


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

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

    for i in range(n):
        num = x[i]
        for j in range(1,n + 1):
            for s in range(n * a + 1):
                if s - num >= 0:
                    dp[i + 1][j][s] = dp[i][j][s] + dp[i][j - 1][s - num]
                else:
                    dp[i + 1][j][s] = dp[i][j][s]
    
    ans = 0
    for i in range(1,n + 1):
        ans += dp[-1][i][i * a]
    print(ans)
    

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
readline = sys.stdin.buffer.readline

n,a = map(int,readline().split())
lst1 = list(map(int,readline().split()))

dig = n #桁数
bit_mask = list(itertools.product([0,1],repeat=dig))
ans = 0
for i in bit_mask:
    res = 0
    num = 0
    for j,k in enumerate(i):
        if k == 1:
            res += lst1[j]
            num += 1
    try:
        if res/num == a:
            ans += 1
    except:
        pass

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,a=map(int,input().split())
x=list(map(int,input().split()))
l=max(max(x)*n+3,a*n+3)
dp=[[l*[0]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(l):dp[i][j][k]=dp[i-1][j][k]
  for j in range(1,i+1):
    for k in range(x[i-1],l):dp[i][j][k]+=dp[i-1][j-1][k-x[i-1]]
ans=0
for j in range(1,n+1):
  ans+=dp[-1][j][j*a]
print(ans)

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
from itertools import combinations
N,A=map(int,input().split())
x=input().split()
numbers=[int(n) for n in x]
count=2
answer=0
for z in numbers:
    if z==A:
        answer+=1
    else:
        pass

while N-count>=0:
    a=list(combinations(numbers,count))
    for b in a:
        c=sum(b)/count
        if c==A:
            answer+=1
        else:
            pass
    count+=1

print(answer)

Submission status: Time Limit Exceeded

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

ans = 0

for bit in range(1 << N):
  total = 0
  count = 0

  for i in range(N):
    if bit & (1 << i):
      total += X[i]
      count += 1

  if count != 0:
    if total / count == A:
      ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, a = map(int, input().split())
cards = list(map(int, input().split()))
combi = []
for i in range(2, len(cards) + 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: Time Limit Exceeded

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

for i in range(n):
    for j in range(1,n+1):
        if i+1 == j:
            #print('ngo',i,j,sum(x[:i]))
            dp[i][j][sum(x[:i+1])] = 1
            break
        for k in range(a*n+1):
            if k-x[i] >= 0:
                dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i]]
            else:
                dp[i][j][k] = dp[i-1][j][k]
            if j == 1 and x[i] == k:
                dp[i][j][k] += 1

"""
for i in range(n):
    for j in range(1,n+1):
        if j>i+1:
            break
        for k in range(n*a+1):
            if dp[i][j][k] != 0:
                print('dp[{}][{}][{}]={}'.format(i,j,k,dp[i][j][k]))
"""


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

Submission status: Time Limit Exceeded

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

def make_array(dims,fill):
    if len(dims) == 1:
        return [fill]*dims[0]
    ret = []
    nxt = dims[1:]
    for i in range(dims[0]):
        ret.append(make_array(nxt,fill))
    return ret
S = sum(X)+1
dp = make_array([N+2,N+2,S],0)
dp[0][0][0] = 1
for i in range(N):
    for j in range(N):
        for s in range(S-X[i]):
            dp[i+1][j+1][s+X[i]] += dp[i][j][s]
            dp[i+1][j][s] += dp[i][j][s]
ans = 0
for j in range(1,N+1):
    for s in range(1,S+1):
        if j*A == s:
            ans += dp[-2][j][s]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,A = map(int,input().split())
X = list(map(int,input().split()))
ans = 0
for i in range(1,2**N):
    state = format(i,'0%ib'%(N))
    value = 0
    count = 0
    for j,s in enumerate(state):
        if s == '1':
            value += X[j]
            count += 1
    if value == A*count:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
    for j in range(i + 1):
        for k in range(2451):
            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][j * a]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

N, A = map(int, input().split())
x = list(map(int, input().split()))
sum_x = sum(x)
X = max(x + [A])

answer = 0

@lru_cache(maxsize=None)
def solve(j, k, s):
    global x
    if j == 0 and k == 0 and s == 0:
        return 1
    elif j >= 1 and s < x[j - 1]:
        return solve(j-1, k, s)
    elif j >= 1 and k >= 1 and s >= x[j - 1]:
        return solve(j-1, k, s) + solve(j-1, k - 1, s - x[j - 1])
    else:
        return 0

for k in range(1, N + 1):
    answer += solve(N, k, k * A)
print(answer)

Submission status: Time Limit Exceeded

Solution code:
N, A = map(int, input().split())
x = list(map(int, input().split()))
sum_x = sum(x)
X = max(x + [A])

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

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

print(answer)

Submission status: Time Limit Exceeded

Solution code:
N, A = map(int, input().split())
x = list(map(int, input().split()))
sum_x = sum(x)
X = max(x + [A])

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

for j in range(len(dp)):
    for k in range(len(dp[j])):
        for s in range(len(dp[j][k])):
            if j == 0 and k == 0 and 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:
                dp[j][k][s] = 0

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

print(answer)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

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

def dfs(i, num, sum):      
  if i >= len(x):
    return 0
  else: 
    r = dfs(i+1, num + 1, sum + x[i])
    r += dfs(i+1, num, sum)
    sum += x[i]
    if (sum) / num == a:
      r += 1
      #print(" i = {} x = {} sum = {} num = {} r = {}".format(i, x[i],num,  sum, r ))
    return (r)
    
r = dfs(0,1,0)
print(r)

Submission status: Time Limit Exceeded

Solution code:
n,a=map(int,input().split())
x=list(map(int,input().split()))
x.sort(reverse=True)
sx=sum(x)
dp=[[0]*(n+1) for i in range(sx+1)]
dp[0][0]=1
for i in range(n):
    dp_sub=[[0]*(n+1) for j in range(sx+1)]
    for j in range(sx+1):
        for k in range(n+1):
            if (j==0 and k==0) or dp[j][k]!=0:
                dp_sub[j+x[i]][k+1]=dp[j][k]
    for j in range(sx+1):
        for k in range(n+1):
            dp[j][k]+=dp_sub[j][k]
cnt=0

for i in range(min(sx//a,n)):
    cnt+=dp[a*(i+1)][i+1]
#print(dp)
print(cnt)

Submission status: Time Limit Exceeded

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

ans = 0

for n in range(1, N+1):
  for bit in range(1 << N):
    s = []

    for index, i in enumerate(li):
      if bit & (1 << index):
        s.append(i)

    if len(s) == n:
      if sum(s) / len(s) == A:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

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

res = 0

for i in range(1,2**n):
    sum = 0
    num = 0
    for j in range(n):
        if ((i >> j) & 1):
            sum += x[j]
            num += 1
    if num != 0:
        ave = sum / num
    if ave == a:
        res += 1
print(res)

Submission status: Time Limit Exceeded

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

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

dp[0][0][0]=1
dp[0][1][x[0]]=1
for i in range(1, N):
  dp[i][0][0]=1
  for j in range(1, i+2):
    for k in range(2501):
      if k-x[i]>=0:
        dp[i][j][k]=dp[i-1][j-1][k-x[i]]+dp[i-1][j][k]
      else:
        dp[i][j][k]=dp[i-1][j][k]
        
print(sum([dp[-1][j][A*j] for j in range(1, N+1)]))

Submission status: Time Limit Exceeded

Solution code:
import itertools
from statistics import mean

a = float(input().split(' ')[1])
x = [int(i)for i in input().split(' ')]
select = 0
for i in range(1, len(x)+1):
    for j in itertools.combinations(x,i):
        if mean(j) == a:
            select += 1

print(select)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from statistics import mean

a = float(input().split(' ')[1])
x = [int(i)for i in input().split(' ')]
select = 0
for i in range(1, len(x)+1):
    select = select + sum([1 for j in itertools.combinations(x,i) if mean(j)==a])

print(select)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N, A = map(int,input().split())
data = list(map(int,input().split()))

ans = 0

for i in range(1, N + 1):
    ret = list(combinations(data, i))

    for j in range(len(ret)):
        tmp_sum = 0
        for k in range(len(ret[j])):
            tmp_sum += ret[j][k]

        if tmp_sum / len(ret[j]) == A:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,A=map(int,input().split())
X=list(map(int,input().split()))
kouho = []
count = 0
for i in range(1,N+1):
    for v in itertools.combinations(X,i):
        kouho.append(v)
ans=[]
for j in range(len(kouho)):
    ans.append([len(kouho[j]),sum(kouho[j])])
for k in range(len(ans)):
    if ans[k][1]/ans[k][0]==A:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

ans = 0
for bit in range(1 << n):

    s = 0
    count = 0
    for i in range(n):
        if bit & (1 << i):
            s += x[i]
            count += 1

    if count and s / count == a:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

n,a=LI()
l=LI()

def dfs(i,sm,nm):
  if i==n:
    return 1 if nm!=0 and sm==a*nm else 0

  ans=0
  ans+=dfs(i+1,sm+l[i],nm+1)
  ans+=dfs(i+1,sm,nm)

  return ans

def main():
  return dfs(0,0,0)

# main()
print(main())

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

n,a=LI()
l=LI()

def dfs(i,sm,cnt):
  if i==n:
    return 1 if sm==cnt*a and cnt!=0 else 0

  ans=0
  ans+=dfs(i+1,sm+l[i],cnt+1)
  ans+=dfs(i+1,sm,cnt)

  return ans

def main():
  return dfs(0,0,0)

# main()
print(main())

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

n,a=LI()
l=LI()

def dfs(i,sm,cnt):
  if i==n:
    return sm==cnt*a

  ans=0
  ans+=dfs(i+1,sm+l[i],cnt+1)
  ans+=dfs(i+1,sm,cnt)

  return ans

def main():
  return dfs(0,0,0)-1

# main()
print(main())

Submission status: Time Limit Exceeded

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

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()
# 総和0を平均とするためKを引く
A = [a-K for a in LIST()]

# 半分全列挙
A1 = A[:N//2]
A2 = A[N//2:]

# それぞれの全組み合わせ
P1 = [0]
for S in range(1, 1<<len(A1)):
    p = 0
    for i in range(len(A1)):
        if S & 1<<i:
            p += A1[i]
    P1.append(p)
P2 = [0]
for S in range(1, 1<<len(A2)):
    p = 0
    for i in range(len(A2)):
        if S & 1<<i:
            p += A2[i]
    P2.append(p)

# 総和0になるペアの数を求める
C2 = Counter(P2)
ans = 0
for p in P1:
    ans += C2[-p]
# どちらも1つも選ばない分の1を引く
print(ans - 1)

Submission status: Time Limit Exceeded

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

# editorial 参照 -> 3 dimentional DP
# 制約1: x1-xjのカード, 制約2: k枚選択, 制約3: 点数合計A*k
sum_X = sum(X)
DP = [[[0 for _ in range(sum_X+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(sum_X+1):
            if (j==0) and (k==0) and (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:
                DP[j][k][s] = 0

ans  = 0
for k in range(1, n+1):
    if a*k > sum_X:
        pass
    else:
        ans += DP[n][k][a*k]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,A=map(int,input().split())
X=[int(x) for x in input().split()]
ans=0
for x in itertools.product([0,1],repeat=N):
  p=0
  q=0
  for i in range(N):
    if x[i]==1:
      p +=X[i]
      q +=1
  if not q==0 and p/q==A:
    ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
import numpy as np
import itertools


def main(argv=sys.argv):

    _, target_mean = map(int, input().split(' '))
    cards = list(map(int, input().split(' ')))

    case_count = 0
    for card_count in range(1, len(cards) + 1):
        combination = list(itertools.combinations(cards, card_count))
        card_mean = np.array(list(map(np.mean, combination)))
        case_count += np.count_nonzero((card_mean == target_mean))

    print(case_count)

    return 0


if __name__ == '__main__':
    sys.exit(main())

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, A = map(int, input().split())
X = list(map(int, input().split()))
sum_X = sum(X)
dp = np.zeros((N+1, N+1, sum_X+1), np.int64)
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
      # not used
      dp[i+1][j][k] += dp[i][j][k]
      # used
      dp[i+1][j+1][k+X[i]] += dp[i][j][k]
ans = 0
for k in range(1, N+1):
  if k*A <= sum_X:
    ans += dp[N][k][k*A]
print(ans)

Submission status: Time Limit Exceeded

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

dp = np.zeros((N+1, N+1, 2555), np.int64)
dp[0][0][0] = 1
for i in range(N):
  for j in range(N):
    for k in range(2555):
      if dp[i][j][k] == 0: continue
      # not used
      dp[i+1][j][k] += dp[i][j][k]
      # used
      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)

Submission status: Time Limit Exceeded

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

ans = -1

for i in range(2**n):
    tmp = 0
    for j in range(n):
        if (i >> j) & 1:
            tmp += x[j]
    if tmp == 0:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, a = map(int, input().split())
x = [int(b) for b in input().split()]

count = 0

for i in range(1,n+1):

    for data in itertools.combinations(x, i):
        
        if sum(data)/i == a:

            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n, a = map(int, input().split())
l = list(map(int, input().split()))
c = 0
for r in range(1, n+1):
    temp = list(combinations(l, r))
    for item in temp:
        if sum(item)/len(item) == a:
            c += 1
print(c)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n, a = map(int, input().split())
l = list(map(int, input().split()))
r = 0
a = str(a) + '.0'


def avg(l):
    return sum(l)/len(l)


for i in range(1, min(n+1, 17)):
    temp = list(combinations(l, i))
    temp = [str(avg(s)) for s in temp]
    r += temp.count(a)
print(r)

Submission status: Time Limit Exceeded

Solution code:
import itertools as it

N, A = map(int, input().split())
x = [int(i) for i in input().split()]
ans = 0
for choice in it.product(range(2), repeat=N):
    i_sum = 0
    for i in range(N):
        i_sum += choice[i] * x[i]
    if i_sum != 0 and i_sum == A * sum(choice):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations


def main():
    
    kai,av=[int(x) for x in input().rstrip().split()]
    l=[int(x) for x in input().rstrip().split()]
    ll=[i for i in range(1,kai+1)]
    result=[]
    count=0
    
    
    for i in ll:
        for j in combinations(l,r=i):
            if av==(sum(j)/i):
                count+=1
    print(count)
main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import itertools
    kai,av=[int(x) for x in input().rstrip().split()]
    l=[int(x) for x in input().rstrip().split()]
    ll=[i for i in range(1,kai+1)]
    result=[]
    count=0
    
    
    for i in ll:
        for j in itertools.combinations(l,r=i):
            if av==(sum(j)/i):
                count+=1
    print(count)
main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
kai,av=[int(x) for x in input().rstrip().split()]
l=[int(x) for x in input().rstrip().split()]
ll=[i for i in range(1,kai+1)]
result=[]
count=0
 
 
for i in ll:
    for j in itertools.combinations(l,r=i):
        if av==(sum(j)/i):
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

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

dp[0][0][0] = 1
if x[0] <= A * N:
    dp[0][1][x[0]] = 1

for j in range(N - 1):
    for k in range(N + 1):
        for s in range(A * N + 1):
            if k == 0 and s == 0:
                dp[j + 1][k][s] = 1
            elif k > j + 2:
                dp[j + 1][k][s] = 0
            elif s >= x[j + 1] and k >= 1:
                dp[j + 1][k][s] = dp[j][k][s] + dp[j][k - 1][s - x[j + 1]]
            else:
                dp[j + 1][k][s] = dp[j][k][s]

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, a = map(int, input().split())
x = list(map(int, input().split()))
x = list(map(lambda b: b - a, x))

ans = 0
for i in range(1, n + 1):
    for c in itertools.combinations(x, i):
        if sum(c) == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# N枚のカード、平均Aにしたい

N, A = map(int, input().split())
x = list(map(int, input().split()))
       
# 回答用のカウンター
cnt = 0
# bit全探索を使い、ありえる組み合わせを全部列挙する
for i in range(1 << len(x)):
    output = []
    for j in range(len(x)):
        if ((i >> j) & 1) == 1:
            output.append(x[j])
    # 結果が[]でなく、平均がAだったら、カウンターを増やす
    if output != []:
        if (sum(output) / len(output)) == A:
            cnt += 1
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,a=map(int,input().split())
x=list(map(int,input().split()))
s=max(sum(x)+1,n*a+1)
dp=[[s*[0]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(s):
      dp[i][j][k]=dp[i-1][j][k]
      if j!=0 and k>=x[i-1]:dp[i][j][k]+=dp[i-1][j-1][k-x[i-1]]
ans=0
for j in range(1,n+1):ans+=dp[-1][j][j*a]
print(ans)