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):
import itertools as itt

def bit(n,m):
    bi = list((itt.product([i for i in range(n)],repeat = m)))
    return bi

N,M = list(map(int,input().split()))
L = [list(map(int,input().split())) for  _ in range(M)]
P = [int(s) for s in input().split()]

ans = 0
petterns = bit(2,N)
for pettern in petterns:
    count = 0
    flag = 1
    for i in range(M): 
        
        count = 0
        for j in range(L[i][0]):
            if pettern[L[i][j+1] - 1] == 1:
                count += 1
        if count % 2 != P[i]:
            count = 0
            flag = 0
    if flag == 1:
        ans += 1
print(ans)

Solution (Python):
import itertools
n,m=map(int,input().split())
K={"K"+str(i+1):list(map(int,input().split())) for i in range(m)}
P=list(map(int,input().split()))
for item in K.keys():
  K[item].pop(0)


l=list(itertools.product([0,1],repeat=n))

c=0
for item in l:
  f=0
  for i in range(m):
    l_s=[item[K["K"+str(i+1)][j]-1] for j in range(len(K["K"+str(i+1)]))]
    if sum(l_s)%2==P[i]:
      f+=1
  if f==m:
    c+=1
print(c)

Solution (Python):
N, M = map(int, input().split())
K = []
S = []
for i in range(M):
    k, *s = input().split()
    K.append(int(k))
    S.append([int(si) for si in s])
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    
    on_switch = [0] * N
    all_lights_on = True
    for j in range(N):
        
        if i & (1<<j):
            on_switch[j] = 1
    for l in range(M):
        num_on = 0
        s_connected = S[l]
        for s in s_connected:
            if on_switch[s-1]:
                num_on += 1
        if num_on % 2 != P[l]:
            all_lights_on = False
    if all_lights_on:
    	ans += 1

print(ans)

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

ans = 0

for i in range(2**n):
    light = [0] * m
    flag = True
    for j in range(m):
        for k in range(1,switch[j][0]+1):
            if (i >> (switch[j][k]-1))&1 == 1:
                light[j] += 1
        if light[j] % 2 != p[j]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
li = [input() for i in range(m)]
conds = list(map(int, input().split()))

b_li = []
for item in li:
    tmp = item.split()[1:]
    cond = 0
    for elm in list(map(int, tmp)):
        cond = cond | (2 ** (elm - 1))
    b_li.append(cond)

cnt = 0
for i in range(2**n):
    for j in range(m):
        k =bin(i & b_li[j])
        onCnt = str(k).count('1')
        if (onCnt % 2) != conds[j]:
            break
    else:
        cnt += 1

print(cnt)

Solution (Python):
from numpy import*
n,m=map(int,input().split())
s=[[int(j) for j in input().split()][1:] for i in range(m)]
p=[int(i) for i in input().split()]
a=0
for i in range(2**n):
    b=array([(i>>j)&1 for j in range(n)])
    if [sum(b[array(k)-1])%2 for k in s]==p:
      a+=1
print(a)

Solution (Python):
from itertools import product

N,M = map(int,input().split())

ks = []
for i in range(M):
    ks.append(list(map(int, input().split())))
    
p = list(map(int, input().split()))
    
ans = 0
for comp in product(range(2), repeat=N):
    onoff = [0]*M
    for li in range(M):
        s_on = 0
        for si in range(ks[li][0]):
            s_on += comp[ks[li][si+1]-1]
        
        if s_on%2 == p[li]:
            onoff[li] = 1
    if sum(onoff) == M:
        ans += 1
        
print(ans)

Solution (Python):
N, M = map(int, input().split())
int_switch_repr = 2**N
light_bulbs_switches = []
for i in range(M):
  k_s = [int(x) for x in input().split()]
  k_i = k_s[0]
  light_bulbs_switches.append(k_s[1:]) 
P = [int(x) for x in input().split()]  

ans = 0
for itg in range(int_switch_repr):
  binary_switch_repr = "{w:{fill}{width}b}".format(w=itg, fill='0', width=N)
  all_on = True
  for lbs_i, p_i in zip(light_bulbs_switches, P):
    is_light_on = sum([1 for sw in lbs_i if binary_switch_repr[int(sw)-1]=='1'])%2 == p_i
    if not is_light_on:
      all_on = False
      break
  if all_on:
    ans+=1

print(ans)

Solution (Python):
N, M = map(int, input().split())
int_switch_repr = 2**N
light_bulbs_switches = []
for i in range(M):
  k_s = [int(x) for x in input().split()]
  k_i = k_s[0]
  light_bulbs_switches.append(k_s[1:]) 
P = [int(x) for x in input().split()]  

ans = 0
for itg in range(int_switch_repr):
  binary_switch_repr = "{w:{fill}{width}b}".format(w=itg, fill='0', width=N)
  all_on = True
  for lbs_i, p_i in zip(light_bulbs_switches, P):
    is_light_on = sum([1 for sw in lbs_i if binary_switch_repr[int(sw)-1]=='1'])%2 == p_i
    if not is_light_on:
      all_on = False
  if all_on:
    ans+=1

print(ans)

Solution (Python):
n,m=map(int,input().split())
s=[]
for i in range(m):
    b = [int(i) for i in input().split()]
    s.append(b[1:])
p=[int(i) for i in input().split()]
ans=0
for i in range(2**n):
    s_ind=0
    k=bin(i)[2:]
    k=k.zfill(n)
    for j in s:
        c=0
        for M in j:
            if k[-M]=="1":c+=1
        if p[s_ind]!=c%2:break
        s_ind += 1
        if s[-1]==j:
            ans+=1
print(ans)

Solution (Python):

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


s = []
for i in ks :
        t = 0
        for j in range(len(i)) :
                t += 2**(n-i[j])
        s.append(t)


ans = 0
for i in range(2**n) :
        flag = True
        for j in range(m) :
                if bin(s[j] & i).count('1') % 2 != p[j] :
                        flag = False
                        break
        if flag :
                ans += 1
print(ans)

Solution (Python):
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
KS = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]
p = [int(x) for x in stdin.readline().rstrip().split()]

k = [KS[l][0] for l in range(M)]
s = [KS[m][1:] for m in range(M)]
cnt = 0


def to_binary(x):
    out = ''
    for l in range(N):
        if x >= 2 ** (N - l - 1):
            out += '1'
            x -= 2 ** (N - l - 1)
        else:
            out += '0'
    return out


for m in range(2 ** N):
    bin_num = to_binary(m)
    for x in range(M):
        swi = 0
        for y in range(k[x]):
            if bin_num[s[x][y] - 1] == '1':
                swi += 1
        if swi % 2 != p[x]:
            break
        if x == M - 1:
            cnt += 1

print(cnt)

Solution (Python):
n,m = map(int, input().split())
li = []
all_count = 0
for i in range(m):
  li.append(list(map(int, input().split())))
zero_one = list(map(int, input().split()))


for i in range(2**n):
  b = bin(i)[2:].rjust(n, '0')
  light = list(str(b))
  for l, j in enumerate(li):
    num_swith = j[0]
    count = 0
    for k in j[1:]:
      count += int(light[k-1])
    if count % 2 != zero_one[l]:
      break
      
    if l == m-1:
      all_count += 1
      
      
print(all_count)

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(2 ** N):
  ptn = bin(i)[2:].rjust(N, "0")  
  light = True  

  for j in range(M):
    tmp = 0  
    
    for n in range(1, s[j][0] + 1):
      if ptn[s[j][n] - 1] == "1": 
        tmp += 1
    if tmp%2 != p[j]%2:
      light = False
  if light:
    ans += 1
print(ans)

Solution (Python):
from numpy import*
n,m=map(int,input().split())
l=[]
for i in range(m):
    *a,=map(int,input().split())
    l.append(a[1:])
*p,=map(int,input().split())

ans=0
for t in range(2**n):
    tmp=array([t>>s&1 for s in range(n)])
    if p==[sum(tmp[array(i)-1])%2for i in l]:
        ans+=1
print(ans)

Solution (Python):
from sys import stdin
import itertools
N, M = [int(x) for x in stdin.readline().rstrip().split()]
K = []
S = []
for i in range(M):
    k, *s = map(int, input().split())
    K.append(k)
    S.append(s)
P = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0
for n in list(itertools.product([0,1],repeat=N)):
    flag = True
    for ind,s in enumerate(S):
        fired = 0
        for s_index in s:
            if n[s_index - 1] == 1:
                fired += 1
        if fired % 2 != P[ind]:
            flag = False
    if flag:
        ans += 1
print(ans)

Solution (Python):
N, M = map(int, input().split())
n_switch = []
switch = []
for i in range(M):
	s = list(map(int, input().split()))
	n_switch.append(s[0])
	switch.append(s[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	x = 1
	b = bin(i)[2:].rjust(N, '0')
	for j in range(M):
		n_light = 0
		for k in range(n_switch[j]):
			if b[switch[j][k] - 1] == '1':
				n_light += 1
		if n_light % 2 != p[j]:
			x *= 0
			break
	if x == 1:
		ans += 1
print(ans)

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

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


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

ans = 0






for i in range(2 ** N):
    ptn = bin(i)[2:].rjust(N, '0')

    allLight = True  

    
    for j in range(M):

        n_light = 0
        
        for k in range(n_switches[j]):
            
            if ptn[switches[j][k] - 1] == '1':
                n_light += 1

        if n_light % 2 != p[j]:
            allLight = False
            break

    if allLight:
        ans += 1

print(ans)

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

c = 0
for n in range(1 << N):
    for i, S in enumerate(A):
        
        if P[i] ^ sum(n >> s-1 & 1 for s in S) & 1:
            break
    else:
        c += 1

print(c)

Solution (Python):


N,M = map(int,input().split())
bulbs = []
for i in range(M):
    l = list(map(int,input().split()))
    bulbs.append(l)
p = list(map(int,input().split()))

ans = 0
for i in range(2 ** N):
    switches = []
    for j in range(N):
        if (i >> j) & 1:
            switches.append(1)
        else:
            switches.append(0)
    
    
    
    flag = True
    for x in range(M):
        count = 0
        k = bulbs[x][0]
        for y in range(1, k + 1):
            if switches[bulbs[x][y] - 1] == 1:
                count += 1
        if (count % 2) != p[x]:
            flag = False
            break
    
    if flag == True:
        ans += 1
        
print(ans)

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

ans = 0
for b in range(1<<N): 
  for i in range(M): 
    c = 0
    for s in src[i][1: ]: 
      if b&(1<<(s-1)): 
        c += 1 
    if c%2 != P[i]: break 
  else: 
    ans += 1

print(ans)

Solution (Python):
import itertools


def bit(n, m):
    bit_list = list(itertools.product([i for i in range(m)], repeat=n))
    return bit_list

N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))

patterns = bit(N, 2)

res = 0
for pattern in patterns:
    flag = True
    
    for i in range(M):
        count = 0
        
        for j in range(L[i][0]):
            if pattern[L[i][j+1] - 1] == 1:
                count += 1
                
        if count%2 != P[i]:
            flag = False
            
    if flag:
        res += 1
        
print(res)

Solution (Python):
from functools import reduce
from operator import add
n, m = [int(i) for i in input().split()]

lamp = [None] * m
for i in range(m):
    tmp = ['0'] * n
    for k in [int(j) for j in input().split()][1:]:
        tmp[n-k] = '1'
    lamp[i] = int(''.join(tmp), 2)

p = [int(i) for i in input().split()]

ans = 0
for i in range(0, 2**n):
    if all([bin(i & lamp[j]).count("1") % 2 == p[j] for j in range(m)]):
        ans += 1

print(ans)

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

def mask(l):
    m = 0
    for i in l:
        m += 2**(i-1)
    return m

masks = list(map(mask, sw))

ret = 0
for i in range(2**N):
    if all(bin(i&m).count('1')%2 == p for m, p in zip(masks, P)):
        ret += 1
print(ret)

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

ans = 0
for i in range( 1 << N):
    t = [0]*M
    for j in range(N):
        if ((i >> j) & 1) == 1:
            for x in range(M):
                for y in range(k[x][0]):
                    if k[x][y+1] == j+1:
                        t[x] += 1
    c = 0
    for q in range(M):
        if t[q] % 2 == p[q]:
            c += 1
    if c == M:
        ans += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

N,M=rl()
S = [[0]*(N+1) for _ in range(M)]
for i in range(M):
    k, *s = rl()
    for s_ in s:
        S[i][s_] = 1
P=rl()

ans = 0
import itertools
for switch in itertools.product(range(2),repeat=N):
    ret = 0
    for p, s in zip(P,S):
        cnt = 0
        for i in range(N):
            cnt += switch[i]*s[i+1]
        if p != cnt%2:
            break
        ret += 1
    ans += ret//M

print(ans)

Solution (Python):
import itertools
N, M = map(int, raw_input().split())
data = [map(int, raw_input().split()) for i in range(M)]
p = map(int, raw_input().split())
k = [data[i][0] for i in range(M)]
s = [data[i][1:] for i in range(M)]

candidate = []

def Check(switches):
    for i in range(M):
        if (sum([switches[s[i][j] - 1] for j in range(k[i])]) % 2) != p[i]:
            return 0
    return 1

print sum(Check(switches) for switches in itertools.product([0, 1], repeat=N))

Solution (Python):
def c_switches(N, M, Switches, P):
    import numpy as np

    def rank_matrix(matrix):
        """mod2 上で行列の階数を求める"""
        num_row, num_col = matrix.shape[0], matrix.shape[1]
        rank = 0

        for col in range(num_col):
            
            pivot = -1
            max_element = 0  
            for row in range(rank, num_row):
                if matrix[row][col] > max_element:
                    max_element = matrix[row][col]
                    pivot = row
            if pivot == -1:
                continue  

            tmp = matrix[pivot, :].copy()
            matrix[pivot, :] = matrix[rank, :]
            matrix[rank, :] = tmp

            
            
            for row in range(num_row):
                if row != rank and matrix[row][col] == 1:
                    for col2 in range(num_col):
                        matrix[row][col2] = (matrix[row][col2] - matrix[rank][col2]) % 2
            rank += 1
        return rank

    
    a = np.zeros((M, N), dtype='int8')
    for t, (_, *switches) in enumerate(Switches):
        for s in switches:
            a[t][s - 1] = 1
    p = np.reshape(P, (-1, 1))
    ap = np.concatenate((a, p), axis=1)  
    rank_a, rank_ap = rank_matrix(a), rank_matrix(ap)
    return 2**(N - rank_a) if rank_a == rank_ap else 0
    

N, M = [int(i) for i in input().split()]
Switches = [[int(i) for i in input().split()] for j in range(M)]
P = [int(i) for i in input().split()]
print(c_switches(N, M, Switches, P))

Solution (Python):
def c_switches(N, M, Switches, P):
    import numpy as np

    def rank_matrix(matrix):
        """mod2 上で行列の階数を求める"""
        num_row, num_col = matrix.shape[0], matrix.shape[1]
        rank = 0

        for col in range(num_col):
            
            pivot = -1
            max_element = 0  
            for row in range(rank, num_row):
                if matrix[row][col] > max_element:
                    max_element = matrix[row][col]
                    pivot = row
            if pivot == -1:
                continue  

            tmp = matrix[pivot, :].copy()
            matrix[pivot, :] = matrix[rank, :]
            matrix[rank, :] = tmp

            
            
            for row in range(num_row):
                if row != rank and matrix[row][col] == 1:
                    for col2 in range(num_col):
                        matrix[row][col2] = (matrix[row][col2] + matrix[rank][col2]) % 2
            rank += 1
        return rank

    
    a = np.zeros((M, N), dtype='int8')
    for t, (_, *switches) in enumerate(Switches):
        for s in switches:
            a[t][s - 1] = 1
    p = np.reshape(P, (-1, 1))
    ap = np.concatenate((a, p), axis=1)  
    rank_a, rank_ap = rank_matrix(a), rank_matrix(ap)
    return 2**(N - rank_a) if rank_a == rank_ap else 0
    

N, M = [int(i) for i in input().split()]
Switches = [[int(i) for i in input().split()] for j in range(M)]
P = [int(i) for i in input().split()]
print(c_switches(N, M, Switches, P))

Solution (Python):
def c_switches(N, M, Switches, P):
    import numpy as np

    def rank_matrix(matrix, is_extended=False):
        num_row = matrix.shape[0]
        num_col = matrix.shape[1]
        rank = 0

        for col in range(num_col):
            
            

            pivot = -1
            ma = 0
            for row in range(rank, num_row):
                if matrix[row][col] > ma:
                    ma = matrix[row][col]
                    pivot = row
            if pivot == -1:
                continue

            tmp = matrix[pivot, :].copy()
            matrix[pivot, :] = matrix[rank, :]
            matrix[rank, :] = tmp

            for row in range(num_row):
                if row != rank and matrix[row][col] == 1:
                    for col2 in range(num_col):
                        matrix[row][col2] = (matrix[row][col2] + matrix[rank][col2]) % 2
            rank += 1
        return rank

    a = np.zeros((M, N), dtype='uint8')
    for t, (_, *switches) in enumerate(Switches):
        for s in switches:
            a[t][s - 1] = 1
    p = np.reshape(P, (-1, 1))
    ap = np.concatenate((a, p), axis=1)
    rank_a, rank_ap = rank_matrix(a), rank_matrix(ap)
    return 2**(N - rank_a) if rank_a == rank_ap else 0

N, M = [int(i) for i in input().split()]
Switches = [[int(i) for i in input().split()] for j in range(M)]
P = [int(i) for i in input().split()]
print(c_switches(N, M, Switches, P))

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

count = 0
for i in range(2**N):
    switch = (("{:0"+str(N)+"b}").format(i))[::-1]
    judge = True
    for m in range(M):
        if sum(int(switch[j-1]) for j in s[m]) % 2 != p[m]:
            judge = False
            break
    if judge:
        count += 1

print(count)

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

for i in range(2**N):
    bulb=[0]*M
    x=format(i,'b').zfill(N)   
    
    for j in range(M):
        
        total=0
        for k in range(arr[j][0]):
            
            
            
            total+=int(x[ arr[j][k+1]-1 ])
        if total%2!=p[j]:
            break
        else:
            bulb[j]=1
    if sum(bulb)==M:
        cnt+=1
        
print(cnt)

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

ans=0
Lswitches=[]
for j in range(2**N):
    Lswitches.append(format(j,'b').zfill(N))

for k in Lswitches:
    M_off=0
    for m in range(M):
        n=1
        Even_Odd=0
        while n<=Lks[m][0]:
            if k[Lks[m][n]-1]=="1":
                Even_Odd+=1
            else:
                pass
            n+=1
        if Even_Odd%2!=Lp[m]:
            M_off+=1
        else:
            pass
    if M_off==0:
        ans+=1
    else:
        pass

print(ans)

Solution (Python):
n, m = [int(x) for x in input().split()]
L = [ [int(x) for x in input().split()] for i in range(m) ]
P = [int(x) for x in input().split()]



S = []
def switch(x=[], y=0):
    if y == n:
        return S.append(x)
    for i in range(2):
        switch(x+[i], y+1)
switch()


ans = 0
for i in S:    
    s = 1
    for j in range(m):    
        
        Sk = []
        for k in L[j][1:]:
            Sk.append(i[k-1])
        
        if Sk.count(1) % 2 == P[j]:
            s *= 1
        else:
            s *= 0
    ans += s

print(ans)

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

import numpy as np
n_pattern = 2**N
form = '0{0}b'.format(N)
ans = 0
from operator import itemgetter
for i in range(n_pattern):
    state = str(format(i, form))
    counter = 0
    for j,k in enumerate(switch_idx):
        if (itemgetter(*(np.array(k)-1))(state).count('1') % 2) == p[j]:
            counter += 1
        if len(switch_idx) == counter:
            ans += 1

print(ans)

Solution (Python):
import sys
from fractions import gcd
from functools import reduce
from itertools import combinations

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def is_MM(s):
    num = int(s)
    return 0 < num <= 12


def solve():
    N, M = il()
    KS = iml(M)
    p = il()

    ans = 0
    for i in range(1 << N):
        for j in range(M):
            swi = 0
            for s in KS[j][1:]:
                swi += 2 ** (s - 1)
            if (bin(i & swi).count("1") % 2) != p[j]:
                break
        else:
            ans += 1
    return ans


if __name__ == "__main__":
    print(solve())

Solution (Python):
N,M=map(int,input().split())
ks=[[int(a) for a in input().split()] for i in range(M)]
p=[int(a) for a in input().split()]
ans=0

for i in range(2**N):
    for j in range(M):
        sw_see=0
        for k in ks[j][1:]:
            sw_see+=2**(k-1)
        if (bin(i&sw_see)).count('1')%2!=p[j]:
            break
    else:
        ans+=1

print(ans)

Solution (Python):
N, M = map(int, input().split())
switch = [[int(_) for _ in input().split()] for _ in range(M)]
p = [int(_) for _ in input().split()]
ans = 0

for i in range(2**N):
    for j in range(M):
        switchnum = 0
        for k in switch[j][1:]:
            switchnum += 2**(k-1)
        
        if (bin(i & switchnum).count('1') % 2 != p[j]):
            break
    else:
        ans += 1

print(ans)

Solution (Python):
n,m=map(int,input().split())
l=[]
count=0
for i in range(m):
  l1=list(map(int,input().split()))
  del l1[0]
  l.append(l1)
lm=list(map(int,input().split()))
for i in range(2**n):
  c2=0
  l2=[]
  for j in range(n):
    if i>=2:
      l2.append(i%2)
      i=i//2
    else:
      l2.append(i)
      i=i//2
  for j in range(m):
    c=0
    for k in range(len(l[j])):
      if l2[l[j][k]-1]==1:
        c+=1
    if c%2==lm[j]:
      c2+=1
  if c2==m:
    count+=1
print(count)

Solution (Python):

n, m = map(int, input().split())
s = []

for i in range(m):
    s.append(list(map(int, input().split())))

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

ans = 0
for value in range(1 << n):
    all = True
    for i in range(m):
        count = 0
        for j in range(1, s[i][0] + 1):
            count += ((1 << (s[i][j] - 1)) & value) != 0
        if count % 2 != p[i]:
            all = False
            break
    if all:
        ans += 1

print(ans)

Solution (Python):
N,M=map(int,input().split())
s=[]
for i in range(M):
    s.append(list(map(int,input().split())))
p=list(map(int,input().split()))
count=0
for state in range(1<<N):
    flag = 0
    for i in range(M):
        count_ = 0
        flag=1
        for j in range(1, s[i][0]+1):
            if (1 << (s[i][j] - 1)) & state:
                count_ += 1
        if count_ % 2 != p[i]:
            flag = 0
            break
    if flag:
        count += 1
print(count)

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

res = 0
for bit in range(1 << n):
  flag = 0
  for i in range(m):
    count = 0
    for j in range(1, l[i][0]+1):
      if (1 << (l[i][j] - 1)) & bit:
        count += 1
      else:
        pass
    if count % 2 == p[i]:
      flag = 1
    else:
      flag = 0
      break
  if flag:
    res += 1
  else:
    pass

print(res)

Solution (Python):
light=input().split(' ')
line=[]
for i in range(int(light[1])):
  line.append(input().split(' ')[1:])
  
switch=input().split(' ')

length=2**int(light[0])
count=0
for i in range(length):
  li=[]
  for j in range(int(light[0]),0,-1):
    if i%2 == 1:
      li.append(1)
    else:
      li.append(0)
      
    i//=2

  flg=True
  for j in range(int(light[1])):
    light_count=0
    for k in line[j]:
      if li[int(k)-1]==1:
        light_count+=1
        
    if light_count%2!=int(switch[j]):
      flg=False
      break

  if flg:
    count+=1
    
print(count)

Solution (Python):


N, M = map(int, input().split())
sm = [list(map(int, input().split()))[1:] for _ in range(M)]
pm = list(map(int, input().split()))


tmp = [[0] * N for _ in range(M)]
for i in range(len(sm)):
    for si in sm[i]:
        tmp[i][si - 1] = 1
sm = tmp


def check(state):
    ret = 0
    for i, k in enumerate(sm):
        c = 0
        for j, s in enumerate(state):
            c += k[j] if s == '1' else 0
        if (c % 2) != pm[i]:
            break
    else:
        ret = 1

    return ret


def count(state):
    ret = 0
    if len(state) == N:
        ret += check(state)
    else:
        for s in '01':
            ret += count(state + s)
    return ret


print(count(''))

Solution (Python):
n, m = map(int, input().split())
switch = [0] * m
for i in range(m):
    s = list(map(int, input().split()))
    for j in s[1:]:
        switch[i] |= 1 << (j - 1)
p = list(map(int, input().split()))
ans = 0
for bit in range(1 << n):
    for i in range(m):
        if bin(bit & switch[i]).count('1') % 2 != p[i]:
            break
    else:
        ans +=1
print(ans)

Solution (Python):
import sys

def all_lighted(input, mod, pattern):
    for i, bulb in enumerate(input):
        if bin(bulb & pattern).count('1') % 2 == mod[i]:
            next
        else:
            return False
    
    return True


def main():
    num_switch, num_bulb = [int(x) for x in sys.stdin.readline().split()]
    input = [0] * num_bulb

    for i in range(num_bulb):
        for x in sys.stdin.readline().split()[1:]:
            input[i] += 2**(int(x) - 1)

    mod = [int(x) for x in sys.stdin.readline().split()]

    count = 0

    for pattern in range(2 ** num_switch):
        if all_lighted(input, mod, pattern): count += 1

    print(count)


if __name__ == "__main__":
    main()

Solution (Python):
import itertools

N, M = map(int, input().split())

Ss = []
for i in range(M):
    tmp = list(map(int,input().split()))
    k = tmp[0]
    Ss.append(list(tmp[1:]))
Ps = list(map(int,input().split()))

all_list = list(itertools.product(range(2),repeat=N))

count = 0
for l in all_list:
    is_ok = True
    for light_num, s in enumerate(Ss):
        summation = 0
        for index in s:
            summation += l[index - 1]
        if summation % 2 != Ps[light_num]:
            is_ok = False
            break
    if is_ok:
        count += 1

print(count)

Solution (Python):




def main():
    
    n, m = [int(s) for s in input().split()]
    reports = [[int(s) for s in input().split()] for _ in range(m)]
    ps = [int(s) for s in input().split()]
    
    def get_switch_lists():
        for i in range(2**n):
            yield [(i//2**k)%2 for k in range(n)]
    def get_odd(switch_list, repo):
        return sum(switch_list[r-1] for r in repo[1:]) % 2
    ans = 0
    for switch_list in get_switch_lists():
        qs = [get_odd(switch_list, repo) for repo in reports]
        if all(p==q for p, q in zip(ps, qs)):
            ans += 1
    
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
onptns = []
for i in range(M):
    k, *s= list(map(int, input().split()))
    onptn = 0
    for i in s:
        onptn += 1 << (i - 1)
    onptns.append(onptn)
ps = list(map(int, input().split()))

ans = 0

s = 0
while s < (1 << N):
    ans += 1
    for onptn, p in zip(onptns, ps):
        if bin(s & onptn).count('1') % 2 != p:
            ans -= 1
            break
    s += 1

print(ans)

Solution (Python):
n,m=map(int,input().split())
List=[list(map(int,input().split())) for i in range(m)]
P=list(map(int,input().split()))

ans=0

for i in range(2**n):
    flug=True
    for l in range(m):
        count=0
        for j in range(List[l][0]):
            if ((i >> (List[l][j+1]-1))&1)==1:
                count += 1
        if count%2 != P[l]:
            flug=False
    if flug==True:
        ans += 1
        
print(ans)