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())
k = [0]*m
s = [0]*m

for i in range(m):
    k[i], *s[i] = map(int,input().split())

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

ans = 0
for i in range(1 << n):
    cnt = [0]*m
    for j in range(n):
        if (i >> j) % 2 == 1:
            for a in range(m):
                if j + 1 in s[a]:
                    cnt[a] += 1
    chk = 0
    for j in range(m):
        if cnt[j] % 2 != p[j]:
            chk = 1
            break
    if chk == 0:
        ans += 1
print(ans)

Solution (Python):
N,M = map(int,input().split())
array = []
for _ in range(M):
    array.append(list(map(int,input().split()))[1:])
P = list(map(int,input().split()))
count = 0
for mask in range(2**N):
    se = set()
    for i in range(N):
        if mask>>i & 1:
            se.add(i+1)
    for m in range(M):
        p = P[m]
        tmp = 0
        for j in array[m]:
            if j in se:
                tmp+=1
        if tmp%2!=p:
            break
    else:
        count+=1
print(count)

Solution (Python):
from collections import deque

N, M = map(int, input().split())
k = deque()
s = deque()
for _ in range(M):
    inp = list(map(int, input().split()))
    k.append(inp[0])
    s.append(inp[1:])
p = list(map(int, input().split()))

ans = 0
for i in range(1<<N):
  all_on = True
  for m_i in range(M):
    swon = 0
    for s_i in s[m_i]:
      if i>>(s_i-1)&1:
        swon += 1
    
    if swon%2 != p[m_i]: 
      all_on = False
      break
  
  if all_on: ans += 1

print(ans)

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())
k = [list(map(int, readline().split())) for _ in range(m)]
p = list(map(int, readline().split()))

ans = 0
flag = True

for i in product((0, 1), repeat=n):
    

    for j, valK in enumerate(k):
        pp = p[j]
        temp = 0
        for k1, k2 in enumerate(valK):
            if (k1 == 0):
                continue
            else:
                temp += i[k2 - 1]

        if (temp % 2 == pp):
            continue
        else:
            flag = False
            break
    if (flag is False):
        flag = True
        continue
    else:
        ans += 1


print(ans)

Solution (Python):
def resolve():
    N, M = list(map(int, input().split()))
    swi = []
    for i in range(M):
        k, *ss = list(map(int, input().split()))
        t = 0
        for s in ss:
            t += 1 << (s-1)
        swi.append(t)

    ps = list(map(int, input().split()))
    ans = 0
    for i in range(1 << N):
        for s, p in zip(swi, ps):
            t = i & s
            c = bin(t).count('1') % 2
            if c != p:
                break
        else:
            ans += 1
    print(ans)
    return

resolve()

Solution (Python):
N,M = map(int,input().split())
K = [0 for m in range(M)]
count = 0

for m in range(M):
  K[m] = list(map(int,input().split()))
P = list(map(int,input().split()))

for i in range(2**N):
  op = [0]*N
  for j in range(N):
    if ((i>>j) & 1):
      op[N-1-j] = 1
      
  flag = True
  
  for k in range(M):
    S = 0
    for l in range(K[k][0]):
      S += op[K[k][l+1]-1]
    if S % 2 != P[k]:
      flag = False
  if flag:
    count += 1
    
print(count)

Solution (Python):

import itertools

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

bits = itertools.product(["on", "off"], repeat=N)

def tento(bit, k, p):
    for i, pi in enumerate(p):
        ki = list(k[i])
        tmp = 0
        for kij in ki[1:]:
            if bit[kij-1] == "on":
                tmp += 1
        if tmp % 2 != pi:
            return False
    return True

res = 0
for bit in bits:
    if tento(bit, k, p):
        res+=1
print(res)

Solution (Python):
n,m=map(int,input().split())
denk=[]
for _ in range(m):
  s=list(map(int,input().split()))
  denk.append(s[1:])
amari=list(map(int,input().split()))

ans=0


for i in range(2**n):
  kara=[]
  check=0
  for j in range(n):
    if (i>>j)&1:
      kara.append(j+1)
  for q in range(m):
    kari=denk[q]
    kyoutuu=set(kari)&set(kara)
    aa=len(kyoutuu)%2
    if aa==amari[q]:
      check+=1
  if check==m:
    ans+=1
    
print(ans)

Solution (Python):
import sys
import math
import itertools


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    K = [[] for _ in range(M)]

    for j in range(M):
        k = list(map(int, input().split()))
        K[j] = set(k[1:])
    P = list(map(int, input().split()))
    count = 0
    l = list(range(1, N + 1))
    for i in range(0, N + 1):
        for comb in itertools.combinations(l, i):
            flag =0
            for j in range(M):  
                temp = set(comb)
                if len(temp.intersection(K[j]) )% 2 != P[j]:
                    flag = 1
                    break
            if flag ==0:
                count +=1
    print(count)

if __name__ == "__main__":
    main()

Solution (Python):
n,m = map(int,input().split())
s = [0] * m
ans = 0
for i in range(m):
    s[i] = list(map(int,input().split()))
    s[i] = s[i][1:]
p = list(map(int,input().split()))
for k in range(2**n):
    a = format(k,'0'+str(n)+'b')
    t = True
    for i in range(m):
        if sum(a[j-1] == '1' for j in s[i])%2 != p[i]:
            t = False
            break
    ans += t
print(ans)

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

ans = 0
for state in range(2 ** N):
  for m in range(M):
    count = 0
    for s in S[m]:
      if state & (1 << (s - 1)):
        count += 1
    if count % 2 != P[m]:
      break
  else:
    ans += 1
print(ans)

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

ans = 0
for i in range(2**n): 
    cnt = 0
    for j in range(m): 
        s_on = 0
        for k in range(s[j][0]):
            s_on += (i >> (s[j][k+1]-1) & 1)
        if s_on % 2 == p[j]:
            cnt += 1
    if cnt == m:
        ans += 1

print(ans)

Solution (Python):
import sys
N,M =map(int, input().split())
q = list()

for i in range(M):
  q.append(list(map(int, input().split()))) 
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())

switch = []

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


ans = 0
for i in range(2**n):
    s = []
    for j in range(n):
        s.append((i>>j)&1)
    f = 1
    for j in range(m):
        a = 0
        for k in switch[j]:
            a += s[k]

        if a%2== p[j]:
            pass
        else:
            f = 0
            break

    if f:
        ans += 1

print(ans)

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

total = 0
for i in range(int(2**N)):
  bin_val = bin(i)				
  bin_val = str(bin_val[2:])	
  bin_val = bin_val.zfill(N)	

  
  flag = 1
  for j in range(M):
    count = 0
    k = ks[j][0]
    s = ks[j][1:k+1]
    for l in range(k):      
      if bin_val[s[l]-1] == '1':
        count += 1
    if count % 2 != p[j]:
      flag = 0
      break
  if flag == 1:
    total += 1
print(total)

Solution (Python):
n, m = map(int, input().split())
q = list()
for i in range(m):
    q.append(list(map(int, input().split())))
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 = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))

ans = 0
B = 1 << N
for i in range(B):
  L = [0] * M
  for j in range(M):
    for k in ks[j][1:]:
      if i >> (k - 1) & 1:
        L[j] = (L[j] + 1) % 2
  for j in range(M):
    if L[j] != p[j]:
      break
  else:
    ans += 1

print(ans)

Solution (Python):







__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


def main():
  N, M = list(map(int, input().split()))
  l_s = []
  for i in range(M):
    l_s.append(list(map(int, input().split()))[1:])
  P = list(map(int, input().split()))

  ans = 0
  for bit in range(1 << N):
    
    for lidx, ss in enumerate(l_s):

      num_on_s = 0
      for s in ss:
        mask = (1 << (s-1))
        if bit & mask:
          num_on_s += 1
      if num_on_s % 2 == P[lidx]:
        continue
      break
    else:
      ans += 1
  print(ans)


if(__name__ == '__main__'):
  main()

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

ans = 0
for state in range(1 << N):
    for m in range(M):
        count = 0
        for s in S[m]:
            if state & (1 << (s - 1)):
                count += 1
        if count % 2 != P[m]:
            break
    else:
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
switch = [list(map(lambda x:int(x)-1, input().split()))[1:] for _ in range(m)]
rest = list(map(int, input().split()))
ans = 0
for bit in range(1<<n):
    for j in range(m):
        on_sum = 0
        for i in range(n):
            if bit >> i & 1 and i in switch[j]:
                on_sum += 1
        if on_sum % 2 != rest[j]:
            break
    else :
        ans += 1
print(ans)

Solution (Python):
from itertools import product

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


def on_count(p):
    c = 0
    while p > 0:
        if p % 2 == 1:
            c += 1
        p //= 2
    return c


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

total = 0
for pattern in product([0, 1], repeat=N):
    t = 0
    for k, indices in enumerate(switches):
        n_on = 0
        for idx in indices:
            if pattern[idx-1]:
                n_on += 1
        if n_on % 2 == P[k]:
            t += 1
    if t == M:
        total += 1
print(total)

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()))

ans = 0
for i in range(1 << n):
    light = 0
    for j in range(m):
        cnt = 0
        for k in range(n):
            if i >> k & 1 and (k + 1) in s[j]:
                cnt += 1
        if cnt % 2 == p[j]:
            light += 1
    if light == m:
        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()))
ans = 0
for i in range(1<<N):
    ok = True
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i&(1<<(s-1)):
                cnt += 1
        if cnt%2 != P[j]:
            ok = False
            break
    if ok:
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
klst = []
for i in range(m):
  klst.append(list(map(lambda x: int(x) - 1, input().split()))[1:])
plst = list(map(int, input().split()))
res = 0
for ibit in range(2 ** n):
  TF = True
  for j in range(m):
    cnt = 0
    for swnum in klst[j]:
      if ((ibit >> swnum) & 1):
        cnt += 1
    if cnt % 2 != plst[j]:
      TF = False
  if TF:
    res += 1
print(res)

Solution (Python):
n,m= map(int,input().split())
l = []
for i in range(m):
    a=(list(map(int,input().split())))
    l.append(a[1:])
b = list(map(int,input().split()))
ans = 0
for i in range(2**n):
    sw = [0 for i in range (m)]
    g = i+0
    for j in range(n):
        if g &1 == True:
            for k in range(m):
                if j+1 in l[k]:
                    sw[k]+=1
        g = g>>1
    cnt = 0
    for j in range(m):
        if sw[j]%2==b[j]:
            cnt+=1
    if cnt==m:
        ans+=1
print(ans)

Solution (Python):
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
  onswichi = [False] * n
  onlight = [0] * m
  for j in range(n):
    if (i >> j) & 1:
      onswichi[j] = True
  for k in range(m):
    cnt = 0
    for f in ks[k][1:]:
      if onswichi[f-1]:
        cnt += 1
    if cnt % 2 == p[k]:
      onlight[k] = 1
  if sum(onlight) == m:
    ans += 1
print(ans)

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

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



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

ans=0

for i in range(2**N):
    sw=[0 for i in range(M)]
    I=i+0
    for j in range(N):
        if I&1==True:
            for k in range(M):
                if j+1 in L[k]:
                    sw[k]+=1
        I=I>>1
    
    cnt=0
    for j in range(M):
        if sw[j]%2==S[j]:
            cnt+=1
    if cnt==M:
        ans+=1
print(ans)

Solution (Python):
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n, m = map(int, input().split())
    S = []
    for i in range(m):
        k, *s = map(int, input().split())
        s = [i-1 for i in s]
        S.append(s)
    p = list(map(int, input().split()))
    ans = 0
    for i in range(2**n):
        check = [False]*m
        for j in range(m):
            s = S[j]
            cnt = 0
            for idx in s:
                if (i>>idx)&1:
                    cnt += 1
            if cnt%2 == p[j]:
                check[j] = True
        if not False in check:
            ans += 1
    print(ans)

        

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product
from copy import deepcopy

n, m = map(int, input().split())
k = []
s = []
for j in range(m):
    a = list(map(int, input().split()))
    k.append(a[0])
    s.append(deepcopy(a[1:]))
p = list(map(int, input().split()))

ans = 0
for x in product([0,1], repeat=n):
    c = True
    for i in range(m):
        count = 0
        for j in range(k[i]):
            if x[s[i][j]-1] == 1:
                count += 1
        if count % 2 != p[i]:
            c = False
            break
    if c:
        ans += 1
print(ans)

Solution (Python):
N,M = map(int, input().split())
S = [[]for i in range(M)]
for i in range(M):
    k_s = list(map(int, input().split()))
    for j in range(len(k_s)-1):
        S[i].append(k_s[j+1])
p = list(map(int, input().split()))
Answer = 0


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

        switch[j] = a


    flag = True
    for j in range(M):
        Sum = 0
        for k in range(len(S[j])):
            
            Sum += switch[S[j][k]-1]

        if (Sum%2) != p[j]:
            break

        if j == M-1:
            Answer += 1

print(Answer)

Solution (Python):
n,m=map(int,input().split())
denkyu_switch=[]
res=0
for i in range(m):
    denkyu_switch+=[list(map(int, input().split()))[1:]]
p=list(map(int, input().split()))
for i in range(2**n):
    denkyu = [0] * m
    for j in range(n):
        if i>>j & 1:
            for k in range(m):
                if j+1 in denkyu_switch[k]:
                    denkyu[k]+=1
    denkyu2=[i%2 for i in denkyu]
    if p==denkyu2:
        res+=1
print(res)

Solution (Python):
N,M=map(int,input().split())
k_i=[]
S=[]
for i in range(M):
  l = list(map(int,input().split()))
  k_i.append(l[0])
  S.append(l[1:])
P=list(map(int,input().split()))
ans=0
for i in range(2**N):
  flag=1
  for j in range(M):
    res=0
    for k,x in enumerate(bin(i)[2:][::-1]):
      if x=="1" and k+1 in S[j]:
        res+=1
    if res%2 != P[j] :
      flag=0
      break
    
  if flag:
    ans+=1
print(ans)

Solution (Python):
N,M=map(int,input().split())
ls=[]
cnt,cnt2,ans=0,0,0
for i in range(M):
    ls1=list(map(int,input().split()))
    ls.append(list(ls1))
    ls1.clear()
lsp = list(map(int,input().split()))


for i in range(2**N):
    flg = True
    for j in range(M):
        cnt = 0
        for k in range(1,len(ls[j])):
            if i >> ls[j][k]-1 & 1:
                cnt += 1
        if cnt%2 != lsp[j]:
            flg = False
    if flg:
        ans += 1
print(ans)

Solution (Python):
import numpy as np
N,M=map(int,input().split())
ary_list = []
for i in range(M):
    S = list(map(int,input().split()))
    S.pop(0)
    ary_list.append(S)
P_list = list(map(int,input().split()))
check = True
count = 0
swith = np.array([False]*N)
for i in range(2**N):
    for j in range(N):
        if ((i>>j)&1):
            swith[j] = True
        else:
            swith[j] = False
    for k,p in zip(ary_list,P_list):
        if(list(swith[np.array(k)-1]).count(True)%2!=p):
            check = False
    if(check):
        count+=1
    check=True
print(count)

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

ans = 0

for x in range(2**N):                                                                             
    ok = True                                                                                                          
    for si in range(M):                                                                           
        cnt = 0
        for s in S[si]:                                                                           
            if x & (1 << (s - 1)):                                                                                     
                cnt += 1
        if cnt % 2 != P[si]:                                                                                           
            ok = False                                                                            
            break
    if ok:
        ans += 1
print(ans)

Solution (Python):
import sys
import math
n,m=map(int,input().split())
k=[]
for i in range(m):
    s=list(map(int,input().split()))
    s = list(map( lambda x:x-1,s))
    k.append(s[1:])
p=list(map(int,input().split()))

ans=0

for bit in range(1<<n):
    cnt_swit=[0]*m
    for i in range(n):
        if bit>>i & 1:
            for j in range(m):
                if i in k[j]:
                    cnt_swit[j]+=1
    cnt_swit = list(map( lambda x:x%2,cnt_swit))
    tmp=0
    for pi,cnt in zip(p,cnt_swit):
        if pi==cnt:
            tmp+=1
    if tmp==m:
        ans+=1
print(ans)

Solution (Python):
n, m = map(int, input().split())
lamp_list = [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):
    on_lamp = 0 
    
    for j in range(m):
        on_sw = 0 
        for k in range(n):
            
            if (i >> k) & 1 and k in lamp_list[j]:
                on_sw += 1
        if on_sw%2 == p[j]:
            on_lamp += 1
    if on_lamp == m:
        ans += 1
print(ans)

Solution (Python):
n,m=map(int,input().split())
s=[]
for _ in range(m):
  k,*b=map(int,input().split())
  s.append(b)
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
  tr=bin(i)[2:].zfill(n)
  light=0
  for j in range(m):
    sw=0
    for l in s[j]:
      if tr[l-1]=='1':
        sw+=1
    if sw%2==p[j]:
      light+=1
  if light==m:
    ans+=1
print(ans)

Solution (Python):
from itertools import product

N, M = map(int, input().split())
connected = []  
for _ in range(M):
    
    connected.append(list(map(int, input().split())))
mod = list(map(int, input().split()))
ans = 0

for is_on_li in product([False, True], repeat=N):
    is_ok = True
    for light_idx in range(M):
        on_cnt = 0
        for i in range(1, len(connected[light_idx])):
            sw_idx = connected[light_idx][i] - 1
            if is_on_li[sw_idx]:
                on_cnt += 1
        if on_cnt % 2 != mod[light_idx]:
            is_ok = False
    if is_ok:
        ans += 1
print(ans)

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

switch = []


for _ in range(M):
    s = input().split()
    switch.append(s)
p = input().split()



ans = 0
for i in range(1<<N):
    s = []
    for j in range(N):
        if (i>>j)&1 == 1:
            s.append(1)
        else:
            s.append(0)
    
    
    cnt = 0
    for k in range(M):
        
        a = 0
        for l in range(int(switch[k][0])):
            a += s[int(switch[k][l+1])-1]
        
        
        
        if a % 2 == int(p[k]):
            cnt += 1
        
    if cnt == M:
        ans += 1
            
print(ans)

Solution (Python):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

n,m = LI()
bulbs = []
for _ in range(m):
    b = LI()
    bulbs.append(b[1:])
p = LI()
ans = 0


for switch in range(1 << n):
    check = [0]*m
    for i, bulb in enumerate(bulbs):
        cnt = 0
        for b in bulb:
            if (switch>>(b-1))&1:
                cnt+=1
        if cnt % 2 == p[i]:
            check[i] = True
        else:
            check[i] = False
    if all(check):
        ans += 1
print(ans)

Solution (Python):
from itertools import product
N,M = map(int,input().split())
cc = []
for i in range(M):
  ll = list(map(int,input().split()))
  cc.append(ll)
p = list(map(int,input().split()))
count = 0
for i in product([0,1],repeat = N):
  bulb = []
  for j in range(M):
    on = 0
    for k in range(cc[j][0]):
      if i[cc[j][k+1]-1] == 1:
        on += 1
    if on % 2 == p[j]:
      bulb.append(1)
  if sum(bulb) == 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 i in range(2**n):
    x=format(i,'010b')
    
    flg=1
    for j in range(m):
        temp=0
        for k in range(1,s[j][0]+1):
            temp+=int(x[-s[j][k]])
        if temp % 2 != p[j]:
            flg=0
            break
    if flg:
        ans+=1


print(ans)

Solution (Python):
from itertools import product

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()))

count = 0

for i in product([0,1], repeat=n):
    switch = []
    for j in range(m):
        on = 0
        for l in range(k[j][0]):
            if i[k[j][l+1]-1] == 1:
                on += 1
        if on % 2 == p[j]:
            switch.append(1)
    if sum(switch) == m:
        count += 1

print(count)

Solution (Python):
import itertools

n, m = map(int, input().split())
k = []
s = []
for _ in range(m):
    words = list(map(int, input().split()))
    k.append(words[0])
    s.append(words[1:])
p = tuple(map(int, input().split()))

sw_stat_list = list(itertools.product([0, 1], repeat=n))
for i in range(m):
    sw_stat_list_next = []
    for sw_stat in sw_stat_list:
        sw_on_num = sum([sw_stat[sw - 1] for sw in s[i]])
        if sw_on_num % 2 == p[i]:
            sw_stat_list_next.append(sw_stat)
    sw_stat_list = sw_stat_list_next

print(len(sw_stat_list))

Solution (Python):
def main():
    ans = 0
    n,m = map(int,input().split())
    s = []
    for i in range(m):
        tmp = [int(i) for i in input().split()]
        s.append(tmp)
    p = [int(i) for i in input().split()]
    for i in range(2**n):
        light = [0 for k in range(m)]
        for j in range(n):
            if (i>>j)&1 == 1:
                for x in range(m):
                    if j+1 in s[x][1:s[x][0]+1]:
                        light[x] += 1
        Flag = True
        for x in range(m):
            """
            if light[x]==0:
                Flag = False
                """
            if light[x]%2!=p[x]:
                Flag = False
        if Flag:
            ans += 1

    print(ans)

main()

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

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


count = 0
for i in range(2 ** N):
  on = [0] * N
  ans = [0] * M
  ans2 = [1] * M
  for j in range(N):
    if ((i >> j) & 1):
      on[j] = 1
  
  for k in range(M):
    now = 0
    for l in K[k]:
      if on[l - 1] == 1:
        now += 1
    if now % 2 == P[k]:
      ans[k] = 1
  
  if ans == ans2:
    count += 1

print(count)

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

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

import itertools 
data = list(itertools.product(range(2), repeat = n))
ans = 0

for d in data:
    light = 0
    for i in range(m):
        s_cnt = 0
        for j in range(k[i]):
            s_no = s[i][j]-1
            if d[s_no]==1: s_cnt+=1
        if s_cnt%2==p[i]:
            light += 1
    if light == m:
        ans += 1

print(ans)

Solution (Python):
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() 
ni = lambda: int(readline().rstrip()) 
nm = lambda: map(int, readline().split()) 
nl = lambda: list(map(int, readline().split())) 

N, M = nm()
K = []
S = []
for _ in range(M):
    tmp = nl()
    K.append(tmp[0])
    S.append(tmp[1:])
P = nl()
ans = 0
for state in range(1 << N):
    isOn = [True if (state >> i) % 2 == 1 else False for i in range(N)]
    isOK = True
    for i, li in enumerate(S):
        sum = 0
        for s in li:
            if isOn[s-1]:
                sum += 1
        if not sum % 2 == P[i]:
            isOK = False
            break
    if isOK:
        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()))[1:])
p = list(map(int,input().split()))
cnt = 0
for i in range(2**n):
    switch = [0]*n
    
    f = True
    for k in range(n):
        if(i>>k)&1:
            switch[k] = 1
    
    for j in range(m):
        sum = 0
        for k in range(len(s[j])):
            if switch[s[j][k]-1] == 1:
                sum += 1
        if sum % 2 != p[j]:
            f = False
    if f:
        cnt += 1
        



print(cnt)

Solution (Python):
N,M = (int(x) for x in input().split())
Con = [[] for I in range(0,M)]
for T in range(0,M): Con[T] = [int(x) for x in input().split()][1:]
Lights = [int(x) for x in input().split()]
Count = 0
for TT in range(0,pow(2,N)):
    Flag = True
    Switch = list(int(x) for x in list(('{:0'+str(N)+'b}').format(TT,'b')))
    for T in range(0,M):
        if sum(Switch[x-1] for x in Con[T])%2!=Lights[T]:
            Flag = False
            break
    if Flag: Count += 1
print(Count)

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

for _ in range(M):
    f = list(map(int, input().split()))
    k = f[0]
    s = f[1:]
    K.append(k)
    S.append([c-1 for c in s])

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

search = 1<<N
ans = 0
for i in range(search):
    b = [0]*N
    for j in range(N):
        if i & 1<<j:
            b[j] = 1
        else:
            b[j] = 0

    ok = True
    for q in range(M):
        n = 0
        for s in S[q]:
            n += b[s]
    
        if n%2 != P[q]:
            ok = False
            break
    
    if ok:
        ans += 1

print(ans)

Solution (Python):
n,m=map(int,input().split())
k=[list(map(int,input().split())) for _ in range(m)]
k2=[]
for v in k:
  a=[2**(v[i]-1) for i in range(1,v[0]+1)]
  k2.append(sum(a))
  
p=list(map(int,input().split()))

sm=0
for i in range(2**n):
  c=1
  for j in range(m):
    b=bin(k2[j] &i)
    
    d=b.count("1")
    if d%2!=p[j]:
      c=0
  if c==1:
    sm+=1

print(sm)

Solution (Python):
n, m = map(int,input().split())
K = [0]*m
S = [[] for _ in range(m)]    

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

ans = 0
for i in range(2**n):
    s = list(map(int, list(bin(i)[2:].zfill(n))))
    for j in range(m):
        p = [_s for k,_s in enumerate(s) if k+1 in S[j]]
        if sum(p)%2!=P[j]:
            break
        else:
            if j==m-1:
                ans += 1
print(ans)