Problem:
 Score : 300 points    Problem Statement We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N , and the bulbs are numbered 1 to M .  Bulb i is connected to k_i switches: Switch s_{i1} , s_{i2} , ... , and s_{ik_i} . It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2 .  How many combinations of "on" and "off" states of the switches light all the bulbs?      Constraints  1 \leq N, M \leq 10  1 \leq k_i \leq N  1 \leq s_{ij} \leq N  s_{ia} \neq s_{ib} (a \neq b)  p_i is 0 or 1 .  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  M  k_1  s_{11}  s_{12}  ...  s_{1k_1}  :  k_M  s_{M1}  s_{M2}  ...  s_{Mk_M}  p_1  p_2  ...  p_M       Output Print the number of combinations of "on" and "off" states of the switches that light all the bulbs.        Sample Input 1 2 2
2 1 2
1 2
0 1      Sample Output 1 1   Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2 .  Bulb 2 is lighted when there is an odd number of switches that are "on" among the following: Switch 2 .   There are four possible combinations of states of (Switch 1 , Switch 2 ): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 1 .       Sample Input 2 2 3
2 1 2
1 1
1 2
0 0 1      Sample Output 2 0   Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2 .  Bulb 2 is lighted when there is an even number of switches that are "on" among the following: Switch 1 .  Bulb 3 is lighted when there is an odd number of switches that are "on" among the following: Switch 2 .   Switch 1 has to be "off" to light Bulb 2 and Switch 2 has to be "on" to light Bulb 3 , but then Bulb 1 will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print 0 .       Sample Input 3 5 2
3 1 2 5
2 2 3
1 0      Sample Output 3 8

Solution (Python):
N, M = map(int,input().split())

switch = []
for _ in range(M):
    S = list(map(int,input().split()))
    switch.append(S[1:])

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

ans = 0
for bits in range(1<<N):
    flag = True

    for i in range(M):
        cnt = 0
        for s in switch[i]:
            if(bits>>(s-1) & 1):
                cnt += 1

        if cnt % 2 != P[i]:
            flag = False
    
    if flag: ans += 1

print(ans)

Solution (Python):

N, M = map(int, input().split())
K = []
X = []
for _ in range(M):
    k, *x = list(map(int, input().split()))
    K.append(k)
    X.append(x)
P = list(map(int, input().split()))

ans = 0
for bit in range(2 ** N):
    light_on = [False] * M
    for i in range(M):
        tmp = 0
        for s in X[i]:
            tmp += bit >> (s - 1) & 1
        light_on[i] = tmp % 2 == P[i]

    ans += all(light_on)

print(ans)

Solution (Python):
N, M = map(int, input().split())
ks = []
for _ in range(M):
    ks.append(list(map(int, input().split())))
p = list(map(int, input().split()))

ans = 0
for bit in range(2**N):
    on_list = []
    for i in range(N):
        if bit & (1 << i):
            on_list.append(i+1)
    flag = True
    for s, p_ in zip(ks, p):
        on_sum = len(list(set(on_list) & set(s[1:])))
        if on_sum % 2 != p_:
            flag = False
            break
    
    if flag:
        ans += 1
        
print(ans)

Solution (Python):
n, m = map(int, input().split())

s = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for i in range(1 << n):
    tmp = 0
    for j in range(m):
        on = 0
        for k in range(1, s[j][0]+1):
            if i & (1 << s[j][k]-1):
                on += 1
        if p[j] % 2 == on % 2:
            tmp += 1
    if tmp == m:
        ans += 1

print(ans)

Solution (Python):
N, M = map(int, input().split())
K = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))

ans = 0

for num in range(1 << N):
    
    
    flag = True
    for m in range(M):
        count_m = 0
        for j in K[m][1:]:
            if num & (1 << (j - 1)):
                count_m += 1
        
        if count_m % 2 != P[m]:
            flag = False
            break
    
    if flag:
        ans += 1

print(ans)

Solution (Python):
n,m = map(int,input().split())
ans = 0
Lamp_switch = []
for _ in range(m):
    S = list(map(int, input().split()))[1:]
    Lamp_switch.append(S)
Pon = list(map(int, input().split()))

for i in range(2**n):
  cnt = [0]*m
  for j in range(n):
    if (i>>j)&1:
      for k in range(m):
        if (j+1) in Lamp_switch[k]:
          cnt[k] += 1
          cnt[k] %= 2
  if cnt == Pon:
    ans += 1
    
print(ans)

Solution (Python):
N,M = map(int,input().split())

k=[]
s=[]

for i in range(M):
    switch = list(map(int,input().split()))
    k.append(switch[0])
    s.append(switch[1:])
    
p = list(map(int,input().split()))


count = 0
for i in range(2**N):
    lighton_num = 0
    for m in range(M):
        switchon_num = 0
        for j in range(k[m]):
            
            if (i>>(s[m][j]-1)) &1== 1:
                switchon_num+=1
            
        
        if switchon_num%2 == p[m]:
            lighton_num += 1
        
        
    if lighton_num == M:
        count += 1

print(count)

Solution (Python):
N, M = map(int, input().split())
List = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
num = 0
for i in range(2**N): 
  B = [0 for _ in range(M)] 
  for j in range(N):
    if ((i>>j)&1):
      for k in range(M):
        if j+1 in List[k][1:]:
          B[k] += 1
  for l in range(M):
    if B[l] % 2 != p[l]:
      break
  else:
    num += 1
print(num)

Solution (Python):
n, m = map(int, input().split())
denq = []
for _ in range(m):
    ks = tuple(map(lambda x: int(x)-1, input().split()))
    denq.append(ks[1:])
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    switch_states = [(i>>j)&1 for j in range(n)]
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += switch_states[s]
        if counts%2 != P[idq]:
            break
    else:
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
denq = []
for _ in range(m):
    ks = tuple(map(lambda x: int(x)-1, input().split()))
    denq.append(ks[1:])
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += (i>>s)&1
        if counts%2 != P[idq]:
            break
    else:
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
denq = []
for _ in range(m):
    ks = tuple(map(lambda x: int(x)-1, input().split()))
    denq.append(ks[1:])
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    kk = [0] * m
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += (i>>s)&1
        if counts%2 != P[idq]:
            break
    else:
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
denq = []
for _ in range(m):
    ks = tuple(map(lambda x: int(x)-1, input().split()))
    denq.append(ks[1:])
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    kk = [0] * m
    
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += (i>>s)&1
        if counts%2 != P[idq]:
            break
    else:
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
denq = []
for _ in range(m):
    ks = tuple(map(lambda x: int(x)-1, input().split()))
    denq.append(ks[1:])
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    kk = [0] * m
    switch_states = [(i>>j)&1 for j in range(n)]
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += switch_states[s]
        if counts%2 != P[idq]:
            break
    else:
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
denq = []
for _ in range(m):
    ks = tuple(map(lambda x: int(x)-1, input().split()))
    denq.append(set(ks[1:]))
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    kk = [0] * m
    for j in range(n):
        
        if (i>>j)&1:
            for idq, dq in enumerate(denq):
                
                
                if j in dq:
                    kk[idq] += 1

    for idq in range(m):
        if P[idq] != kk[idq]%2:
            break
    else:
        ans += 1
print(ans)

Solution (Python):
n,m=map(int,input().split())
light=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    state=[0]*n
    for j in range(n):
        if (i>>j&1):
            state[j]=1
    light_num=0
    for k in range(m):
        switch_num=0
        for l in range(1,light[k][0]+1):
            if state[light[k][l]-1]==1:
                switch_num+=1
        if switch_num%2==p[k]:
            light_num+=1
    if light_num==m:
        ans+=1
print(ans)

Solution (Python):
"""
ビット全探索
"""
n, m = map(int, input().split())
lamps = [list(map(lambda x:int(x)-1, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
ans = 0

for i in range(2**n) :
    for r in range(m) :
        on = 0
        for j in range(n) :
            
            
            if (i>>j) & 1 == 1 and j in lamps[r] :
                on += 1
        if on % 2 != p[r] :
            break
    else :
        ans += 1
print(ans)

Solution (Python):
import itertools

n, m = map(int, input().split())
switches = []
for i in range(m):
  switches.append(input())
lights = list(map(int, input().split()))

switch = [0, 1]
lists = list(itertools.product(switch, repeat=n))
count = 0
for l in lists:
  for i in range(m):
    on = 0
    switches_list = list(map(int, switches[i].split()))
    switch_num = lights[i]
    repeat_num = switches_list[0] + 1
    for j in range(1, repeat_num):
      switch_pos = switches_list[j] - 1
      on += l[switch_pos]
    if on % 2 != switch_num:
      break
    if i == m - 1:
      count += 1
print(count)

Solution (Python):










































































global FLAG_LOG
FLAG_LOG = False


def log(value):
    
    
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    
    
    N, M = list(map(int, lines[0].split()))
    
    values_p = list(map(int, lines[M+1].split()))
    
    
    
    valueses = list()
    for i in range(M):
        valueses.append(list(map(int, lines[i+1].split())))

    
    result = 0
    
    for i in range(2**N):
        
        pattern = format(int(format(i, 'b')), '0=' + str(N))
        log(f'pattern=[{pattern}]')
        on_cnt1 = 0
        
        for m in range(M):
            on_cnt2 = 0
            log(f'm=[{m}]')
            ss = valueses[m][1:]
            log(f'ss=[{ss}]')
            for s in ss:
                if pattern[s-1] == '1':
                    on_cnt2 += 1
                    log(f'on_cnt2=[{on_cnt2}]')
                else:
                    log(f'pattern[s-1]=[{pattern[s-1]}]')
            log(f'on_cnt2=[{on_cnt2}]')
            if on_cnt2 % 2 == values_p[m]:
                on_cnt1 += 1
                log(f'result++, on_cnt2=[{on_cnt2}]')
        if on_cnt1 == M:
            result += 1

    return [result]



def get_input_lines():
    line = input()
    N, M = list(map(int, line.split()))
    lines = list()
    lines.append(line)
    for _ in range(M+1):
        lines.append(input())
    return lines



def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['2 2', '2 1 2', '1 2', '0 1']
        lines_export = [1]
    if pattern == 2:
        lines_input = ['2 3', '2 1 2', '1 1', '1 2', '0 0 1']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['5 2', '3 1 2 5', '2 2 3', '1 0']
        lines_export = [8]
    return lines_input, lines_export



def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode



def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    
    
    
    
    
    
    
    
    
    
    



if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product

N,M=map(int,input().split())
S = []
for i in range(M):
  k,*s = map(int,input().split())
  S.append(s)
P=list(map(int,input().split()))

ans=0
for p in product(range(2),repeat=N):
  cnt1 = 0
  for i in range(M):
    cnt2 = 0
    for j in range(len(S[i])):
      if p[S[i][j]-1]==1:
        cnt2 += 1
    if cnt2 % 2== P[i]:
      cnt1 += 1
  if cnt1 == M:
    ans += 1

print(ans)

Solution (Python):
n,m = map(int,input().split())
light = [list(map(int,input().split()))[1:] for _ in range(m)]
check = list(map(int,input().split()))
ans = 0
for i in range(2**n):
    for j in range(m):
        cnt = 0
        ok = 1
        for k in light[j]:
            if i >> (k-1) & 1 == 1:cnt += 1
        if cnt%2 == check[j]:
            continue
        else:
            ok=0
            break
    ans += ok 
print(ans)

Solution (Python):
NN, MM = list(map(int,input().split()))
ARR = [list(map(int,input().split())) for l in range(MM)]
PMAP = list(map(int,input().split()))

switch = [[0 for j in range(NN)] for i in range(MM)]
for i in range(MM):
    for j in range(ARR[i][0]):
        switch[i][ARR[i][j+1]-1] = 1


number_of_switch_on = 0
for j in range(2**NN):

    switch_on = 1
    for l in range(MM):
        checksum = 0

        for k in range(NN):
            if (j>>k) & 1:

                checksum += switch[l][k]

        if (checksum % 2) != PMAP[l]:
            switch_on = 0
    number_of_switch_on = number_of_switch_on + switch_on


print(number_of_switch_on)

Solution (Python):
n = list(map(int, input().split()))
sw = []
for x in range(n[1]):
    sw.append(list(map(int, input().split())))
p = list(map(int, input().split()))
kumi = 0

for a in range(2 **n[0]):
    akari = 0
    kai = []
    for b in range(n[0]):
        if ((a >> b)& 1):
            kai.append(b+1)
    
    for c in range(n[1]):
        hantei = 0
        for d in range(1,sw[c][0]+1):
            if kai.count(sw[c][d]) >= 1:
                hantei +=1
        if p[c] == 0 and hantei %2 ==0:
            akari += 1
        elif p[c] == 1 and hantei %2 !=0:
            akari += 1
    if akari == n[1]:
        kumi += 1

print(kumi)

Solution (Python):
N, M = map(int, input().split())

s = []
for i in range(M):
    i = list(map(int, input().split()))
    s.append(i[1:])

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

ans = 0


for i in range(2**N):
    flag = True

    
    for j in range(len(s)):
        
        cnt = 0
        
        for k in range(N):
            
            if (k + 1) in s[j] and ((i >> k) & 1):
                cnt += 1
        
        if cnt % 2 != p[j]:
            flag = False
            break

    if flag:
        ans += 1

print(ans)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n,m = inpm()
s = [[0] * n for i in range(m)]
for i in range(m):
    tmp = inpl()
    for j in range(len(tmp) - 1):
        s[i][tmp[j+1]-1] = 1
p = inpl()

ans = 0
for i in range(2**n):
    for j in range(m):
        cnt = 0
        for k in range(n):
            if s[j][k] == 1 and (i >> k) & 1 == 1:
                cnt += 1
        if p[j] != (cnt % 2):
            break
    else:
        ans += 1
        continue
print(ans)

Solution (Python):

n, m = map(int, input().split())

l = [list(map(int, input().split())) for i in range(m)]
pl = list(map(int, input().split()))
count=0
for i in range(2**n):
    b = bin(i)
    switch = [False for i in range(n)]
    boollist=[]
    for j in range(n):
        if ((i >> j) & 1):
            switch[j] = True
    for j in range(m):
        k = l[j][0]
        sl = l[j][1:]
        total=0
        for sij in sl:
            if switch[sij-1]:
                total+=1
        if total % 2 == pl[j]:
            boollist.append(True)
        else:
            boollist.append(False)
    if all(boollist):
        count += 1
print(count)

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from itertools import product
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, M = map(int, readline().split())
    S = []
    for _ in range(M):
        k, *s = map(int, readline().split())
        S.append(s)
    P = list(map(int, readline().split()))
    ans = 0

    for switch in product((0,1),repeat=N):
        for i, s in enumerate(S):
            tmp = 0
            for k in s:
                tmp ^= switch[k-1]
            if tmp==P[i]:
                continue
            else:
                break
        else:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def resolve():
    '''
    code here
    '''
    N, M = [int(item) for item in input().split()]
    tube_to_s = [[int(item) for item in input().split()] for _ in range(M)]
    mods = [int(item) for item in input().split()]

    to_list = [[] for _ in range(M)]

    for i in range(M):
        k, *arg = tube_to_s[i]
        to_list[i] += arg
    
    res = 0
    for i in range(2**N):
        temp_s = format(i, '0{}b'.format(N))
        for j in range(M):
            temp_on_num = 0
            for item in to_list[j]:
                temp_on_num += int(temp_s[item-1])
            
            if temp_on_num % 2 == mods[j]:
                pass
            else:
                break
        else:
            res += 1

    print(res)


if __name__ == "__main__":
    resolve()

Solution (Python):
N, M = map(int, input().split())
K = []
for i in range(M):
  i = list(map(int, input().split()))
  K.append(i[1:])
p = list(map(int, input().split()))

ans = 0
for i in range(2**N):
  tmp = i
  flag = True
  cnt = 0
  for j in range(len(K)):
    for k in range(N):
      if ((i>>k) & 1):
        if k+1 in K[j]:
          cnt += 1
    if cnt % 2 != p[j]:
      flag = False
      break
    else:
      cnt = 0
      i = tmp
  if flag:
    ans += 1
print(ans)

Solution (Python):
def resolve():
    import itertools
    N, M = map(int, input().split())
    S = []
    K = []
    ans = 0
    for _ in range(M):
        s = list(map(int, input().split()))
        K.append(s[0])
        S.append(s[1:])
    P = list(map(int, input().split()))
    for i in itertools.product([0,1], repeat=N):
        count = 0
        for j in range(M):
            ichi = 0
            for q in range(K[j]):
                ichi += i[S[j][q]-1]
            if ichi%2 == P[j]:
                count += 1
        if count == M:
            ans += 1
    print(ans)
resolve()

Solution (Python):
n, m = map(int, input().split())
switches = [list(map(int, input().split())) for _ in range(m)]
correct = list(map(int, input().split()))

ans = 0
for i in range(2 ** n):
    
    flg = True
    for p in range(m):
        cnt = 0
        for j in range(n):
            
            if (i >> j) & 1:
                if (j + 1) in switches[p][1:]:
                    cnt += 1
        if cnt % 2 != correct[p]:
            flg = False
            break
    if flg:
        ans += 1

print(ans)

Solution (Python):
def main():
    import itertools
    n,m = map(int,input().split())
    lt = []
    for i in range(m):
        lt.append(list(map(int,input().split())))
    p = list(map(int,input().split()))
    stats = ((0,1) for i in range(n))
    ans = 0
    for stat in itertools.product(*stats):
        flg = 0
        for i in range(m):
            cnt = 0
            for j in range(1,lt[i][0]+1):
                if stat[lt[i][j]-1]==1:
                    cnt+=1
            if cnt%2!=p[i]:
                flg = 1
                break
        if flg==0:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
n,m = map(int,input().split())
s = [0] * m
k = [0] * m
for i in range(m):
    s[i] = list(map(int,input().split()))
    k[i] = s[0]
    s[i] = s[i][1:]
p = list(map(int,input().split()))

ans = 0
b = '0' + str(n) + 'b'
for i in range(1 << n):
    sw = format(i,b)
    if all(sum(sw[g-1] == '1' for g in s[j])%2 == p[j] for j in range(m)):
        ans += 1
print(ans)

Solution (Python):
N, M = map(int, input().split())
s = [list(map(int, input().split()))[1:] for i in range(M)]
p = list(map(int, input().split()))
cnt = 0
for a in range(2 ** N):
    flag = 1
    for i in range(M):
        if sum([(a >> (x - 1)) & 1 for x in s[i]]) % 2 != p[i]:
            flag = 0
            break
    cnt += flag
print(cnt)

Solution (Python):
N,M = map(int,input().split())
Connect = [0] * M
for i in range(M):
    k, *Connect[i] = map(int,input().split())
P = list(map(int,input().split()))
Switch = [0] * N
ans = 0
for i in range(1<<N):
    for j in range(N):
        bit = i>>j & 1
        Switch[j] = bit
    flag = True
    for l in range(M):
        count = 0
        for c in Connect[l]:
            if Switch[c-1]:
                count+=1
        if not P[l] == count % 2:
            flag = False
    if flag:
        ans += 1

print(ans)

Solution (Python):
def popcount(x):
    x = (x & 0x5555555555555555) + (x >> 1  & 0x5555555555555555)
    x = (x & 0x3333333333333333) + (x >> 2  & 0x3333333333333333)
    x = (x & 0x0f0f0f0f0f0f0f0f) + (x >> 4  & 0x0f0f0f0f0f0f0f0f)
    x = (x & 0x00ff00ff00ff00ff) + (x >> 8  & 0x00ff00ff00ff00ff)
    x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff)
    x = (x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff)
    return x

n, m = map(int, input().split())

mask = []
for i in range(m):
    vals = list(map(int, input().split()))
    bits = 0
    for s in vals[1:]:
        bits |= 1 << (s-1)
    mask.append(bits)
p = list(map(int, input().split()))

cnt = 0
for i in range(1 << n):
    if all([popcount(i & mask[j]) % 2 ^ p[j] == 0 for j in range(m)]):
        cnt += 1
print(cnt)

Solution (Python):
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N, M = rl()
K = []
for i in range(M):
	ks = rl()
	K.append(ks[1:])
P = rl()

def check(b):
	for i in range(M):
		if sum([b[k-1] for k in K[i]]) % 2 != P[i]:
			return False
	return True

cnt = 0
for b in product([0, 1], repeat=N):
	if check(b):
		cnt += 1
print(cnt)

Solution (Python):
n,m=map(int, input().split())
k=[list(map(int, input().split())) for _ in range(m)]
p=list(map(int, input().split()))

ans=0

for i in range(2**n):
    t=0
    for j in range(m):
        o=sum(1 for h in k[j][1:] if i >>(h-1)&1)
        if o%2==p[j]:
            t+=1
    if t==m:
        ans+=1
print(ans)

Solution (Python):
N,M=map(int,input().split())
k=[list(map(int,input().split())) for _ in range(M)] 
*p,=map(int,input().split())
print(sum(1for i in range(2**N) if M==sum(1for j in range(M) if sum(1for h in k[j][1:] if i>>(h-1)&1)%2==p[j])))

Solution (Python):
N,M=map(int,input().split())
k=[list(map(int,input().split())) for _ in range(M)] 
*p,=map(int,input().split())
t=0
a=0
for i in range(2 ** N):
 t=sum(1 for j in range(M) if sum(1 for h in k[j][1:] if i>>(h-1)&1)%2==p[j])
 if t==M:a+=1
print(a)

Solution (Python):
N,M=map(int,input().split())
k=[list(map(int,input().split())) for _ in range(M)] 
*p,=map(int,input().split())
t=0
a=0
for i in range(2 ** N):
 t=0
 for j in range(M):
  if sum(1 for h in k[j][1:] if i>>(h-1)&1)%2==p[j]:t+=1
 if t==M:a+=1
print(a)

Solution (Python):
N,M=map(int,input().split())
k=[list(map(int,input().split())) for _ in range(M)] 
*p,=map(int,input().split())
t=0
a=0
for i in range(2 ** N): 
    t=0
    for j in range(M): 
        
        o=sum(1 for h in k[j][1:] if i>>(h-1)&1) 
        
        if o%2==p[j]:
            t+=1
    if t==M:
        a+=1
print(a)

Solution (Python):
import itertools
n,m=map(int,input().split())
xs=[list(map(int,input().split()))[1:] for i in range(m)]
p=tuple(map(int,input().split()))
ans=0
for switch in itertools.product(range(2),repeat=n):
  judge=True
  for i in range(m):
    cnt=0
    lst=xs[i]
    for j in lst:
      cnt+=switch[j-1]
    if cnt%2!=p[i]:
      judge=False
      break
  if judge:
    ans+=1

print(ans)

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi



import string

from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    
    n, m = [int(x) for x in input().split()]
    s = []
    for _ in range(m):
        k, *r = [int(x) - 1 for x in input().split()]
        s.append(r)
    p = [int(x) for x in input().split()]
    ans = 0
    for i in range(2 ** n): 
        ok = 1
        for j in range(m): 
            pp = p[j]
            cnt = 0
            for ss in s[j]:
                if i & (1 << ss):
                    cnt += 1
            if cnt % 2 != pp:
                ok = 0
        ans += ok
    print(ans)

    


t = 1

for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""

Solution (Python):
import itertools
N, M = [int(_) for _ in input().split()]
KS = [[int(_) - 1 for _ in input().split()] for _ in range(M)]
P = [int(_) for _ in input().split()]
ans = 0
for switches in itertools.product(range(2), repeat=N):
    f = all(
        sum(switches[s] for s in ks[1:]) % 2 == P[i]
        for i, ks in enumerate(KS))
    ans += f
print(ans)

Solution (Python):

import itertools

import numpy as np



n, m = map(int, input().split())
swicthes = np.zeros((m, n), dtype=int)

for i in range(m):
    _, *s = map(lambda x: int(x) - 1, input().split())
    swicthes[i, np.array(s, dtype=int)] = 1

l = list(map(int, input().split()))
p = np.array(l, dtype=int)


count = 0
for on in itertools.product([0, 1], repeat=n):
    _on = np.array(on, dtype=int)
    status = np.sum(swicthes * _on, axis=1) % 2
    if np.sum(p == status) == m:
        
        count += 1

print(count)

Solution (Python):


n, m = map(int, input().split())

lamps = [list(map(lambda x: int(x)-1, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))

ans = 0

for i in range(1 << n):
    for r in range(m):
        on_sum=0
        for j in range(n):
            if i >> j & 1 and j in lamps[r]:
                on_sum += 1

        if on_sum % 2 != p[r]:
            break

    else:
        ans += 1

print(ans)

Solution (Python):
import math
N, M = list(map(int, input().split()))
q = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))

result_count = 0
for i in range(2**N):
    flag = True
    for idx, j in enumerate(q):  
        tmp_count = 0
        for k in j[1:]:
            if i >> (k - 1) & 1 == 1:
                tmp_count += 1
        if tmp_count % 2 != p[idx]:
            flag = False
    result_count += 1 if flag else 0

print(result_count)

Solution (Python):
n,m = map(int,input().split())
q = [list(map(int, input().split())) for i in range(m)]
p= list(map(int, input().split()))
ans = 0
 
for s in range(2**n): 
    judge = True
    for i in range(m): 
        cnt=0
        for j in range(1,len(q[i])): 
            w=q[i][j]
            if s >> (w-1) &1 ==1: 
                cnt+=1 
        if cnt % 2 != p[i]: 
            judge = False
    if judge:
        ans += 1
 
print(ans)

Solution (Python):
n,m=map(int,input().split())
light=[]
ans=0
for i in range(m):
    List=list(map(int,input().split()))
    light.append(List)
p=list(map(int,input().split()))

for i in range(2**n):
    l=[0]*n
    for j in range(n):
        if (i>>j&1):
            l[j]=1
    on=0
    for k in range(m):
        cnt=0
        for o in range(1,len(light[k])):
            if (l[light[k][o]-1]==1):
                cnt+=1
        if cnt%2==p[k]:
            on+=1
    if on==m:
        ans+=1
print(ans)

Solution (Python):
N,M=map(int,input().split())
ls3 = []
for i in range(M):
    ls1=list(map(int,input().split()))
    ls1.pop(0)
    ls3.append(ls1)
ls2 = list(map(int,input().split()))

kk = 0
for i in range(2**N):
    ls4 = [0]*M
    for j in range(N):
        if (i>>j&1):
            for k in range(M):
                if j+1 in ls3[k]:
                    ls4[k] += 1
    ii = 0
    for l in range(M):
        if ls4[l] % 2==ls2[l]:
            ii += 1

    if ii == M:
        kk += 1
print(kk)

Solution (Python):
from itertools import product
N, M = map(int, input().split())
S = []
for m in range(M):
    s = list(map(int, input().split()))
    S.append(s[1:])
    
p = list(map(int, input().split()))

ans = 0
for c in product([0, 1], repeat = N):
    ok = True
    for m in range(M):
        sm = 0
        for k in S[m]:
            sm += c[k - 1]
        if sm % 2 != p[m]:
            ok = False
            break
    if ok:
        ans += 1
print(ans)

Solution (Python):
def main():
    N,M = map(int,input().split())
    switches = []
    for i in range(M):
        switches.append(list(map(int,input().split()))[1:])
    P = list(map(int,input().split()))
    ans = 0
    for i in range(2**N):
        on = [False]*N
        for j in range(N):
            if (2**j) & i :
                on[j] = True

        for j in range(M):
            count = 0
            for s in switches[j]:
                if on[s-1]:
                    count += 1
            if count % 2 != P[j]:
                break
            else:
                continue
            break
        else:
            ans += 1
    print(ans)










main()

Solution (Python):
import itertools

n,m = map(int,input().split())
ks = [list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))


switch = [i for i in range(1,n+1)]
comb = []
for i in range(n+1):
    for v in itertools.combinations(switch,i):
        comb.append(v)

ans = 0
for i in comb:
    for j in range(m):
        tmp = 0
        for l in range(1,ks[j][0]+1):
            if ks[j][l] in i:
                tmp += 1
        if tmp%2 != p[j]:
            break
    else:
        ans += 1

print(ans)