output_description: Print the number of ways to select cards such that the average of the written
  integers is exactly A.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      N A
      x_1 x_2 ... x_N
attempt: import sys
  
  n, a = map(int, input().split())
  x = [int(x) for x in input().split()]
  
  x_small = []
  x_big = []
  count = 0
  
  for v in x:
      if v == a:
          count += 1
      elif v > a:
          x_big.append(v - a)
      else:
          x_small.append(a - v)
  
  key = 0
  k = 1
  for v in range(count, 0, -1):
      k *= v
      k //= count - v + 1
      key += k
  
  if not x_big or not x_small:
      print(key)
      sys.exit()
  
  x_big_size = len(x_big) * (max(x) - a + 1)
  x_small_size = len(x_small) * a + 1
  x_big_sub = [0] * (x_big_size)
  x_small_sub = [0] * (x_small_size)
  
  for i in range(len(x_big)):
      for j in range(x_big_size - 1, -1, -1):
          if j == 0 or x_big_sub[j]:
              if j + x_big[i] <= x_big_size:
                  x_big_sub[j + x_big[i]] += 1
  
  for i in range(len(x_small)):
      for j in range(x_small_size - 1, -1, -1):
          if j == 0 or x_small_sub[j]:
              if j + x_small[i] <= x_small_size:
                  x_small_sub[j + x_small[i]] += 1
  
  sub = []
  for i in range(min([len(x_small_sub), len(x_big_sub)])):
      v = x_small_sub[i] * x_big_sub[i]
      if v:
          sub.append(v)
  
  for i in range(len(sub)):
      k = 1
      for j in range(i):
          k += sub[j]
      sub[i] *= k
  
  sub_sum = sum(sub)
  ans = (sub_sum + 1) * (key + 1) - 1
  print(ans)
  
problem_description: 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?
samples: [{"input": "4 8\n    7 9 8 9", "output": "5\n    \n\n  * The following are the 5 ways to select cards such that the average is 8:\n    * Select the 3-rd card.\n    * Select the 1-st and 2-nd cards.\n    * Select the 1-st and 4-th cards.\n    * Select the 1-st, 2-nd and 3-rd cards.\n    * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n    6 6 9", "output": "0\n    \n\n* * *"}, {"input": "8 5\n    3 6 2 8 7 6 5 9", "output": "19\n    \n\n* * *"}, {"input": "33 3\n    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", "output": "8589934591\n    \n\n  * The answer may not fit into a 32-bit integer."}]