output_description: Print the maximum number of apple pies we can make with what we have.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      A P
attempt: # N,M = 2, 2
  N, M = map(int, input().split())
  
  # kの値は特に必要ないので最初から取得しない
  # S = [[1, 2], [2]]
  # p = [0, 1]
  S = [list(map(int, input().split()))[1:] for i in range(M)]
  p = list(map(int, input().split()))
  
  ans = 0
  
  for i in range(1 << N):  # スイッチのオンオフ状態(0, 1, 2, 3)
      count_2 = -1
      bit = list(str(bin(i)))  # 0b0, 0b1, 0b10...
      fail = 0
  
      # 桁埋め処理
      ketaume = (1 << N) // 2 + 2 - len(bit)
      if ketaume > 0:
          for i in range(ketaume):
              bit.insert(2, "0")
      # print("search target={}".format(bit))
      for s in S:  # [1, 2], [2]の階層
          count_2 += 1  # 何番目のSかを数えたい
          count = 0
          for t in s:  # 1, 2の階層
              # print("bit = {}".format(bit[-t]))
              if int(bit[-t]) == 1:
                  count += 1  # ついているスイッチの数を数える
  
          # print("{}-> number of switch is {}".format(s, count))
  
          # ついているスイッチが偶数か奇数かを判定
          # print("if mod is {}, OK".format(p[count_2]))
          # print("")
          if not count % 2 == p[count_2]:
              fail = 1  # 望ましくなければ，失敗フラグを立ててブレイク
              break
      if fail == 0:
          # print("ans += 1")
          ans += 1
  
  print(ans)
  
problem_description: Statement
  
  We have A apples and P pieces of apple.
  
  We can cut an apple into three pieces of apple, and make one apple pie by
  simmering two pieces of apple in a pan.
  
  Find the maximum number of apple pies we can make with what we have now.
samples: [{"input": "1 3", "output": "3\n    \n\nWe can first make one apple pie by simmering two of the three pieces of apple.\nThen, we can make two more by simmering the remaining piece and three more\npieces obtained by cutting the whole apple.\n\n* * *"}, {"input": "0 1", "output": "0\n    \n\nWe cannot make an apple pie in this case, unfortunately.\n\n* * *"}, {"input": "32 21", "output": "58"}]