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())
s=[]
for i in range(m):
    ks=list(map(int,input().split()))
    s.append(ks[1:])
p=list(map(int,input().split()))
ans=0
for i in range(1<<n):

    for j in range(m):
        cnt=0
        for k in s[j]:
            if i&1<<(k-1):
                cnt+=1
        if cnt%2!=p[j]:
            break
    else:
        ans+=1

print(ans)

Solution (Python):
from itertools import product

N, M = map(int, input().split())
S = []
for _ in range(M):
    xs = list(map(int, input().split()))
    S.append([x - 1 for x in xs[1:]])
P = list(map(int, input().split()))

counter = 0
for sw in product([True, False], repeat=N):
    for i in range(M):
        if sum(1 if sw[j] else 0 for j in S[i]) % 2 != P[i]:
            break
    else:
        counter += 1
print(counter)

Solution (Python):
from itertools import product

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

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

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

ans = 0
for j in product([1,0],repeat=n):
    for i, s in enumerate(x):
        if sum([j[k-1] == 1 for k in s]) % 2 != p[i]:
            break
            
    else:
        ans += 1

print(ans)

Solution (Python):
from itertools import product
import numpy as np

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

lst = [list(map(int, input().split())) for _ in range(M)]
p_lst = np.array(list(map(int, input().split())))

ans = 0
mat = [[0]*N for _ in range(M)]

for j, lst2 in enumerate(lst):
    for i in lst2[1:]:
        mat[j][i-1] = 1

mat_np = np.array(mat)

for a in product([0, 1], repeat=N):
    l = np.array(a)
    b = np.dot(mat_np, l)%2
    if np.sum(b==p_lst)==M:ans += 1

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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):
N,M = map(int,input().split())
B = [list(map(int,input().split())) for _ in range(M)]
P = list(map(int,input().split()))

def isOn(sw, b, p):
    onCount = 0
    for i in range(1,b[0]+1):
        if sw[b[i]-1] == '1':
            onCount += 1
    if onCount % 2 == p:
        return True
    return False

ans = 0
for i in range(1<<N):
    sw = format(i, '0' + format(N, 'd') + 'b')
    for j in range(M):
        if not isOn(sw, B[j], P[j]):
            break
    else:
        ans += 1

print(ans)

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

ans = 0
for i in range(1 << n):
    al = True
    v = [bool(i & (1 << x)) for x in range(n)]
    for j in range(m):
        num = 0
        for t in s[j]:
            num += v[t - 1]
        if p[j] != num % 2:
            al = False
    ans += al
print(ans)

Solution (Python):
N,M = map(int,input().split())
D = tuple(tuple(int(i) for i in input().split())for _ in range(M)) 

S = [[]for i in range(N)]

for i in range(M):
    for j in D[i][1:]:
        S[j-1].append(i)
P = tuple(int(i) for i in input().split())
ans = 0
for i in range(2**N):
    bit = bin(i)[2:][::-1]
    L = [0 for _ in range(M)]
    for j,s in enumerate(list(bit)):
        if s == '1':
            for k in S[j]:
                L[k] += 1
    flag = True
    for j in range(M):
        if L[j]%2 != P[j]:
            flag = False
    if flag:
        ans += 1
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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_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):
n, m = map(int, input().split())
sw = [list(map(int, input().split())) for _ in range(m)]
for x in sw:
    x.pop(0)
p = list(map(int, input().split()))

ans = 0
for i in range(1<<n):
    s = str(bin(i).replace('0b', '')).zfill(n)
    for j in range(m):
        sum_sw=0
        for k in sw[j]:
            sum_sw+=int(s[k-1])
        if p[j] != sum_sw%2:
            break
    else:
        ans+=1
        
print(ans)

Solution (Python):
n,m = map(int,input().split())
S = [list(map(int,input().split()))[1:] for _ in range(m)]
P = list(map(int,input().split()))
A = int("1"*n,2)
cnt = 0
for i in range(A+1):
    a = bin(i)[2:].zfill(n)
    l = list(map(int,list(a)))
    for j in range(m):
        cnt1 = 1
        b = 0
        for s in S[j]:
            b += l[s-1]
        if b%2 != P[j]:
            cnt1 = 0
            break
    cnt += cnt1
print(cnt)

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

for i in range(M):
    a = list(map(int,input().split()))
    a.pop(0)
    sum = 0
    for j in range(len(a)):
        sum += 2**(a[j]-1)
    array.append(sum)

s = 0
for i in range(N):
    s += 2**i

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

total = 0
for switch in range(s+1):
    c = 0
    for i in range(M):
        if (bin(switch & array[i]).count('1'))%2 == p[i]:
            c += 1
    if c == M:
        total += 1

print(total)

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

ans=0

for i in range(2**n):
    l = [False]*n
    for j in range(n):
        if(i>>j & 1):
            l[j] = True

    light = 0
    for x,aa in enumerate(a):
        cnt = 0
        for y,k in enumerate(aa):
            if y == 0:
                continue
            if l[k-1] == True:
                cnt += 1
        if cnt%2 == p[x]:
            light += 1
    if light == m:
        ans += 1
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, M = MAP()
L = [MAP()[1:] for _ in range(M)]
P = MAP()



switches = []
for i in range(2**N):
	switch = [0]*N
	for j in range(N):
		if ((i>>j) & 1):
			switch[N-j-1] = 1
	switches.append(switch)

ans = 0
for s in switches:
	for idx,l in enumerate(L):
		count = 0
		
		for ll in l:
			count+=s[ll-1]
		if count%2!=P[idx]: break
	else:
		ans += 1

print(ans)

Solution (Python):



def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n, m = rli()
    switch = []
    for i in range(m):
        tmp = rli()
        k = tmp[0]
        ls = tmp[1:]
        switch.append(ls)
    lp = rli()
    ans = 0
    def check(mask):
        on_off = []
        for i in range(0, n):
            on_off.append(mask & (1 << i))
        for i in range(m):
            cnt = sum(1 for s in switch[i] if on_off[s-1])
            if cnt % 2 != lp[i]:
                return 0
        return 1
    ans = 0
    for i in range(1 << n):
        ans += check(i)
    print(ans)





if __name__ == '__main__':
    main()

Solution (Python):
n, m = map(int, input().split())
A = []
for _ in range(m):
  k, *s = map(int, input().split())
  c = 0
  for i in s:
    c += 2**(i-1)
  A.append(c)
P = tuple(map(int, input().split()))
ans = 0
for i in range(2**n):
  f = True
  for j in range(m):
    c = bin(i & A[j]).count("1")
    if c%2 != P[j]:
      f = False
      break
  if f:
    ans += 1
print(ans)

Solution (Python):
import itertools
N,M = map(int,input().split())
switch = [list(map(int,input().split())) for m in range(M)]
p = list(map(int,input().split()))

S = list(itertools.product([0,1], repeat=N))
ans = 0
for s in S:
    s_ok = 0
    
    for m in range(M):
        count = 0
        
        for i in range(1, switch[m][0]+1):
            if s[switch[m][i]-1] == 1:
                count += 1
        if count%2 == p[m]:
            s_ok += 1
        else:
            break
    if s_ok == M:
        ans += 1
print(ans)

Solution (Python):
import itertools
N,M = map(int,input().split())
switch = [list(map(int,input().split())) for m in range(M)]
p = list(map(int,input().split()))
S = list(itertools.product([0,1], repeat=N))
ans = 0
for s in S:
    s_ok = 0
    for m in range(M):
        count = 0
        for i in range(1, switch[m][0]+1):
            if s[switch[m][i]-1] == 1:
                count += 1
        if count%2 == p[m]:
            s_ok += 1
        else:
            break
    if s_ok == M:
        ans += 1
print(ans)

Solution (Python):
import itertools
N,M = map(int,input().split())
switch = [list(map(int,input().split())) for m in range(M)]
p = list(map(int,input().split()))
S = list(itertools.product([0,1], repeat=N))
ans = 0
for s in S:
    s_ok = 0
    for m in range(M):
        count = 0
        for i in range(1, len(switch[m])):
            if s[switch[m][i]-1] == 1:
                count += 1
        if count%2 == p[m]:
            s_ok += 1
        else:
            break
    if s_ok == M:
        ans += 1
print(ans)

Solution (Python):
import copy

N,M = map(int, input().split())
jisho = [[] for i in range(N)]
for i in range(M):
    val = input().split()
    for j in val[1:]:
        jisho[int(j)-1].append(i)

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

sw = []
def create_ki(data):
    if len(data) == N:
        sw.append(data)
        return
    tmp = copy.copy(data)
    tmp.append(0)
    create_ki(tmp)
    tmp2 = copy.copy(data)
    tmp2.append(1)
    create_ki(tmp2)

create_ki([])

ans = 0
for val in sw:
    num = 0
    sw2 = [0]*M
    for i in val:
        if i == 0:
            num += 1
            continue
        data = jisho[num]
        for j in data:
            sw2[j] += 1
        num += 1
    cn = 0
    for j in sw2:
        if j % 2 != p[cn]:
            break
        cn += 1
    if cn == M:
        ans += 1

print(ans)

Solution (Python):

N, M = map(int, input().split())
K, S = [], []
for i in range(M):
    tmp = list(map(int, input().split()))
    K.append(tmp[0])
    S.append(tmp[1:])
P = list(map(int, input().split()))

ans = 0
for bit in range(2**N):
    lamp = 0
    switch = [0] * N
    
    for j in range(N):
        if (bit >> j) & 1 == 1:
            switch[j] = 1
    
    for i in range(M):
        cnt = 0
        for k in range(N):
            if k+1 in S[i] and switch[k] == 1:
                cnt += 1
        
        if cnt % 2 == P[i]:
            lamp += 1
    if lamp == M:
        ans += 1
print(ans)

Solution (Python):
n,m=map(int,input().split())
tmp=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split()))
k=[tmp[i][0] for i in range(m)]
s=[tmp[i][1:] for i in range(m)]
ans=0
for switch in range(2**n):
  on_all=True
  for light in range(m):
    cnt=0
    for connect in s[light]:
      if switch>>(connect-1)&1==1:
        cnt+=1
    if cnt%2!=p[light]:
      on_all=False
  if on_all:
    ans+=1
print(ans)

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

ans = 0

for i in range(2 ** n):
    switch = [0 for i in range(n)]
    for j in range(n):
        if ((i >> j) & 1):
            switch[n - 1 - j] = 1
    for l in range(m):
        cnt = 0
        for s in K[l][1:]:
            cnt += switch[s-1]
        if cnt % 2 != P[l]:
            break
    else:
        ans += 1

print(ans)

Solution (Python):
N,M=map(int,input().split())
L=[list(map(int,input().split()))[1:] for _ in range(M)]
P=list(map(int,input().split()))
ans=0
for i in range(2**N):
  lit=[0]*M
  for j,switch in enumerate(L):
    cnt=0
    for s in switch:
      if i>>(s-1)&1:
        cnt+=1
    if cnt%2==P[j]:
      lit[j]=1
    else:
      lit[j]=0
  if all(lit): ans+=1 
print(ans)

Solution (Python):
N,M=map(int,input().split())
L=[list(map(int,input().split()))[1:] for _ in range(M)]
P=list(map(int,input().split()))
ans=0
for i in range(2**N):
  lit=[0]*M
  for j,switch in enumerate(L):
    cnt=0
    for s in switch:
      if i>>(s-1)&1:
        cnt+=1
    if cnt%2==P[j]:
      lit[j]=True
    else:
      lit[j]=False
  if all(lit): ans+=1 
print(ans)

Solution (Python):
N,M=map(int,input().split())
L=[list(map(int,input().split())) for _ in range(M)]
P=list(map(int,input().split()))
ans=0
for i in range(2**N):
  lit=[0]*M
  for j,switch in enumerate(L):
    cnt=0
    for s in switch[1:]:
      if i>>(s-1)&1:
        cnt+=1
    if cnt%2==P[j]:
      lit[j]=True
    else:
      lit[j]=False
  if all(lit):
    ans+=1
print(ans)

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







s_pattern = [''] * (2**n)
str_format = '{:0' + str(n) + 'b}'
for i in range(2**n):
  s_pattern[i] = str_format.format(i)


ans = 0

for i in range(2**n):
  pattern = s_pattern[i]
  for j in range(m):
    need_switches = s[j]
    on_count = 0
    for switch in need_switches:
      if pattern[switch-1] == '1':
        on_count += 1
    
    
    if on_count % 2 == p[j]:
      continue
    else:
      break
  else:
    
    ans += 1

print(ans)

Solution (Python):
n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for i in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    l=[False]*n
    for j in range(n):
        if(i>>j & 1):
            l[j]=True
    
    light=0
    for x,aa in enumerate(a):
        cnt=0
        for y,k in enumerate(aa):
            if y==0:
                continue
            if l[k-1]==True:
                cnt+=1
        if cnt%2==p[x]:
            light+=1
    if light==m:
        ans+=1
print(ans)

Solution (Python):
n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for i in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    l=[False]*n
    for j in range(n):
        if(i>>j & 1):
            l[j]=True
    
    light=0
    for x,aa in enumerate(a):
        cnt=0
        for y,k in enumerate(aa):
            if y==0:
                continue
            if l[k-1]==True:
                cnt+=1
        if cnt%2==p[x]:
            light+=1
    if light==m:
        ans+=1
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))
res=[0 for i in range(n)]
cnt=0

def ch():
    global res,cnt,p,a
    my_cnt=0
    for i in range(m):
        pre=0
        for j in range(len(a[i])):
            if j==0: continue
            pre+=res[a[i][j]-1]
        if p[i]==0:
            if pre%2==0:
                my_cnt+=1
        else:
            if pre%2==1:
                my_cnt+=1
    if my_cnt==m:
        
        cnt+=1
        
def abc(i):
    global res
    if i==n:
        ch()
    else:
        res[i]=0
        abc(i+1)
        res[i]=1
        abc(i+1)

abc(0)
print(cnt)

Solution (Python):
n, m = map(int, input().split())
k = [0] * m
s = [[]] * m
t = [set() for _ in range(n)]
for i in range(m):
    ki, *si = map(int, input().split())
    k[i] = ki
    for j in si:
        t[j - 1].add(i)
p = list(map(int , input().split()))
ans = 0
for i in range(2 ** n):
    on = [0] * m
    light = [0] * m
    for j in range(n):
        if((i >> j) & 1):
            for k in t[j]:
                light[k] += 1
            
    is_all = True
    for x in range(m):
        is_all = is_all and (light[x] % 2 == p[x])
    if is_all:
        ans += 1
print(ans)

Solution (Python):
import itertools

n, m = input().split()
n, m = int(n), int(m)
 
bulbs = []
 
for i in range(m):
    l = input().split()
    arr = [int(x) for x in l][1:]
    bulbs.append(arr)

needs = [int(x) for x in input().split()]
 
combos = 0

def test(lis):
  for i in range(m):
    curr = 0
    need = needs[i]
    for b in bulbs[i]:
      if lis[b-1] == 1:
        curr += 1
    if curr % 2 != need:
      return False
  return True
  
for i in itertools.product([0, 1], repeat=n):
  if test(list(i)):
    combos += 1

print(combos)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
lst = [LI() for _ in range(m)]
p = LI()
ans = 0
for i in range(2**n):
    b = [0]*n
    for j in range(n):
        if (i >> j) & 1:
            b[j] = 1
    for j in range(m):
        tmp = 0
        k = lst[j][0]
        for l in range(1,k+1):
            if b[lst[j][l]-1] == 1:
                tmp += 1
        if tmp % 2 != p[j]:
            break
    else:
        ans += 1
print(ans)

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

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

ans = 0
for i in range(2**N):
    light_cnt = 0
    for condition_idx in range(M):


        switch_num = 0
        for j in range(N):
            if i >> j & 1 and j+1 in conditions[condition_idx][1:]: 
                switch_num += 1
        if switch_num%2 == p[condition_idx]:
            light_cnt += 1
    if light_cnt == M:
        ans += 1
print(ans)

Solution (Python):
n, m = list(map(int, input().split()))
light = []
for i in range(m):
    k = list(map(int, input().split()))
    aaaaa = [0 for i in range(n)]
    for i in range(k[0]):
        aaaaa[k[i+1] - 1] = 1
    aaaaa = int("".join(map(str, aaaaa)), 2)
    light.append(aaaaa)
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    flag = 1
    for j in range(len(light)):
        
        k = i & light[j]
        if list(bin(k)).count("1") % 2 != p[j]:
            flag = 0
    if flag:
        ans += 1
print(ans)

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

msk = [0] * m
for i in range(m):
    lst = list(map(int, input().split()))
    for j in range(1, lst[0] + 1):
        msk[i] |= 1 << lst[j] - 1

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

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

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

N, M = [int(x) for x in input().strip().split()]

K = [0] * M
S = [0] * M
P = [0] * M

for i in range(M):
    t_ = [int(x) for x in input().strip().split()]
    K[i], S[i] = t_[0], t_[1:]

P = [int(x) for x in input().strip().split()]

def check(sw, s, p, M):
    for m in range(M):
        if sum([sw[i-1] for i in s[m]]) % 2 != p[m]:
            return 0
    else:
        return 1

def f(sw, s, p, M, i, K, N):
    if i == N:
        return check(sw, s, p, M)
    ans = 0
    for j in (0, 1):
        sw_ = sw[:]
        sw_[i] = j
        ans += f(sw_[:], s, p, M, i+1, K, N)
    return ans

print(f([0 for _ in range(N)], S, P, M, 0, K, N))

Solution (Python):
N, M = list(map(int,input().split()))
s = []
ans = 0
for _ in range(M):
    temp = list(map(int, input().split()))
    s.append(temp[1:])
p = list(map(int, input().split()))
for i in range(2 ** N):
    flag = 1
    flag_1 = 1
    sw = bin(i)[2:]
    sw = sw.zfill(N)
    for j in range(M):
        sumsw = 0
        for k in s[j]:
            sumsw += int(sw[k-1])
        if sumsw % 2 != p[j]:
            flag = 0
            flag_1 = 0
            break
        if flag_1 == 0:
            break
    if flag:
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
k = [[int(i) for i in input().split(" ")] for i in range(m)]
p = [int(i) for i in input().split(" ")]
c = 0
for i in range(2**n):
    t = bin(i+2**n)[2:]
    a = sum([0 if sum([1 if t[l]=="1" else 0 for l in k[j][1:]])%2 == p[j] else 1 for j in range(len(k))])
    if a == 0:
        c+=1
print(c)

Solution (Python):

import numpy as np
N, M = map(int, raw_input().split())
k = np.empty(M, dtype=int)
s = []
for i in xrange(M):
    inp = map(int, raw_input().split())
    k[i] = inp[0]
    s.append(np.array(inp[1:])-1)

is_odd = np.array(map(int, raw_input().split()), dtype=bool)

ans = 0
for i in xrange(2**N):
    all_lighted = True
    on = np.array([int(k) for k in"{:0{}b}".format(i,N)])
    for j in xrange(M):
        if not np.sum(on[s[j]]) % 2 == is_odd[j]:
            all_lighted=False
            break
    if not all_lighted:
        continue
    ans += 1

print ans

Solution (Python):
n, m = map(int, input().split())
x = []
for i in range(2**n):
    x.append(format(i, '011b'))
y = []
for _ in range(m):
    _, *s = map(int, input().split())
    y.append(s)
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    f = 0
    for j in range(m):
        cnt = 0
        for k in y[j]:
            cnt += int(x[i][k - n - 1])
        if cnt % 2 == p[j]:
            f += 1
    if f == m:
        ans += 1
print(ans)

Solution (Python):
import sys
import math
import itertools


def main():
    N,M = map(int,input().split())
    S={}
    P=[0] * (M+1)
    List=[]
    for i in range(1,M+1):
        array = list(map(int, input().split()))
        for s in range(1,len(array)):
            
            if i in S.keys():
                S[i].append(array[s])
            else:
                S[i]=[]
                S[i].append(array[s])

    array = list(map(int, input().split()))
    for i in range(1,M+1):
        P[i]=array[i-1]

    for i in range(N):
        List.append(i+1)

    comb=[]
    count=0
    for i in range(1,N+1):
        for l in itertools.combinations(List,i):
            comb=l       
            flag=-1
            for j in range(1,M+1):
                
                cnt=0
                for k in range(0,len(comb)):
                    if comb[k] in S[j]:
                        cnt+=1
                if cnt%2==P[j]:
                    flag=1
                else:
                    flag=-1
                    break
            if flag==1:
                count+=1

    for j in range(1,M+1):
        if(0==P[j]):
            flag=1
        else:
            flag=-1
            break
    if flag==1:
        count+=1
        
    print(count)
                    
                               
if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
import numpy as np
import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
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(map(int, input().split())) for _ in range(n)]


def main():
    n,m=inpm()
    s=inpll(m)
    p=inpl()
    k=[]
    cnt = 0
    for i in range(m):
        k.append(s[i][0])
        s[i].pop(0)
    
    for i in range(n+1):
        for lis in combinations(range(n),i):
            a = [0 for _ in range(n)]
            for j in lis:
                a[j] = 1
            key = 0
            for den in range(m):
                b = [0 for _ in range(n)]
                for con in s[den]:
                    b[con-1]=1
                a=np.asarray(a)
                b=np.asarray(b)
                x = np.dot(a,b)
                if x%2 != p[den]:
                    key = 1
                    break
            if key == 0:
                cnt+=1
    print(cnt)

if __name__ == "__main__":
    main()

Solution (Python):
N,M= map(int,input().split(' '))
KSn =[]
for _ in range(M):
    KS = list(map(int,input().split(' ')))
    K = KS[0]
    Sn = KS[1:K+1]
    KSn.append(Sn)
Pn = list(map(int,input().split(' ')))

def bit_cal2(n):
    return_list = ['']* (2 ** n)
    for i in range(2 ** n):
        for j in range(n):
            if ((i >> j) & 1):
                return_list[i] = return_list[i] + '1'
            else:
                return_list[i] = return_list[i] + '0'
    return return_list

possible_list = bit_cal2(N)
comb_count = 0
for possible in possible_list:
    flag = True
    for i in range(M):
        count = 0
        for i2 in KSn[i]:
            count += int(possible[i2-1])
        if count%2 != Pn[i]:
            flag = False
            break
    if flag:
        comb_count += 1
print(comb_count)

Solution (Python):
import itertools
N,M = map(int,input().split())
X=[]
for i in range(M):
  X+=[[int(x) for x in input().split()]]
P=[int(x) for x in input().split()]
result=0
for switch in itertools.product([0,1],repeat=N):
  on=0
  for i in range(M):
    count=0
    for j in range(X[i][0]):
      if switch[X[i][j+1]-1]==1:
        count +=1
    if count%2==P[i]:
      on +=1
    else:
      break
  if on==M:
    result +=1
print(result)

Solution (Python):

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



a = [0] * N
for i in range(M):
    K, *S = list(map(int, input().split()))
    for j in range(K):
        s = S[j]
        s -= 1
        
        a[s] |= 1 << i

expected = 0
l = list(map(int, input().split()))
for i in range(M):
    expected |= l[i] << i



ans = 0
for s in range(1 << N):
    
    lighting = 0
    for i in range(N):
        
        if s >> i & 1:
            
            lighting ^= a[i]
    
    if lighting == expected:
        ans += 1

print(ans)

Solution (Python):
import sys
import itertools


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    ks = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    p = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for v in itertools.product([True, False], repeat=n):
        b = True
        for i in range(m):
            t = 0
            for kv in ks[i][1:]:
                t += v[kv-1]
            if t % 2 != p[i]:
                b = False
                break
        if b:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    solve()

Solution (Python):




n, m = map(int, input().split())
balbs = [[] for _ in range(m)]
for i in range(m):
    
    connectswtiches = list(map(lambda x: int(x) - 1, input().split()))[1:]
    balbs[i] = connectswtiches

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


def f(cur, n):
    if n == 0:
        
        for i, balb in enumerate(balbs):
            on_switch_count = 0
            for swtich_n in balb:
                if cur[swtich_n] == 1:
                    on_switch_count += 1
            if correct_state[i] != on_switch_count % 2:
                return 0
        return 1

    ret = 0
    lnh = len(cur)
    nex = cur[:]
    nex[lnh - n - 1] = 1
    ret += f(nex, n - 1)
    nex[lnh - n - 1] = 0
    ret += f(nex, n - 1)
    return ret


print(f([0 for _ in range(n)], n))

Solution (Python):
N, M = map(int, input().split())
s = []
for i in range(M):
  k = list(map(int, input().split()))
  k.pop(0)
  s.append(k)
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
  c = []
  for j in range(N):
    c.append((i >> j)&1)
  flag = True
  for j in range(M):
    count =  0
    for l in range(len(s[j])):
      if c[s[j][l]-1]==1:
        count+=1
    if count % 2 != p[j]:
      flag = False
  if flag:
    ans += 1
print(ans)

Solution (Python):
N,M = [int(i) for i in input().split()]
switches = []
for i in range(M):
    buff = 0
    k,*sss = [int(i) for i in input().split()]
    for s in sss:
        buff += 1 << (s-1)
    switches.append(buff)

ppp = [int(i) for i in input().split()]
ans = 0
for i in range(1<<N):
    for p,s in zip(ppp,switches):
        buff = s&i
        buff = bin(buff).count("1")%2
        if buff != p:
            break
    else:
        ans += 1

print(ans)

Solution (Python):
N,M = [int(i) for i in input().split()] 
kslist = []
for i in range(M):
    kslist.append([int(i)-1 for i in input().split()][1:])
plist = [int(i) for i in input().split()]




count = 0

lamp_str = "0"*N
for i in range(2**N):
    lamp_onoff_list = [int(i) for i in lamp_str]
    iflampturnson = [0 for i in range(M)]
    for j in range(M):
        for s in kslist[j]:
            iflampturnson[j] += lamp_onoff_list[s]
    
    iflampturnson = [k%2 for k in iflampturnson]
    
    buff = True
    for k in range(M):
        if plist[k] != iflampturnson[k]:
            buff = False
    if buff == True:
        count += 1

    lamp_str = format(int(lamp_str,2) + 1,"b")
    lamp_str = lamp_str.zfill(N)

print(count)