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, K = list(map(int,input().split()))
a = list(map(int,input().split()))

for i in range(N):  a[i] -= K
dp = [[0 for _ in range(5020)] for _ in range(N + 5)]
dp[0][2500] = 1
for i in range(N):
    for j in range(5000):
        if j - a[i] >= 0:  dp[i + 1][j] += dp[i][j - a[i]]
        dp[i + 1][j] += dp[i][j] 
        
ans = dp[N][2500] - 1
print(ans)

Submission status: Runtime Error

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()
print(dic[0])

Submission status: Runtime Error

Solution code:
def solve():
  ans = 0
  N, A = map(int, input().split())
  X = list(map(int, input().split()))
  x = sum(X)
  dp = [[[0]*(sum(X)+50) 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(x):
        dp[i+1][j][k] += dp[i][j][k]
        dp[i+1][j+1][k+X[i]] += dp[i][j][k]
  for j in range(1,N+1):
    ans += dp[-1][j][j*A]
  return ans
print(solve())

Submission status: Runtime Error

Solution code:
N, A = map(int, input().split())
*X, = map(lambda x:int(x)-A, input().split())

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

for i in range(1,N):
    for v in range(-M, M+1):
        dp[i][v+M] += dp[i-1][v+M]
        if -M<=v-X[i]<=M:
            dp[i][v+M] += dp[i-1][v-X[i]+M]

print(dp[-1][M]-1)N, A = map(int, input().split())
*X, = map(lambda x:int(x)-A, input().split())

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

for i in range(1,N):
    for v in range(-M, M+1):
        dp[i][v+M] += dp[i-1][v+M]
        if -M<=v-X[i]<=M:
            dp[i][v+M] += dp[i-1][v-X[i]+M]

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

Submission status: Runtime Error

Solution code:
def main():
    n, a = list(map(int, input().split()))
    X = list(map(lambda x: int(x) - a, input().split()))
    m = sum([x for x in X if x < 0])
    p = sum([x for x in X if x > 0])
    if p == m == 0:
        print(pow(2, n) - 1)
        exit()
    dp = [[0] * (p - m + 1) for  _ in range(n + 1)]
    dp[0][1 - m] = 1
    for i in range(1, n + 1):
        for j in range(p - m + 1):
            if 0 <= j - X[i - 1] < p - m + 1:
                dp[i][j] = dp[i - 1][j] + dp[i - 1][j - X[i - 1]]
            else:
                dp[i][j] = dp[i - 1][j]
    print(dp[n][1 - m] - 1)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import * as fs from 'fs'

function main(input: string) {
  let lines = input.split('\n');
  let tmp = lines[0].split(' ');

  let N = Number(tmp[0]);
  let A = Number(tmp[1]);

  let x = [0];
  x = x.concat(lines[1].split(' ').map(Number));

  let dp = new Array(N + 1);
  for (let i = 0; i <= N; ++i) {
    dp[i] = new Array(N + 1);
    for (let j = 0; j <= N; ++j) {
      dp[i][j] = new Array(A * N + 1).fill(0);
    }
  }

  for (let i = 0; i < N; ++i) dp[i][0][0] = 1;

  for (let i = 1; i <= N; ++i) {
    for (let j = 1; j <= i; ++j) {
      for (let k = 1; k <= A * N; ++k) {
        if (k < x[i]) {
          dp[i][j][k] = dp[i - 1][j][k];
        } else {
          dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]];
        }
      }
    }
  }

  let ans = 0;
  for (let j = 1; j <= N; ++j) {
    ans += dp[N][j][j * A];
  }

  console.log(ans);
}

main(fs.readFileSync('/dev/stdin', 'utf8').toString());

Submission status: Runtime Error

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

    dp = [[[0 for _ in range(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, i + 1):
            for k in range(1, N * A + 1):
                if k < x[k]:
                    dp[i][j][k] = dp[i - 1][j][k]
                else:
                    dp[i][j][k] = dp[i - 1][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: Runtime Error

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

dp = [Zeros(3000,n+1) for k in range(n+1)]

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

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

Submission status: Runtime Error

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

N, A = map(int, input().split())
x = readints()

sum = 0
for i in range(N):
    sum += x[i]

dp = [[[0]*(55) for _ in range(55)] for _ in range(3000)]
dp[0][0][0] = 1
for i in range(N):
    for j in range(N+1):
        for k in range(N*A):
            dp[i+1][j][k] += dp[i][j][k]
            if k >= x[i]:
                dp[i+1][j+1][k] += dp[i][j][k-x[i]]
ans = 0
for j in range(1, N+1):
    ans += dp[N][j][j*A]
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

N, A = map(int, input().split())
x = readints()

sum = 0
for i in range(N):
    sum += x[i]

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

Submission status: Runtime Error

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

j = n
k = n
t = n * a
maxv = max(xlist)


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(0, j + 1):
    for ki in range(0, ji + 1):
        for ti in range(0, ki * maxv + 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: Runtime Error

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

j = n
k = n
t = n * a
maxv = max(xlist)


dp = [[[0 for t in range(n*maxv + 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(0, j + 1):
    for ki in range(0, ji + 1):
        for ti in range(0, ki * maxv + 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: Runtime Error

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

j = n
k = n
t = n * a
maxv = max(xlist)


dp = [[[0 for t in range(n*maxv + 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 * maxv + 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: Runtime Error

Solution code:
%time
n,a=map(int,input().split())
X=list(map(int,input().split()))
dp=[[[0]*55 for _ in range(2555)] for _ in range(55)]
ans=0
dp[0][0][0]=1
for i in range(n):
    for j in range(52+50*i):
        for k in range(n):
            ni=i+1
            nj=j+X[i]
            nk=k+1
            dp[ni][nj][nk]+=dp[i][j][k]
            dp[ni][j][k]+=dp[i][j][k]
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()))
dp=[[[0]*55 for _ in range(2505)] for _ in range(55)]
ans=0
dp[0][0][0]=1
for i in range(n):
    for j in range(52+50*i):
        for k in range(n):
            ni=i+1
            nj=j+X[i]
            nk=k+1
            dp[ni][nj][nk]+=dp[i][j][k]
            dp[ni][j][k]+=dp[i][j][k]
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()))
dp=[[[0]*55 for _ in range(2505)] for _ in range(55)]
ans=0
dp[0][0][0]=1
for i in range(n):
    for j in range(52+50*i):
        for k in range(i+1):
            ni=i+1
            nj=j+X[i]
            nk=k+1
            dp[ni][nj][nk]+=dp[i][j][k]
            dp[ni][j][k]+=dp[i][j][k]
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()))
dp=[[[0]*52 for _ in range(2505)] for _ in range(52)]
ans=0
dp[0][0][0]=1
for i in range(n):
    for j in range(52+50*i):
        for k in range(i+1):
            ni=i+1
            nj=j+X[i]
            nk=k+1
            dp[ni][nj][nk]+=dp[i][j][k]
            dp[ni][j][k]+=dp[i][j][k]
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())
xl = list(map(int,input().split()))

# i個のカードまで使って和がjの組み合わせ
dp = [[0 for i in range(50*50+1)] for j in range(51)]
dp[0][0] = 1

for i in range(n):
    for j in range(n, -1, -1):
        for k in range(50*50+1):
            if k+xl[i] < 50*50+1:
                dp[j+1][k+xl[i]] += dp[j][k]
ans = 0
for i in range(1,n+1):
    ans += dp[i][i*a]

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline


def main():
    N, A = map(int, input().split())
    X = list(map(int, input().split()))

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

dp = [[[0] * (max(x)*n+1) for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1
#print(dp)

for i in range(1, n+1):
    for j in range(0, n+1):
        for k in range(0, max(x)*n+1):
            if i == 0:
                pass
            else:
                if j == 0:
                    dp[i][j][k] = dp[i-1][j][k]
                else:
                    if k < x[i]:
                        dp[i][j][k] = dp[i-1][j][k]
                    else:
                        dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i]] 
                        #print(x[i])

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


#for i in range(n+1):
#    print(dp[i])

Submission status: Runtime Error

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

MAXSUM = sum(X)+5
dp = [[[0 for _ in range(MAXSUM)] for _ in range(N+5)] for _ in range(N+5)]
for i in range(N):
  dp[i+1][1][X[i]] += 1
  for k in range(N):
    for j in range(MAXSUM):
      dp[i+1][k][j] += dp[i][k][j]
      if X[i]+j < MAXSUM:
        dp[i+1][k+1][X[i]+j] += dp[i][k][j]
#print(dp)
ans = 0
for i in range(N):
  ans += dp[N][i+1][A*(i+1)]
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)
n, a = map(int, input().split())
x = list(map(int, input().split()))

def rec(i, j, tmp):
  if i == n:
    if tmp / j == a:
      return 1
    else:
      return 0
  return rec(i+1, j+1, tmp + x[i]) + rec(i+1, j, tmp)
  
print(rec(0, 0, 0))

Submission status: Runtime Error

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

x = list(map(int, input().split()))
#print(*x)
for i in range(n):
    x[i] -= a
#print(*x)
mx = max(x)*n
mn = min(x)*n
rng = mx + abs(mn)
#print(mx,mn,rng,x[0])
if rng ==0:###3
    rng+=1
dp = [[0 for _ in range(rng)]  for i in range(n)]

dp[0][x[0]] += 1
dp[0][0] += 1

for i in range(1,n):
    for sm in range(rng):
        #print(i,sm)
        dp[i][sm] += dp[i-1][sm] + dp[i-1][(sm-x[i]+rng)%rng]###
        
        #print(i,sm,dp[sm][i-1] ,dp[sm-x[i]][i-1])

#for i in range(n):
#    print(*dp[i])

print(dp[n-1][0]-1)#0枚がカウントされてる

Submission status: Runtime Error

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

x = list(map(int, input().split()))
#print(*x)
for i in range(n):
    x[i] -= a
#print(*x)
mx = max(x)*n
mn = min(x)*n
rng = mx + abs(mn)
#print(mx,mn,rng,x[0])
if rng ==0:###3
    rng+=1
dp = [[0 for _ in range(rng+1)]  for i in range(n)]

dp[0][x[0]] += 1
dp[0][0] += 1

for i in range(1,n):
    for sm in range(rng):
        #print(i,sm)
        dp[i][sm] += dp[i-1][sm] + dp[i-1][(sm-x[i]+rng)%rng]###
        
        #print(i,sm,dp[sm][i-1] ,dp[sm-x[i]][i-1])

#for i in range(n):
#    print(*dp[i])

print(dp[n-1][0]-1)#0枚がカウントされてる

Submission status: Runtime Error

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):
    for j in range(N+1):
        for s in range(50*N+1):
            if s >= X[i]:  # 今見ているのはX[i], これをどうするかで遷移先を変更する
                dp[i+1][j+1][s] += dp[i][j][s-X[i]]  # 追加する余裕がある場合は追加する
            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: Runtime Error

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+1):
        for s in range(50*N+1):
            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: Runtime Error

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

dp = [[[0]*(max(X)*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(max(X)*N+1):
            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: Runtime Error

Solution code:
n,a,*x=map(int,open(0).read().split());dp={0:1}
for i in x:
	for k,v in dp.items():
		dp[i+k-a]=dp.get(i+k-a,0)+v
print(dp[0]-1)

Submission status: Runtime Error

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

for j in range(1,N+1):
  for k in range(j+1):
    for s in range(X*N+1):
      dp[j][k][s] = dp[j-1][k][s]
      if s >= x[j-1]:
        dp[j][k][s] += dp[j-1][k-1][s-x[j-1]]
      
for i in range(1,N+1):
  ans += dp[-1][i][i*A]
  if (i+1)*A > X*N:
    break
print(ans)

Submission status: Runtime Error

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

for j in range(1,N+1):
  for k in range(j+1):
    for s in range(X*N+1):
      dp[j][k][s] = dp[j-1][k][s]
      if s >= x[j-1]:
        dp[j][k][s] += dp[j-1][k-1][s-x[j-1]]
      
for i in range(1,N+1):
  ans += dp[-1][i][i*A]
  if (i+1)*A >= X*N:
    break
print(ans)

Submission status: Runtime Error

Solution code:
N, A = map(int, input().split())
x = [int(i) for i in input().split()]
ans = 0
X = max(x)
dp = [[[0]*(X*N+1) for j in range(N+1)] for k 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(X*N+1):
      dp[j][k][s] = dp[j-1][k][s]
      if s>=x[j-1]:
        dp[j][k][s] += dp[j-1][k-1][s-x[j-1]]
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())  # N枚のカード, 平均をAにしたい

X = list(map(int, input().split()))  # カードリスト

# [カードの総枚数][選んだカードの枚数][今の総和]
dp = [[[0]*(max(X)*N+1) for _ in range(N+1)] for _ in range(N+1)]

# 0枚の中から0枚選んで総和が0になるパターンは1つ
dp[0][0][0] = 1

for i in range(len(X)):
    for j in range(1, N+1):
        for k in range(1, N+1):
            for s in range(1, max(X)*N+1):
                if s < X[i]:
                    dp[j][k][s] = dp[j-1][k][s]
                if s >= X[i]:
                    # すでにsになっているものと、今見ているカードを加えることでsになるもの
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-X[i]]


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

print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
s = int(input())
def solve(n, s):
    if n == s:
        return n+1
    for b in range(2, math.floor(n**0.5)+1):
        tmp = n
        res = 0
        while tmp>=b:
            res+=tmp%b
            tmp //=b
        res += tmp
        if res == s:
            return b
    for p in range(int(n**0.5), 0, -1):
        r = s-p
        if r<0:
            continue
        if (n-r)%p == 0:
            b = (n-r)//p
            if r<b and b*b>n:
                return b
    return -1
print(solve(n, s))

Submission status: Runtime Error

Solution code:
# ABC044C - 高橋君とカード / Tak and Cards (ARC060C)
from collections import defaultdict


def main():
    N, A = tuple(map(int, input().split()))
    X = tuple(map(int, input().split()))
    Y = [i - A for i in X]
    D = defaultdict(int)
    D[0] = 1
    for i in Y:
        for j, k in D.items():
            D[i + j] += k
    print(D[0] - 1)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# ABC044C - 高橋君とカード / Tak and Cards (ARC060C)
import sys
sys.setrecursionlimit(10 ** 9)


def main():
    N, A = tuple(map(int, input().rstrip().split()))
    X = tuple(map(int, input().rstrip().split()))
    x = max(X)
    # dp[i][j][k] := patterns to make k by j cards from X1, X2, ..., Xi
    dp = [[[0] * (N * x + 1) for _ in range(N + 1)] for _ in range(N + 1)]
    dp[0][0][0] = 1
    for i in range(N):
        for j in range(N):
            for k in range(N * x + 1):
                if dp[i][j][k]:
                    dp[i + 1][j][k] += dp[i][j][k]
                    dp[i + 1][j + 1][k + X[i]] += dp[i][j][k]
    ans = sum(dp[N][i][i * A] for i in range(1, N + 1))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# ABC044C - 高橋君とカード / Tak and Cards (ARC060C)
def main():
    N, A = tuple(map(int, input().rstrip().split()))
    X = tuple(map(int, input().rstrip().split()))
    x = max(X)
    # dp[i][j][k] := patterns to make k by j cards from X1, X2, ..., Xi
    dp = [[[0] * (N * x + 1) for _ in range(N + 1)] for _ in range(N + 1)]
    dp[0][0][0] = 1
    for i in range(N):
        for j in range(N):
            for k in range(N * x + 1):
                if dp[i][j][k]:
                    dp[i + 1][j][k] += dp[i][j][k]
                    dp[i + 1][j + 1][k + X[i]] += dp[i][j][k]
    ans = sum(dp[N][i][i * A] for i in range(1, N + 1))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

N, A = [int(v) for v in input().split()]
X = [0, ] + [int(v) for v in input().split()]
mx = sum(X)

dp = np.zeros((N + 1, N + 1, mx + 1))
dp[0][0][0] = 1

for j in range(1, N + 1):
    for k in range(N + 1):
        for s in range(mx + 1):
            if s - X[j] < 0:
                dp[j][k][s] += dp[j - 1][k][s]
            elif k > 0:
                dp[j][k][s] += dp[j - 1][k - 1][s - X[j]] + dp[j - 1][k][s]
                # print('err')  # for debug
            else:
                dp[j][k][s] = 0

ans = 0
# print(dp)
i = 1
while i * A <= sum(X):
    # print(i * A, dp[N, i, i * A].sum())
    ans += dp[N, i, i * A].sum()
    i += 1
print(int(ans))

Submission status: Runtime Error

Solution code:
n, a = [ int(v) for v in input().split() ]
num_list = [ int(v) for v in input().split() ]
max_num = max(num_list)
field = [ [ 0 for i in range(max_num*n+1) ] for i in range(n+1) ]
field[0][0] = 1

b = num_list[0]
for i in num_list:
    for j in range(n,0,-1):
        for k in range(max_num*n+1):
            if k >= i:
                field[j][k] += field[j-1][k-i]



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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

memo={0:1}
for x in X:
    for k,v in list(memo.items()):
        memo[x+k]=memo.get(x+k,0)+v
        print(memo)
print(memo[0]-1)

Submission status: Runtime Error

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

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

ma = max(X)

dp = [[[0 for s in range(ma*N+1)] 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(i+1) :
        for s in range(ma*N+1) :
            if (k >= 1) and (s >= X[i-1]) :
                dp[i][k][s] = dp[i-1][k][s] + dp[i-1][k-1][s-X[i-1]]
            else :
                dp[i][k][s] = dp[i-1][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 = map(int,input().split())
X = list(map(int,input().split()))

ma = max(X)

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

ma = max(X)

dp = [[[0 for s in range(N*ma+1)] for k in range(N+1)] for j 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*ma+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]]
            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:
from math import sqrt, factorial
from sys import setrecursionlimit
setrecursionlimit(10000000)

def inpl(): return list(map(int, input().split()))
N = int(input())
S = int(input())

RN = int(sqrt(N)) + 1
RN += ((RN+1)**2 == N)

def func(b, N):
    if b <= 1:
        return -1
    tmp = 0
    while N:
        N, d = divmod(N, b)
        tmp += d
    return tmp

for b in range(2, RN+1):
    tmp = func(b, N)
    if tmp == S:
        print(b)
        break
else:
    for x in range(RN, 0, -1):
        b = (N-S+x)//x
        if func(b, N) == S:
            print(b)
            break
    else:
        if func(S+1, N) == S:
            print(S+1)
        else:
            print(-1)

Submission status: Runtime Error

Solution code:
N, A = map(int, input().split())
X = [int(a) for a in input().split()]
PO = [x-A for x in X if x > A]
NE = [A-x for x in X if x < A]
ZE = N - len(PO) - len(NE)

Y = [1] + [0] * 3000
Z = [1] + [0] * 3000

for i in PO:
    for j in range(len(Y) - A)[::-1]:
        Y[i+j] += Y[j]
for i in NE:
    for j in range(len(Z) - A)[::-1]:
        Z[i+j] += Z[j]

ans = -1
for i in range(len(Y)):
    ans += Y[i] * Z[i] * (2**ZE)
print(ans)

Submission status: Runtime Error

Solution code:
N, A = map(int, input().split())
X = [int(a) for a in input().split()]
PO = [x-A for x in X if x > A]
NE = [A-x for x in X if x < A]
ZE = N - len(PO) - len(NE)

Y = [1] + [0] * (N*50)
Z = [1] + [0] * (N*50)

for i in PO:
    for j in range(len(Y) - A)[::-1]:
        Y[i+j] += Y[j]
for i in NE:
    for j in range(len(Z) - A)[::-1]:
        Z[i+j] += Z[j]

ans = -1
for i in range(len(Y)):
    ans += Y[i] * Z[i] * (2**ZE)
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import pandas as pd

N, A = map(int, input().rstrip().split())

X = list(map(int, input().rstrip().split()))

def isA_erase(X):
    """
    erase A in X and count items
    input
    X: input list
    output
    X: erased list
    count: erase item num
    """
    erase_count = 0
    while A in X:
        X.remove(A)
        erase_count += 1
    
    return X, erase_count

X, erase_count = isA_erase(X)
count = 0
# Xの中にあるAを除いて作ることのできるAの数
for i in range(1, N+1 - erase_count):
    cards_list = np.array(list(itertools.combinations(X, i)))
    cards_average = np.sum(cards_list, axis= -1) / i
    count += np.sum(cards_average == A)
count = count * (pow(2, erase_count) - 1) + count + (pow(2, erase_count) - 1)
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
n,a=map(int,input().split())
X=[int(i) for i in input().split()]
tot,m=sum(X),max(X)
DP=np.zeros((n+1,n+1,tot+1),dtype=int)
DP[0][0][0]=1
for i in range(1,n+1):
  for j in range(i+1):
    lim=min(j*m,tot)+1
    for s in range(lim):
      DP[i][j][s]=DP[i-1][j][s]+DP[i-1][j-1][s-X[i-1]]
ans=0
for j in range(1,n+1):
  ans+=DP[n][j][j*a]
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n,a=map(int,input().split())
X=[int(i) for i in input().split()]
DP=np.zeros((n+1,n+1,50*n+1),dtype=int)
DP[0][0][0]=1
for i in range(1,n+1):
  for j in range(i+1):
    for s in range(50*j+1):
      DP[i][j][s]=DP[i-1][j][s]+DP[i-1][j-1][s-X[i-1]]
ans=0
for j in range(1,n+1):
  ans+=DP[n][j][j*a]
print(ans)