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:
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,a = i_map()
    x = i_list()
    x.insert(0,0)

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

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

  

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,a=LI()
  l=LI()

  dp=[[[0]*51 for _ in range(2501)] for __ in range(n+1)]
  dp[0][0][0]=1
  for i in range(n):
    nd=l[i]
    for j in range(2500):
      for k in range(50):
        ni=i+1
        nj=j
        nk=k

        dp[ni][nj][nk]+=dp[i][j][k]

        nj+=nd
        nk+=1

        if nj>2500:
          continue

        dp[ni][nj][nk]+=dp[i][j][k]

  # print(dp[2][9][1])
  # print(dp[3][9][1])
  # print(dp[4][9][1])

  ans=0
  for j in range(2500):
    for k in range(1,50):
      if j%k!=0:
        continue
      if j//k==a and dp[n][j][k]>0:
        ans+=dp[n][j][k]

  return ans

# main()
print(main())

Submission status: Wrong Answer

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

ans = 0

dp = [[[0 for _ in range(N*A + 1)] for _ in range(N+1)] for _ in range(N+1)] # dp[i][num][j] : iこ目までみてnum個選んでjをつくる方法
dp[0][0][0] = 1
for i in range(1, N+1):
    for num in range(i+1):
        for j in range(num * A+1):
            dp[i][num][j] += dp[i-1][num][j]
            if j >= x[i]:
                dp[i][num][j] += dp[i-1][num-1][j-x[i]]

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

print(ans)

Submission status: Wrong Answer

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

ans = 0
for num in range(1, N+1): #num枚選んで平均をAにする
    goal = num * A
    dp = [[0 for _ in range(goal + 1)] for _ in range(N+1)] # iこ目までみてjをつくる方法
    dp[0][0] = 1
    for i in range(1, N+1):
        for j in range(goal+1):
            dp[i][j] += dp[i-1][j]
            if j >= x[i]:
                dp[i][j] += dp[i-1][j-x[i]]
    
    ans += dp[N][goal]

print(ans)

Submission status: Wrong Answer

Solution code:
N, A = map(int, input().split())
X = list(map(lambda x: int(x)-A, input().split()))
X_MAX = max(max(X), -min(X))
NX = N * X_MAX
dp = [[0] * (X_MAX * (N+1) * 2 + 1)  for i in range(N+1)]
dp [0][0] = 1
for i in range(1, N+1):
    for j in range(NX*2+1):
        dp[i][j] += dp[i-1][j]
        dp[i][j] += dp[i-1][j-X[i-1]]

print(dp[N][NX]-1)

Submission status: Wrong Answer

Solution code:
N, A = map(int, input().split())
X = list(map(int, input().split()))
dp = [[0]*(A*N+2) for _ in range(N+2)]
dp[0][0] = 1
for i, x in enumerate(X,start=1):
    for n in reversed(range(i)):
        for k in range(A*i+1):
            if dp[n][k] == 0: continue
            dp[n+1][min(k+x,A*N+1)] += dp[n][k]
print(sum(dp[n][A*n] for n in range(1,N+1)))

Submission status: Wrong Answer

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

dp = [0] * 5010
dp[2500] = 1

for y in Y:
    for i in range(5009, -1, -1):
        if i - y < 0 or i - y >= 5010:
            dp[i] = 0
        else:
            dp[i] += dp[i - y]
print(dp[2500] - 1)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,a = readInts()
x = list(map(lambda x:int(x)-a, input().split()))
#print(x)
dic = Counter(x)
#print(dic)
ans = 0
for k,v in dic.copy().items():
    if k == 0:
        ans += 2**v - 1
    else:
        if dic[k] != -1:
            ans += dic[k]*dic[-k]
            ans += dic[k]*dic[-k] * dic[0]
            dic[k] = -1
            dic[-k] = -1
print(ans)

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
x=list(map(int,input().split()))
dic={}
dic2=dic.copy()
for i in range(n):
  for j in dic:
    if j+x[i]-a in dic2:
      dic2[j+x[i]-a]+=dic[j]
    else:
      dic2[j+x[i]-a]=dic[j]
  if x[i]-a in dic:
    dic2[x[i]-a]+=1
  else:
    dic2[x[i]-a]=1
  dic=dic2.copy()
if 0 in dic:
  print(dic[0])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

n, a = map(int, input().split())
x = list(map(int, input().split()))
y = [xi - a for xi in x]

# 解説AC
dp = [defaultdict(int) for i in range(n + 1)]
dp[0][0] = 1

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

Submission status: Wrong Answer

Solution code:
N,A = map(int,input().split())
X = list(map(int,input().split()))
Y = [x-A for x in X]
t = abs(sum(Y))
dp = [[0]*(t*2+1) for _ in range(N+1)]
#dp[i][j] -> i枚目まで見る。合計をj-tにするパターン数
#i枚目を使う場合 -> dp[i][j] += dp[i-1][j-Yi]
#i枚目を使わない場合 -> dp[i][j] += dp[i-1][j]
dp[0][t] = 1

for i in range(1,N+1):
    y = Y[i-1]
    for j in range(t*2+1):
        if 0 <= j-y <= t*2:
            dp[i][j] += dp[i-1][j-y]
        dp[i][j] += dp[i-1][j]

print(dp[-1][t]-1)

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
dp=[0]*(5300)
l=list(map(int,input().split()))
dp[l[0]-a]=1

for x in l[1:]:
    b=x-a
    for i in range(2550,-2550,-1):
            dp[i]+=dp[i-b]
    dp[b]+=1

print(dp[0])

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
X=[int(x)-a for x in input().split()]
d={0:1}
for x in X:
  for k in list(d.keys()):
    d[k+x]=d.get(k+x,0)+d[k]
print(d[0]-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, A = map(int, input().split())
intA = lambda x: int(x) - A
X = tuple(map(intA, input().split()))

dp = np.zeros(5001, dtype=np.int64)
for x in X:
    if x > 0:
        dp[x:] += dp[:-x]
    elif x < 0:
        dp[:x] += dp[-x:]
    else:
        dp *= 2
    dp[x + 2500] += 1
print(dp[2500])

Submission status: Wrong Answer

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

j = n
k = n
t = n * a



dp = [[[0 for t in range(t + 1)] for k in range(k + 1)] for j in range(j + 1)]

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

# for d in dp:
#     print(d)
# print(dp[1][1][15])

for ji in range(1, j + 1):
    for ki in range(0, ji + 1):
        for ti in range(0, ki*a + 1):
            # print('now', ji, ki, ti)
            if ji == 0 and ki == 0 and ti == 0:
                # print('branch 1')
                dp[ji][ki][ti] = 1
            elif ji >= 1 and ti < xlist[ji - 1]:
                dp[ji][ki][ti] = dp[ji - 1][ki][ti]
                # print('branch 2')
            elif ji >= 1 and ki >= 1 and ti >= xlist[ji - 1]:
                # print('branch 3', ji - 1)
                dp[ji][ki][ti] = dp[ji - 1][ki][ti] + dp[ji - 1][ki - 1][ti - xlist[ji - 1]]
            # print(dp[ji][ki][ti])

count = 0
for i in range(1, k + 1):
    count += dp[j][i][i*a]

print(count)

Submission status: Wrong Answer

Solution code:
w=list(input())
n=len(w)
t=-1
def Z(s):
    m=len(s);z=[0]*m;c=0;f=[1]*m;
    for i in range(1,m):
        if i+z[i-c]<c+z[c]:z[i]=z[i-c]
        else:
            j=max(0,c+z[c]-i)
            while i+j<n and s[j]==s[i+j]:j=j+1
            z[i]=j;c=i
    for p in range(1,m):
        for k in range(2,z[p]//p+2):f[k*p-1]=0
    return f
for j in range(1,n//2+1):
    if n%j==0 and w[:n-j]==w[j:]:t=j;break;
if t==-1:print ('1\n1')
elif t==1:print (n);print (1)
else:
    zl=Z(w)
    w.reverse()
    zr=Z(w)
    cnt=0
    for i in range(0,n-1):
        if zl[i] and zr[n-2-i]:cnt=cnt+1
    print(2);print(cnt);

Submission status: Wrong Answer

Solution code:
n,a = map(int,input().split())
L = list(map(int,input().split()))
ans = 0
for i in range(1,2**n):
    p = (format(i,"b")).zfill(n)
    #print(p)
    sum1 = 0
    for j in range(n):
        if p[j] == "1":
            sum1 += L[int(j)]
            #print(L[int(j)],sum1)
    if sum1%a == 0:
        ans +=1
    #print(sum1,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
minans = inf ;ans = 0 ;count = 0 ;pro = 1

n,K=map(int,input().split())
X=list(map(int,input().split()))
A=[0]*2600
B=[0]*2600
for xi in X:
    xi-=K
    if xi>0:
        for i in range(2599-xi,-1,-1):
            A[i+xi]+=A[i]
        A[xi]+=1
    elif xi==0:count+=1
    else:
        xi=-xi
        for i in range(2599-xi,-1,-1):
            B[i+xi]+=B[i]
        B[xi]+=1
for i in range(2600):
    ans+=A[i]*B[i]*(count+1)
ans+=2**count-1
print(ans)

# print(A[:20],B[:20],count,sep="\n")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
minans = inf ;ans = 0 ;count = 0 ;pro = 1

n,K=map(int,input().split())
X=list(map(int,input().split()))
A=[0]*300
B=[0]*300
for xi in X:
    xi-=K
    if xi>0:
        for i in range(299-xi,-1,-1):
            A[i+xi]+=A[i]
        A[xi]+=1
    elif xi==0:count+=1
    else:
        xi=-xi
        for i in range(299-xi,-1,-1):
            B[i+xi]+=B[i]
        B[xi]+=1
for i in range(300):
    ans+=A[i]*B[i]*(count+1)
ans+=2**count-1
print(ans)

# print(A[:20],B[:20],count,sep="\n")

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
l=list(map(int,input().split()))
for i in range(n):
    l[i]-=a
u=[0]*(3001)
d=[0]*(3001)
ul=[]
dl=[]
z=0
for i in l:
    if i==0:
        z+=1
    elif i<0:
        dl.append(-i)
    else:
        ul.append(i)
        
for i in ul:
    for j in range(3000,-1,-1):
        if u[j]>0 or j==0:
            u[j+i]+=max(1,u[j])
for i in dl:
    for j in range(3000,-1,-1):
        if d[j]>0 or j==0:
            d[j+i]+=max(1,u[j])
ans=0
for i in range(3001):
    ans+=u[i]*d[i]
if ans==0 and z==0:
    print(0)
elif z==0:
    print(ans)
elif ans==0:
    print(2**z-1)
else:
    print((1+ans)*(2**z)-1)

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
l=list(map(int,input().split()))
for i in range(n):
    l[i]-=a
u=[0]*(3001)
d=[0]*(3001)
ul=[]
dl=[]
z=0
for i in l:
    if i==0:
        z+=1
    elif i<0:
        dl.append(-i)
    else:
        ul.append(i)
for i in ul:
    for j in range(3000,-1,-1):
        if u[j]>0 or j==0:
            u[j+i]+=1
for i in dl:
    for j in range(3000,-1,-1):
        if d[j]>0 or j==0:
            d[j+i]+=1
ans=0
for i in range(3001):
    ans+=u[i]*d[i]
if ans==0 and z==0:
    print(0)
elif z==0:
    print(ans)
elif ans==0:
    print(2**z-1)
else:
    print((ans+1)*(2**z)-1)

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
l=list(map(int,input().split()))
for i in range(n):
    l[i]-=a
u=[0]*(3001)
d=[0]*(3001)
ul=[]
dl=[]
z=0
for i in l:
    if i==0:
        z+=1
    elif i<0:
        dl.append(-i)
    else:
        ul.append(i)
for i in ul:
    for j in range(3000,-1,-1):
        if u[j]>0 or j==0:
            u[j+i]+=1
for i in dl:
    for j in range(3000,-1,-1):
        if d[j]>0 or j==0:
            d[j+i]+=1
ans=0
for i in range(3001):
    ans+=u[i]*d[i]
if ans==0 and z==0:
    print(0)
elif z==0:
    print(ans)
elif ans==0:
    print(2**z-1)
else:
    print(ans*(2**z)+1)

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
l=list(map(int,input().split()))
for i in range(n):
    l[i]-=a
u=[0]*(3001)
d=[0]*(3001)
ul=[]
dl=[]
z=0
for i in l:
    if i==0:
        z+=1
    elif i<0:
        dl.append(-i)
    else:
        ul.append(i)
for i in ul:
    for j in range(3000,-1,-1):
        if u[j]>0 or j==0:
            u[j+i]+=1
for i in dl:
    for j in range(3000,-1,-1):
        if d[j]>0 or j==0:
            d[j+i]+=1
ans=0
for i in range(3001):
    ans+=u[i]*d[i]
if ans==0 and z==0:
    print(0)
elif z==0:
    print(ans)
elif ans==0:
    print(2**z-1)
else:
    print(ans*(2**z)+z)

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
l=list(map(int,input().split()))
for i in range(n):
    l[i]-=a
u=[0]*(3001)
d=[0]*(3001)
ul=[]
dl=[]
z=0
for i in l:
    if i==0:
        z+=1
    elif i<0:
        dl.append(-i)
    else:
        ul.append(i)
for i in ul:
    for j in range(3000,-1,-1):
        if u[j]>0 or j==0:
            u[j+i]+=1
for i in dl:
    for j in range(3000,-1,-1):
        if d[j]>0 or j==0:
            d[j+i]+=1
ans=0
for i in range(3001):
    ans+=u[i]*d[i]
if ans==0 and z==0:
    print(0)
elif z==0:
    print(ans)
elif ans==0:
    print(2**z-1)
else:
    print(ans*(2**z))

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
#i番目までのカードのうちj枚を足して数ｓのものを作る方法をリストにメモ計画法で治める
lists=list(map(int,input().split()))
print(lists)
x=max(lists)
x=max(x,a)

anslist=[[[ "w" for _ in range(n*x+1)] for _ in range(n+1)]for _ in range(n+1)]



#0<=i<=n , 0<=j<=n, j<=i, 0<=s<=n*x
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:
                anslist[0][0][0]=1
            elif j>=1 and s<lists[j-1]:
                anslist[j][k][s]=anslist[j-1][k][s]
            elif j>=1 and k>=1 and s>=lists[j-1] :
                anslist[j][k][s]=anslist[j-1][k][s]+anslist[j-1][k-1][s-lists[j-1]]
            else:
                anslist[j][k][s]=0
ans=0
for i in range(1,n+1):
    ans+=anslist[n][i][i*a]

print(ans)

Submission status: Wrong Answer

Solution code:
N, A = map(int, input().split())  # N枚数のカード, 平均をAにしたい
X = tuple(map(int, input().split()))  # N枚のカードの中身

dp = [[[0]*(50*N+2) for _ in range(N+2)] for _ in range(N+2)]

dp[0][0][0] = 1  # 0枚の中から0枚選んで合計が0になる選び方が1通りある

for i in range(N):
    now_card = X[i]
    for j in range(N+1):
        for s in range(50*N):
            if s >= now_card:  # 今見ているのはX[i], これをどうするかで遷移先を変更する
                dp[i+1][j+1][s] += dp[i][j][s-now_card]  # 追加する余裕がある場合は追加する
            dp[i+1][j][s] += dp[i][j][s]  # 何も追加しない
ans = 0
for i in range(1, N+1):
    ans += dp[N][i][i*A]
print(ans)

Submission status: Wrong Answer

Solution code:
N, A = map(int, input().split())  # N枚数のカード, 平均をAにしたい
X = tuple(map(int, input().split()))  # N枚のカードの中身

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

dp[0][0][0] = 1  # 0枚の中から0枚選んで合計が0になる選び方が1通りある

for i in range(N):
    now_card = X[i]
    for j in range(N):
        for s in range(50*N):
            if s >= now_card:  # 今見ているのはX[i], これをどうするかで遷移先を変更する
                dp[i+1][j+1][s] += dp[i][j][s-now_card]  # 追加する余裕がある場合は追加する
            dp[i+1][j][s] += dp[i][j][s]  # 何も追加しない
ans = 0
for i in range(1, N+1):
    ans += dp[N][i][i*A]
print(ans)

Submission status: Wrong Answer

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

dp = [[0 for _ in range(A)] for _ in range(N + 1)]  # dp[num][mod] = count
dp[0][0] = 1

for i in range(N):
    for mod in range(A):
        dp[i + 1][mod] += dp[i][mod]
        dp[i + 1][(mod + X[i]) % A] += dp[i][mod]

print(dp[N][0] - 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, a = map(int, input().split())
x = [int(i) for i in input().split()]
dp = []
k = []
for _ in range(n + 1):
    k.append([0] * ((n * a) + 1))
for _ in range(n + 1):
    dp.append(k)
dp[0][0][0] = 1
for j in range(1, n + 1):
    for k in range(n + 1):
        for s in range((n * a) + 1):
            if (s < x[j - 1]):
                dp[j][k][s] = dp[j - 1][k][s]
            elif (k >= 1) & (s >= x[j - 1]):
                dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]]
ans = sum([dp[n][i+1][(i+1)*a] for i in range(n)])
print(ans)

Submission status: Wrong Answer

Solution code:
n, a = map(int, input().split())
x = [int(i) for i in input().split()]
dp = []
k = []
for _ in range(n + 1):
    k.append([0] * ((n * a) + 1))
for _ in range(n + 1):
    dp.append(k)
dp[0][0][0] = 1
for j in range(1, n + 1):
    for k in range(n + 1):
        for s in range((n * a) + 1):
            if (s < x[j - 1]):
                dp[j][k][s] = dp[j - 1][k][s]
            elif (k >= 1) & (s >= x[j - 1]):
                dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]]
ans = sum([dp[n][i+1][(i+1)*a] for i in range(n)])
print(ans)

Submission status: Wrong Answer

Solution code:
n, a = map(int, input().split())
x = [int(i) for i in input().split()]
x_dict = {i:xx for i, xx in enumerate(x)}
count = 0
for i in range(1, 2 ** n):
    temp = bin(i)[2:]
    temp = ("0" * (n - len(temp))) + temp
    mean_x = 0
    temp_list = [j for j, t in enumerate(temp) if t == "1"]
    for j in temp_list:
        mean_x = x_dict[j]
    if mean_x == a * (temp.count("1")):
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
w=str(input())
w2=set(w)
flag=0
for i in w2:
    cnt=0
    cnt=w.count(i)
    if cnt%2==1:
        print("No")
        flag=1
        break
if flag==0:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n,a=[int(_) for _ in input().split()]
y=[int(_)-a for _ in input().split()]
dp=[[0 for sum in range(2*n*a+51)] for right in range(n)]
dp[0][0+n*a]=1;dp[0][y[0]+n*a]=1
for right in range(n-1):
    for sum in range(-n*a, n*a+1):
        dp[right+1][sum+n*a]+=dp[right][sum+n*a]
        dp[right+1][sum+y[right+1]+n*a]+=dp[right][sum+n*a]
print(dp[-1][n*a]-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, A = map(int, input().split())
X = [0] + list(map(int, input().split()))
NX = N * max(X + [A])

dp = np.zeros((N + 1, N + 1, NX + 1))

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

for j in range(N + 1):
    for k in range(N + 1):
        for s in range(NX + 1):
            if 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]]

ret = 0

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

print(ret)

Submission status: Wrong Answer

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

# dp[i][k][j]
# i枚の中から、k枚選んで、和がj
dp = [[[0 for j in range(2501)]for k in range(n+1)] for i in range(n+1)]

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

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

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


print(ans)

Submission status: Wrong Answer

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

ans = 0
if N == 1:
    if N == A:
        print(1)
        quit()
    else:
        print(0)
        quit()
for i in range(1, 2**N+1):
    b = bin(i)[2:]
    b = '0' * (N-len(b)) + b
    curSum = 0
    curAdd = 0
    for j in range(N):
        curSum += int(b[j]) * X[j]
        if b[j] == '1':
            curAdd += 1
    if curSum == A * curAdd:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(1, 2**N+1):
    b = bin(i)[2:]
    b = '0' * (N-len(b)) + b
    curSum = 0
    curAdd = 0
    for j in range(N):
        curSum += int(b[j]) * X[j]
        if b[j] == '1':
            curAdd += 1
    if curSum == A * curAdd:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

M = 50

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

for i, a in enumerate(X):
    for n in range(M * M):
        dp[i + 1][n] = dp[i][n]
        if 0 <= n - a and n - a <= M * M - 1:
            dp[i + 1][n] += dp[i][n - a]

# print(dp[N][N * A])

ans = 0
for a in range(A,A*N+1,A):
    ans += dp[N][a]
    # print("{}   {},{}".format(dp[N][a], N,a))

# for d in dp:
#     print(sum(d))

# print(dp[N])

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
hi = np.zeros((5000,60),np.int64)
hi[0,0]=1
n,a = [int(it) for it in input().split()]
li = [int(it) for it in input().split()]
for i in li:
    hi[i:-1000,1:]+=hi[:-1000-i,:-1]
s = 0
for i in range(n):
  s+=hi[(i+1)*a,i+1]
print (s)

Submission status: Wrong Answer

Solution code:
n, a = map(int, input().split())
x = [int(i) for i in input().split()]
ans = 0
aaa = []
for i in range(1, (2**n)+1):
    bin_i = list(bin(i)[2:])
    if len(bin_i) < n:
        bin_i = ["0"] * (n - len(bin_i)) + bin_i
    t = []
    for j, bbb in enumerate(bin_i):
        if bbb == "1":
            t.append(x[j])
    if (sum(t) % len(t) == 0) & (sum(t) // len(t) == a):
        ans += 1
        aaa.append(i)
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(1 << min(N, 16)):
    total = 0
    cnt = 0
    for j in range(min(N, 16)):
        if i & (1<<j):
            total += x[j]
            cnt += 1
    if cnt != 0 and total / cnt == A:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

import numpy as np
dp = np.full((n + 1, n + 1, n * max(x + [a]) + 1), None).tolist()

def dfs(j=n, k=n, s=n * max(x)):
    if dp[j][k][s] is not None:
        return dp[j][k][s]
    if j == k == s == 0:
        dp[0][0][0] = 1
        return 1
    result = 0
    if j >= 1:
        if x[j - 1] > s:
            result = dfs(j - 1, k, s)
        elif k >= 1:
            result = dfs(j - 1, k, s) + dfs(j - 1, k - 1, s - x[j - 1])
    dp[j][k][s] = result
    return result

print(sum(dfs(n, k, k * a) for k in range(1, n + 1)))

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
m=list(map(lambda x:int(x)-a,input().split()))
x=max(abs(max(m)),abs(min(m)))*n
dp=[[0for _ in range(2*x+1)]for i in range(n)]
dp[0][0+x]=1
dp[0][m[0]+x]=1
for i in range(1,n):
  y=m[i]
  for j in range(2*x+1):
    if 0<=j+y and j+y<2*x+1:
      dp[i][j+y]+=dp[i-1][j]
    dp[i][j]+=dp[i-1][j]
  #print(y,dp[i])
print(max(0,dp[n-1][0+x]-1))

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
m=list(map(lambda x:int(x)-a,input().split()))
x=max(abs(max(m)),abs(min(m)))*n
dp=[[0for _ in range(2*x+1)]for i in range(n)]
dp[0][0+x]=1
dp[0][m[0]+x]=1
for i in range(1,n):
  y=m[i]
  for j in range(x):
    if dp[i-1][j]==0:
      continue
    dp[i][j+y]=dp[i-1][j+y]+dp[i-1][j]
    dp[i][j]=dp[i-1][j]
print(dp[n-1][0+x]-1)

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
m=list(map(lambda x:int(x)-a,input().split()))
x=max(abs(max(m)),abs(min(m)))*n
dp=[[0for _ in range(2*x+1)]for i in range(n)]
dp[0][0+x]=1
dp[0][m[0]+x]=1
for i in range(1,n):
  y=m[i]
  for j in range(x):
    dp[i][j+y]=dp[i-1][j+y]+dp[i-1][j]
    dp[i][j]=dp[i-1][j]
print(dp[n-1][0+x]-1)

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
m=list(map(lambda x:int(x)-a,input().split()))
x=max(abs(max(m)),abs(min(m)))*n
dp=[[0for _ in range(2*x+1)]for i in range(n)]
dp[0][0+x]=1
dp[0][m[0]+x]=1
for i in range(1,n):
  y=m[i]
  for j in range(x):
    dp[i][j+y]+=dp[i-1][j]
    dp[i][j]+=dp[i-1][j]
print(dp[n-1][0+x]-1)

Submission status: Wrong Answer

Solution code:
n,a=map(int,input().split())
m=list(map(lambda x:int(x)-a,input().split()))
x=max(abs(max(m)),abs(min(m)))*n
dp=[[0for _ in range(2*x+1)]for i in range(n)]
dp[0][0+x]=1
dp[0][m[0]+x]=1
for i in range(1,n):
  y=m[i]
  for j in range(x):
    dp[i][j+y]+=dp[i-1][j]
    dp[i][j]+=dp[i-1][j]
print(dp[n-1][0]-1)

Submission status: Wrong Answer

Solution code:
n,a=map(int, input().split())
x=list(map(int, input().split()))
x=[i-a for i in x]
d={0:2}
for i in x:
    for j,k in list(d.items()):
        d[i+j]=d.get(i+j,0)+k
print(d[0]-2)
#sample code.

Submission status: Wrong Answer

Solution code:
n,a=map(int, input().split())
x=list(map(int, input().split()))
x=[i-a for i in x]
d={0:0}
for i in x:
    for j,k in list(d.items()):
        d[i+j]=d.get(i+j,0)+k
print(d[0])
#sample code.

Submission status: Wrong Answer

Solution code:
n,a=map(int, input().split())
x=list(map(int, input().split()))
x=[i-a for i in x]
d={0:0}
for i in x:
    for j,k in list(d.items()):
        d[i+j]=d.get(i+j,0)+k
print(d[0]-1)
#sample code.

Submission status: Wrong Answer

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

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

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

for i in range(1,n+1): #x_1,x_2...x_n
  for k in range(i):   #k枚数選ぶ
    for s in range(sum(X)+1): #合計
      if dp[i-1][k][s]:
        dp[i][k+1][s+X[i-1]]+=dp[i-1][k][s] #1枚選択肢が増えた時の、そのカードを加えた結果を加算
        dp[i][k][s]+=dp[i-1][k][s]
ans=0
for i in range(1,n):
  for j in range(1,sum(X)+1):
    if j == i*a: #合計が平均のi倍の時に加える
      ans+=dp[n][i][j]

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
from collections import Counter, deque
from itertools import combinations, accumulate
from math import factorial
from operator import neg
n, a = list(map(int, input().split()))
xs = list(map(lambda x: int(x) - a, input().split()))

xs.sort()
l, r = bisect.bisect_left(xs, 0), bisect.bisect_right(xs, 0)
low, n0, high = xs[:l], r - l, xs[r:]
if len(low) > len(high):
    low, high = list(map(neg, high)), list(map(neg, low))
else:
    high = high[::-1]
acc = list(accumulate(high[::-1]))[::-1]

factor = 2 ** n0
lsums = Counter([0])
for v in low:
    tmps = tuple(lsums.items())
    for u, cnt in tmps:
        lsums[u + v] += cnt
del lsums[0]
ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
from collections import Counter, deque
from itertools import combinations, accumulate
from math import factorial
from operator import neg
n, a = list(map(int, input().split()))
xs = list(map(lambda x: int(x) - a, input().split()))

xs.sort()
l, r = bisect.bisect_left(xs, 0), bisect.bisect_right(xs, 0)
low, n0, high = xs[:l], r - l, xs[r:]
if len(low) > len(high):
    low, high = list(map(neg, high)), list(map(neg, low))
else:
    high = high[::-1]
acc = list(accumulate(high[::-1]))[::-1]

factor = 2 ** n0
lsums = sum((Counter(map(sum, combinations(low, 1 + i))) for i in range(len(low))), Counter())

ans = 0
# for lsum, cnt in lsums.items():
#     tmp = 0
#     q = deque()
#     q.append((0, lsum))
#     while len(q) > 0:
#         i, v = q.popleft()
#         if i + 1 < len(high) and v + acc[i + 1] >= 0:
#             q.append((i + 1, v))
#         if i >= len(high):
#             continue
#         v += high[i]
#         if v == 0:
#             tmp += 1
#             continue
#         if v < 0:
#             q.append((i + 1, v))
#     ans += tmp * cnt

# ans *= factor
# ans += 2 ** n0 - 1

print(ans)