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: Runtime Error

Solution code:
N,A=map(int, input().split())
x=[int(x) for x in input().split()]
sort(x)
W=sum(x)
dp=[[[0]*(W+1) for _ in range(N+1)] for _ in range(N+1)]
for j in range(N+1):
    dp[j][0][0]=1
for j in range(1,N+1):
    xj=x[j-1]
    for k in range(1, N+1):
        for s in range(1, W+1):
            if s<xj:
                dp[j][k][s]=dp[j-1][k][s]
            else:
                dp[j][k][s]=dp[j-1][k][s]+dp[j-1][k-1][s-xj]

ans=0
for k in range(1,N+1):
    if k*A<=W:
        ans+=dp[N][k][k*A]
print(ans)

Submission status: Runtime Error

Solution code:
N,A=map(int, input().split())
x=list(map(int, input().split()))
dp=[]
for _ in range(N+1):
    dp.append([[0 for _ in range(N*max(x)+1)] for _ in range(N+1)])
for j in range(0,N+1):
    for k in range(0, N+1):
        for s in range(0, N*max(x)+1):
            if 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]]
            elif j==0 and k==0 and s==0:
                dp[0][0][0]=1
            else:
                dp[j][k][s]=0
ans=0
for k in range(1,N+1):
    ans+=dp[N][k][k*A]
print(ans)

Submission status: Runtime Error

Solution code:
N,A=map(int, input().split())
x=list(map(int, input().split()))
dp=[]
for _ in range(N+1):
    dp.append([[0 for _ in range(sum(x)+1)] for _ in range(N+1)])
for j in range(0,N+1):
    for k in range(0, N+1):
        for s in range(0, sum(x)+1):
            if 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]]
            elif j==0 and k==0 and s==0:
                dp[0][0][0]=1
            else:
                dp[j][k][s]=0
ans=0
for k in range(1,N+1):
    ans+=dp[N][k][k*A]
print(ans)

Submission status: Runtime Error

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

nx = n * max(max(x), a)
dp = [[[0 for k in range(nx + 1)] for j in range(n + 1)] for i in range(n + 1)]
dp[0][0][0] = 1

for i in range(n):
    for j in range(n):
        for k in range(nx):
            if k + x[j] <= n * a:
                dp[i + 1][j + 1][k + x[i]] += dp[i][j][k]
            dp[i + 1][j][k] += dp[i][j][k]

ans = sum([dp[n][k][k * a] for k in range(1, n + 1)])
print(ans)

Submission status: Runtime Error

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

dp = [[0]*(2*n*y+1) for _ in range(n+1)]
dp[0][n*y] = 1
for k in range(n):
    for i in range(2*n*y+1):
        if i+x[k] < 0 or i+x[k] > 2*n*y:
            dp[k+1][i] = dp[k][i]
        else:
            dp[k+1][i] = dp[k][i] + dp[k][i+x[k]]
print(dp[-1][n*y]-1)

Submission status: Runtime Error

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

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

print(s)

Submission status: Runtime Error

Solution code:
def ary3(x, y, z, v): return [[[v for _  in range(z)] for _ in range(y)] for _ in range(x)]

n, a = map(int, input().split())
x = list(map(int, input().split()))
m = max(x)
dp = ary3(n + 1, n + 1, m * n + 1, 0)#(選べる枚数（範囲）0 ~ n, 選んだ枚数0 ~ n, 合計0 ~ n * max(x)) = パターン数

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

for i in range(1, n + 1):
    for j in range(1, i + 1):
        for s in range(m * n + 1):
            if s + x[i - 1] < m * n + 1:
                dp[i][j][s + x[i-1]] += dp[i - 1][j - 1][s]
            dp[i][j][s] += dp[i - 1][j][s]

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

print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product

N, A = map(int, input().split())
x = [int(x) for x in input().split()]

max_x = max(max(x), A)
dp = [[[0 for _ in range(N * max_x)] for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 1

for j, k, s in product(range(1, N + 1), range(N + 1), range(N * max_x)):
    if s < x[j - 1]:
        dp[j][k][s] = dp[j - 1][k][s]
    elif 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]]

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

Submission status: Runtime Error

Solution code:
N, A = map(int, input().split())
x = [int(x) for x in input().split()]

max_x = max(x)
dp = [[[0 for _ in range((N + 1) * max_x)] for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 1

for j in range(1, N + 1):
    for k in range(N + 1):
        for s in range((N + 1) * max_x):
            if s < x[j - 1]:
                dp[j][k][s] = dp[j - 1][k][s]
            elif 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]]

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

Submission status: Runtime Error

Solution code:
import heapq
N, A = map(int, input().split())
X = [int(x) - A for x in input().split()]
for x in X:
  if x > 0:
    Xp.append(x)
  elif x < 0:
    Xm.append(-x)
  else:
    X0.append(x)
limit = min(sum(Xp), sum(Xm))
Xp = [x for x in Xp if x <= limit]
Xm = [x for x in Xm if x <= limit]
R = [[0, 0] for x in range(limit + 1)]
def c(X, k):
  Q = []
  heapq.heappush(Q, 0)
  for x in X:
    _Q = []
    while Q:
      q = heapq.heappop(Q)
      if q > limit:
        break
      heapq.heappush(_Q, q)
      heapq.heappush(_Q, q + x)
    Q = _Q
  while Q:
    q = heapq.heappop(Q)
    if q > limit:
      break
    R[q][k] += 1
c(Xp, 0)
c(Xm, 1)
print(sum([r[0] * r[1] for r in R]) * (2 ** len(X0)) - 1)

Submission status: Runtime Error

Solution code:
import itertools↲                                 
↲                                                   
n, a = map(int, input().split())↲                   
array = [int(x) for x in input().split()]↲          
↲                                                   
array2 = []↲                                        
tmp = 0↲                                            
for i in array:↲                                    
    tmp += i↲                                       
    array2.append(tmp)↲                             
↲                                                   
ans = 0↲                                            
for pickup in range(1, n+1):↲                       
    tmp_gen = itertools.combinations(array, pickup)↲
    for i in tmp_gen:↲                              
    	if sum(i) == a*pickup:↲                     
		ans += 1↲                               
print(ans)↲

Submission status: Runtime Error

Solution code:
import itertools

def get_all_comb(ary):
    r = []
    for i in range(1, len(ary) + 1):
        r += list(itertools.combinations(ary, i))
    return r

N, A = (int(s) for s in input().split())
X = [int(s) for s in input().split()]

lowers = []
i = 0
while X[i] < A:
    lowers.append((X[i]))
    i += 1

lowers = [x for x in X if x <= A]
uppers = [x for x in X if x > A]
sames = [x for x in X if x == A]

lowers_comb = get_all_comb(lowers)
uppers_comb = get_all_comb(uppers)

cnt = 0
for l in lowers_comb:
    for u in uppers_comb:
        avg = (sum(l) + sum(u)) / (len(l) + len(u))
        if avg == A:
            cnt += 1

cnt += len(sames)
print(cnt)

Submission status: Runtime Error

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


for j in range(n):
    for k in range(n+1):
        for s in range(n*X+1):
            dp[j+1][k][s]+=dp[j][k][s]
            if x[j]+s<n*X+1:
                dp[j+1][k+1][s+x[j]]+=dp[j][k][s]
            

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

Submission status: Runtime Error

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

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

for k in range(1,n+1):
  kx=x[k-1]
  f+=kx
  for i in range(k,0,-1):
    for j in range(kx,a*n+1):
      dp[i][j] += dp[i-1][j-kx]
      if j > f:
        break
      
for i in range(1,n+1):
  ans+=dp[i][a*i]

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n, a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
sx=sum(x)
dp= np.zeros((n+1,sx+1),dtype='int32')
#dp=[[0]*(n*a+1)]*(n+1)
dp[0][0]=1
ans=0
f=0
for k in range(1,n+1):
  kx=x[k-1]
  f+=kx
  for i in range(k,0,-1):
    for j in range(kx,sx+1):
      dp[i][j] += dp[i-1][j-kx]
      if j > f:
        break
      
for i in range(1,n+1):
  if i >=sx:
    break
  ans+=dp[i][a*i]

print(ans)

Submission status: Runtime Error

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

dp= np.zeros((n+1,n*a+1),dtype=int)
dp[0][0]=1
ans=0

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

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n, a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
sx=sum(x)
dp= np.zeros((n+1,n*a+1),dtype=int)
dp[0][0]=1
ans=0

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

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n, a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
sx=sum(x)
dp= np.zeros((n+1,n*a+1),dtype=int)
dp[0][0]=1
ans=0

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

print(ans)

Submission status: Runtime Error

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

dp= np.zeros((n+1,n+1,n*a+1),dtype=int)
dp[0][0][0]=1
ans=0

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

print(ans)

Submission status: Runtime Error

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

dp= np.zeros((n+1,s*n+1),dtype=int)
dp[0][0]=1
ans=0

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

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n, a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
xs=sum(x)
dp= np.zeros((n+1,xs*n+1),dtype=int)
dp[0][0][0]=1
ans=0

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

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n, a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
xs=sum(x)
dp= np.zeros((n+1,n+1,xs*n+1),dtype=int)
dp[0][0][0]=1
ans=0

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

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n, a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
xs=sum(x)
dp= np.zeros((n+1,n+1,n*a+1),dtype=int)
dp[0][0][0]=1
ans=0

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

print(ans)

Submission status: Runtime Error

Solution code:
s = int(input())
sl = list(str(s))
sl_n = len(sl) - 1
l = ['a','b']
def a_or_b(x):
    if len(list(str(x[0]))) == sl_n:
        return x
    else:
        ll = []
        for i in range(len(x)):
            ll.append(x[i] + 'a')
        for i in range(len(x)):
            ll.append(x[i] + 'b')
        x = ll
        return a_or_b(x)
    
lll = []
ans = 0

if len(sl) == 1:
    ans = s
else:
    lll = a_or_b(l)
    kkk = []
    for i in range(len(lll)):
        p = sl
        q = list(str(lll[i]))
        st = ''
        for j in range(len(p) - 1):
            if q[j] == 'a':
                st = st + p[j] +'+'
            else:
                st = st + p[j] + ''
        st = st + sl[-1]
        res = eval(st)
        ans += res
        
print(ans)

Submission status: Runtime Error

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

xx = []
for i in range(n):
    xx.append(x-a)
X = max(xx)    
#dp
def dp(j,t,l=xx):
    if j = 0 and t = n * X:
        return 1
    elif j > 0 and t -l[j] < 0 or t- l[j] > 2* n * X:
        return dp(j-1,t,l=xx)
    elif j > 1 and 0 <= t-l[j] <= 2*n*X:
        return dp(j-1,t,l = xx) + dp(j-1,t-l[j],l = xx)
    else:
        return 0
    
print(dp(n,n*X,l=xx) - 1)

Submission status: Runtime Error

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

lis = [0] * n
j = 0
for i in range(n):
    while j < n and a[j] < b[i]:
        j += 1
    lis[i] = j

li = [0] * n
m = 0
j = 0
for i in range(n):
    while j < n and b[j] < c[i]:
        m += lis[j]
        j += 1
    li[i] = m
print(sum(li))

Submission status: Runtime Error

Solution code:
def main():
    N, A = map(int, input().split())
    X = tuple(map(int, input().split()))

    x = [i - A for i in X]
    nx = max(x) * N
    dp = [[0] * (2 * nx + 1) for _ in [0] * (N + 1)]
    for i in range(N + 1):
        for j in range(2 * nx + 1):
            if not i:
                if j == nx:
                    dp[i][j] = 1
            elif j - x[i-1] < 0 or j - x[i-1] > 2 * nx:
                dp[i][j] = dp[i-1][j]
            elif 0 <= j - x[i-1] <= 2 * nx:
                dp[i][j] = dp[i-1][j] + dp[i-1][j - x[i-1]]
    print(dp[N][nx] - 1)

main()

Submission status: Runtime Error

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

sumX = sum(X)
dp = [[[0 for _ in range(sumX+1)] 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(0,i+1):
        for k in range(sum(X)+1):
            if j==0 and k==0:
                dp[i][j][k] = 1
            elif k < X[i]:
                dp[i][j][k] = dp[i-1][j][k]
            elif j > 0 and k >= X[i]:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-X[i]]

if max(X) < A:
    print(0)
else:
    Ans = 0
    for i in range(1,N+1):
        Ans += dp[N][i][A*i]
    print(Ans)

Submission status: Runtime Error

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

maxX = max(X)
dp = [[[0 for _ in range(N*maxX+1)] 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(0,i+1):
        for k in range(N*maxX+1):
            if j==0 and k==0:
                dp[i][j][k] = 1
            elif k < X[i]:
                dp[i][j][k] = dp[i-1][j][k]
            elif j > 0 and k >= X[i]:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-X[i]]

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

print(Ans)

Submission status: Runtime Error

Solution code:
N, A = map(int, input().split())
X = list(map(int, input().split()))
x_max = max(X)
dp = [[[0]*(N*x_max+1) for i in range(N+1)] for i in range(N+1)]
dp[0][0][0] = 1

for j in range(1, N+1):
    for k in range(N+1):
        for s in range(N*x_max+1):
            if X[j-1] <= s:
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-X[j-1]]
            else:
                dp[j][k][s] = dp[j-1][k][s]

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

print(ans)

Submission status: Runtime Error

Solution code:
def c_atcodeer_and_election_report(N, R):
    from math import ceil
    t = 1  # 高橋の票数
    a = 1  # 青木の票数
    for x, y in R:
        # t<=nx ∧ a<=ny を満たす最小のnを求める
        n = max(ceil(t / x), ceil(a / y))
        t = n * x
        a = n * y
    return t + a
N = int(input())
R = [[int(i) for i in input().split()] for j in range(N)]
print(c_atcodeer_and_election_report(N, R))

Submission status: Runtime Error

Solution code:
a, b, c = input().split()
print('YES' if a[-1]==b[0] and b[-1]==c[0] else 'NO')

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc044/tasks/arc060_a

"""
import sys
from sys import stdin
from copy import copy, deepcopy
input = stdin.readline


def solve(N, A, cards):
    ans = 0
    cards.append(0)
    cards.sort()
    W = max(cards) * N

    # dp[j][k][s]: j番目までのカードをk枚使って合計をsにする組み合わせ
    dp = [[[0] * (W+1) for _ in range(N+1)] for _ in range(N+1)]
    for j in range(N+1):
        dp[j][0][0] = 1

    for j in range(1, N+1):
        card = cards[j]
        for k in range(1, N+1):
            for s in range(1, W+1):
                if s < card:
                    dp[j][k][s] = dp[j-1][k][s]
                else:
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-card]

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


def main(args):
    N, A = map(int, input().split())
    cards = [int(x) for x in input().split()]
    ans = solve(N, A, cards)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Runtime Error

Solution code:
def c_Tak_and_Cards(N, A, S):
    X = max(S)
    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: Runtime Error

Solution code:
N,A=map(int,raw_input().split())
x=[0]+map(int,raw_input().split())
#print x

max_n=max(x)

dp=[[[0]*(N*max_n+1) for k in range(N + 1)] for j in range(N+1)]
#print dp


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


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

print ans

Submission status: Runtime Error

Solution code:
import numpy as np

N, A = map(int, raw_input().split())
x = map(int, raw_input().split())
dp = np.full((N+1, A+1, (N+1)*(A+1)), -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]
print sum([dfs(N-1, T, T*A) for T in range(1, N+1)])

Submission status: Runtime Error

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

# 3d DP
max_x = max(x)

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

dp[0][0][0] = 1

for i in range(0, N):
    for k in range(0, N + 1):
        for y in range(max_x * N + 1):
            dp[i + 1][k][y] += dp[i][k][y]
            dp[i + 1][k + 1][y + x[i]] += dp[i][k][y]

cnt = 0
for k in range(1, N + 1):
    for y in range(1, max_x * N + 1):
        if y // k == A and y % k == 0:
            cnt += dp[N][k][y]

print(cnt)

Submission status: Runtime Error

Solution code:
n, a = [int(e) for e in input().split()]
lst = [int(e) for e in input().split()]


def main(n, a, lst):
    count = 0
    lst_len = len(lst) 
    for i in range(1, i + 1):
        for j, _ in enumerate(lst):
            if lst_len <= j + i:
                break
            e = lst[j:j + i]
            if e // i == a:
                count += 1
    return count 


print(main(n, a, lst))

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N, A = map(int, input().split())

    assert N <= 16

    x = [int(i) for i in input().split()]
    cnt = 0

    for i in range(1, 2**N):
        bs = bin(i)[2:].zfill(N)
        bitpop = bs.count('1')
        tmp = sum(x[i] for i, b in enumerate(bs) if b == '1')
        cnt += (tmp // bitpop == A and tmp % bitpop == 0)

    print(cnt)

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:

N, A = [int(_) for _ in input().split()]
x = sorted([int(_) for _ in input().split()])

dp = [[0] * (sum(x)+1) for j in range(N+1)]

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

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

Submission status: Runtime Error

Solution code:
n, a = map(int, raw_input().split())
X = map(int, raw_input().split())
dp = [[0]*(n*a+1) for i in xrange(n+1)]
dp[0][0] = 1
for i in xrange(n):
    for j in xrange(i, -1, -1):
        for k in xrange(n*a, X[i]+1, -1):
            dp[j+1][k] += dp[j][k-X[i]]
ans = 0
for i in xrange(1, n+1):
    ans += dp[i][i*a]
print ans

Submission status: Runtime Error

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().splist(" ")]

    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)


# def dns_child(now_mean, target_mean, card_list: list):
#     """
#     >>> dns_child(0, 8, [7,9,8,9])
#     5
#     >>> dns_child(0, 8, [6,6,9])
#     0
#     >>> dns_child(0, 5, [3,6,2,8,7,6,5,9])
#     19
#     >>> dns_child(0, 3, repeat(3,33))
#     8589934591
#     """


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

    N, A, x_list = read_input()

    naive_checker(x_list, A)

Submission status: Runtime Error

Solution code:
from array import array

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

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

def main():
    n, a = reads()
    x = reads()
    s = sum(x)
    dp = [[array('I', [0]*3500) for j in range(n+1)] for i in range(n+1)]
    dp[0][0][0] = 1
    for i in range(n):
        for j in range(n):
            for k in range(s):
                dp[i][j+1][k] += dp[i][j][k]
                dp[i+1][j+1][k+x[j]] += dp[i][j][k]
    r = 0
    for j in range(1, n+1):
        r += dp[j][n][j*a]
    print(r)

main()

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<< #x <<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

ll dp[51][51][2601];
int main(){
    int N,A,NX,x[51];
    cin >> N >> A;
    REP(i,N) cin >> x[i];
    NX = N * 50;
    dp[0][0][0] = 1;

    REP(i,N)REP(j,N)REP(k,NX){
        dp[i+1][j+1][k+x[i]] += dp[i][j][k];
        dp[i+1][j][k] += dp[i][j][k];
    }

    ll ans = 0;
    FOR(i,1,N+1) ans += dp[N][i][A*i];
    cout << ans << endl;

    return 0;
}

Submission status: Runtime Error

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 = input()
inputs = input()

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

Submission status: Runtime Error

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

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_ze\
ro)
    count += pow(2, count_zero)-1
    print count

Submission status: Runtime Error

Solution code:
n,a=map(int,raw_input().split())
x=map(int,raw_input().split())
ans=0
for i in range(1<<n):
    chk=0
    t=bin(i)[2:]
    t='0'*(n-len(t))+t
    for j,p in enumerate(t):
        if p=='1':
            chk+=x[j]
    if chk!=0 and chk==a*t.count('1'):
        ans+=1
print ans