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())
all_switches = [[] for _ in range(N)]

for i in range(M):
    input_text = list(map(int, input().split()))
    switches = input_text[1:]
    for switch in switches:
        all_switches[switch - 1].append(i)



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

count = 0
for i in range(1 << N):
    lightup_counts = [0 for _ in range(M)]
    for j in range(N):
        
        if i >> j & 1:
            for light in all_switches[j]:
                lightup_counts[light] += 1
    
    compute_success = True
    for j, term in enumerate(lightup_terms):
        if lightup_counts[j] % 2 != term:
            compute_success = False
            break
    if compute_success:
        count += 1
print(count)

Solution (Python):
n,m = [int(i) for i in input().split()]
k = []
for i in range(m):
  array = [int(i) for i in input().split()]
  k.append(array)

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

for i in range(2**n):
  r = format(i,'b')
  r = r.zfill(n)[::-1]
  for j in range(m):
    for l in range(1,k[j][0]+1):
      chk += int(r[k[j][l]-1])
    if chk % 2 != p[j]:
      chk = 0
      break
    if j == m-1:
      
      ans += 1
    chk = 0
  
print(ans)

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

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

res = 0
for i in range(1<<n):
    on = [0 for _ in range(n)]
    
    for j in range(n):
        if(i & (1<<j)): on[j] = 1
    
    all_on = True
    for j in range(m):
        
        on_num = 0
        for s in ks[j][1: ]:
            if(on[s-1]): on_num += 1

        if(on_num%2 != p[j]):
            all_on = False
            break

    if(all_on): res += 1

print(res)

Solution (Python):
N,M = map(int,input().split())
ld = [[]]
for i in range(M):
  ld.append(list(map(int,input().split())))
lp = [0]+list(map(int,input().split()))

ans = 0
for i in range(2**N):
  bs = format(i,"0{}b".format(N+1))
  det = 1
  for j in range(1,M+1):
    c = 0
    for k in ld[j][1:ld[j][0]+1]:
      if int(bs[k]) == 1:
        c += 1
    if c%2 != lp[j]:
      det = 0
      break 
  if det == 1:
    ans += 1
print(ans)

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

def lighton(n,s,p):
    on_num = 0
    for si in s:
        
        if n>>(si-1)&1 == 1:
            on_num +=1
        else:
            continue
    if on_num%2 == p:
        
        return True
    else:
        
        return False
ans = 0
for i in range(2**N):
    dummy = 0
    
    for j in range(len(group_of_s)):
        
        if lighton(i,group_of_s[j],p[j])==True:
            
            dummy += 1
        else:
            break
    if dummy == M:
        ans += 1

print(ans)

Solution (Python):
import itertools
n,m = map(int,input().split())
def light(bit,value,tf):
    count = 0
    bit_v = []
    for i in range(len(bit)):
        if bit[i]:
            bit_v.append(i+1)
    for i in range(len(tf)):
        if tf[i] in bit_v:
            count += 1
    if count%2 == value:
        return True
    else:
        return False
k = [0 for _ in range(m)]
s = [0 for _ in range(m)]
for i in range(m):
    s[i] = map(int,input().split())
for i in range(m):
    s[i] = list(s[i])
    s[i] = s[i][1:]
p = list(map(int,input().split()))
bit = list(map(lambda x:list(x),itertools.product([0,1],repeat=n)))
ans = 0
for i in range(len(bit)):
    c = 0
    for j in range(m):
        if light(bit[i],p[j],s[j]):
            c += 1
    if c == m:
        ans += 1
print(ans)

Solution (Python):
N, M = map(int, input().split())
s = []
k = []
for _ in range(M):
    x = list(map(int, input().split()))
    k.append(x.pop(0))
    s.append(x)
p = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    Switches = [0]*N
    for j in range(N):
        if (i >> j) & 1:
            Switches[j] = 1
    
    Lamps = [0]*M
    for j in range(M):
        for l in range(k[j]):
            if Switches[s[j][l] - 1] == 1:
                Lamps[j] += 1

    
    ok = True
    for j in range(M):
        
        
        
        if Lamps[j] % 2 != p[j]:
            ok = False
            break

    if ok:
        ans += 1
    
print(ans)

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

num_patterns = 2 ** n
ans = 0
for pattern in range(num_patterns):
    switches = []
    for j in range(n):
        if ((pattern >> j) & 1):
            switches.append(1)
        else:
            switches.append(0)
    
    count = 0
    for i, lamp in enumerate(lamp_ls):
        
        s_for_lamp = []
        for s in lamp[1:]:
            if switches[s-1] == 1:
                s_for_lamp.append(1)
            else:
                s_for_lamp.append(0)
        if s_for_lamp.count(1) % 2 == p_ls[i]:
            count += 1
    if count == m:
        ans += 1

print(ans)

Solution (Python):
n,m=map(int,input().split())
k,s=[-1]*m,[-1]*m
for i in range(m):
  k[i],*s[i]=map(int,input().split())
  s[i]=[1 if j in s[i] else 0 for j in range(1,n+1)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
  l=list(map(int,format(i,'0%db'%n)))
  c=0
  for j in range(m):
    if sum([min(t) for t in zip(l,s[j])])%2==p[j]:
      c+=1
  if c==m:
    ans+=1
print(ans)

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

ans = 0

for i in range(2**N):
    s = str(bin(i))
    condition = s[2:].zfill(N)

    
    
    
    
    
    
    
    
    



    for j in range(M):
        cnt = 0
        for k in ks[j][1:]:
            if condition[k-1] == "1":
                cnt += 1
        if cnt%2 != p[j]:
            break
    else:
        ans += 1

print(ans)

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


cnt = 0
for bits in itertools.product([0, 1], repeat=n):
    
    lights = [0] * m

    
    
    for i in range(n):
        if bits[i] == 1: 
            sw = i + 1 
            for j in range(len(ks)): 
                if sw in ks[j][1:]: 
                    lights[j] += 1 

    
    
    
        
    m_lights = [l%2 for l in lights]
    if m_lights == p:
        cnt += 1

print(cnt)

Solution (Python):
import itertools
from pprint import pprint
n,m = map(int,input().split())
klist = []
slist = []
for i in range(m):
    s = list(map(int,input().split()))
    klist.append(s[0])
    slist.append(s[1:])
plist = list(map(int,input().split()))
kklist = klist[:]

status = [(0, 1) for _ in range(n)]
system_status = list(itertools.product(*status))
ans = 0
for i in range(len(system_status)):
    for j in range(n):
        for k in range(m):
            if system_status[i][j] == 1 and j+1 in slist[k]:
                klist[k] -= 1
    for l in range(m):
        if (kklist[l] - klist[l]) % 2 != plist[l]:
            klist = kklist[:]
            break
    else:
        ans += 1
        klist = kklist[:]
print(ans)

Solution (Python):
N, M = map(int, input().split())
a=[list(map(int,input().split())) for i in range(M)]
p=list(map(int,input().split()))
ans=0
for i in range(2**N):
	b=list(str(bin(i)))
	c=b.pop(0)
	c=b.pop(0)
	b=['0']*(N-len(b))+b
	b=list(map(int,b))
	Light=[]
	for i in range(M):
		light=0
		for j in range(1,N+1):
			if j in a[i][1:]:
				light+=b[j-1]
		if light%2==p[i]:
			Light+=[1]
	if Light==[1]*M:
		ans+=1
print(ans)

Solution (Python):
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    switch_pattern = bin(i)[2:].zfill(N)
    for j in range(M):
        switch_on = 0
        for k in ks[j][1:]:
            if switch_pattern[k-1] == "1":
                switch_on += 1
        if switch_on%2 != p[j]:
            break
    else:
        ans += 1
print (ans)

Solution (Python):
def my_code():
    n,m = map(int, input().split())
    G = [[] for _ in range(m)]
    for i in range(m):
        G[i] = list(map(int, input().split()))[1:]
    p = list(map(int, input().split()))
    

    res = 0
    for i in range(pow(2,n)):
        light = [0]*m
        switch = list(map(int, format(i, '0'+str(n)+'b')))
        for j in range(m):
            for connect in G[j]:
                light[j] += switch[connect - 1]
            light[j] += p[j]
            light[j] %= 2
        if sum(light)==0:
            res += 1
            
    print(res)

my_code()

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

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

ps=LI()
ans=0
for i in range(2**n):
    count=0
    for j in range(m):
        sm=0
        for k in range(1,len(sws[j])):
            sm+= (i>>(sws[j][k]-1)) %2
        
        if sm%2==ps[j]:
            count+=1
    if count==m:
        ans+=1
print(ans)

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

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

ps=LI()
ans=0
for i in range(2**n):
    count=0
    for j in range(m):
        sm=0
        for k in range(1,len(sws[j])):
            sm+= (i>>(sws[j][k]-1)) %2
        
        if sm%2==ps[j]:
            count+=1
    if count==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):
    flag = [False] * M
    for k in range(M):
        cnt = 0
        for j in range(N):
            if ((i >> j) & 1): 
                if j + 1 in ks[k][1:]:
                    cnt += 1
        if cnt % 2 == p[k]:
            flag[k] = True
    if all(flag):
        ans += 1       
print(ans)

Solution (Python):
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
ilm = lambda n: [int(sys.stdin.buffer.readline().split()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    S = [il()[1:] for _ in range(M)]
    P = il()

    ans = 0
    for i in range(1 << N):
        for m in range(M):
            cnt = 0
            for j in range(N):
                if i >> j & 1 and j+1 in S[m]:
                    cnt += 1
            if cnt % 2 != P[m]:
                break
        else:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

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

def count_on_switch(switch_array: list, on: set):
    return sum([int(sw in on) for sw in switch_array])

ans = 0

for i in range(2**N):
    on = set()
    for j in range(N):
        if ((i >> j) & 1):
             on.add(j+1)
    temp = 0
    for _ in range(M):
        cou_on = count_on_switch(slist[_], on)
        
        if cou_on % 2 != plist[_]:
            break
    else:
        ans += 1
print(ans)

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

for i in range(2**n):
    flg = True
    for j in range(m):
        count = 0
        for k in range(1,x[j][0]+1):
            
            if (i>>(x[j][k]-1)&1):
                count += 1
        if count%2 == p[j]:
            continue
        else:
            flg=False
            break
    if flg:
        ans += 1

print(ans)

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

for bit in range(1<<n):
    on = []
    ok = True 
    for i in range(n):
        if (bit & (1<<i)):
            on.append(i+1)
    for i in range(m):
        p = P[i]
        c = 0
        for s in S[i]:
            if s in on: c+=1
        if c%2!=p: ok=False
    if ok:ans+=1
print(ans)

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

for i in range(2**n):
    u = 1
    e = str(format(i,'010b'))
    for j in range(m):
        if u == 0:
            break
        kar = 0
        for k in range(x[j][0]):
            if e[10-x[j][k+1]] == "1":
                kar += 1
        if kar % 2 != p[j]:
            u = 0
            break
    if u == 1:
        ans += 1
        
print(ans)

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

if __name__ == '__main__':
    main()

Solution (Python):

import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
KS = [lr() for _ in range(M)]
P = lr()
answer = 0
for pattern in itertools.product([0, 1], repeat=N):
    bl = True
    for i in range(M):
        if sum(pattern[x-1] for x in KS[i][1:]) % 2 != P[i]:
            bl = False
            break
    if bl:
        answer += 1

print(answer)

Solution (Python):



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

switch2bulb = [[] for _ in [0]*N]

for i, ss in enumerate(S):
    for s in ss:
        switch2bulb[s-1].append(i)

ans = 0
for bit in range(2**N):
    sw = [p ^ 1 for p in P]
    for i in range(N):
        if bit >> i & 1:
            for m in switch2bulb[i]:
                sw[m] ^= 1
    if all(sw):
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
nums = [i+1 for i in range(n)]
cnt = 0
ss = [set(map(int, input().split()[1:])) for i in range(m)]
ps = list(map(int, input().split()))
for i in range(2**n):
    flag = True
    s = bin(i)[2:].zfill(n)
    on_set = set(nums[i] for i in range(n) if int(s[i]))
    for j in range(m):
        if len(on_set & ss[j])%2 == ps[j]:
            continue
        else:
            flag = False
            break
    if flag:
        cnt += 1
print(cnt)

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
lights = [lr() for _ in range(M)]
P = lr()
answer = 0
for bit in range(2 ** N):
    bl = True
    for i in range(M):
        p = P[i]
        result = 0
        for s in lights[i][1:]:
            s -= 1
            if (bit >> s) & 1:
                result += 1
        if result % 2 != p:
            bl = False
    if bl:
        answer += 1
print(answer)

Solution (Python):
import itertools

N, M = [int(i) for i in input().split(' ')]

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

P = list(map(int,input().split(' ')))
count = 0

for onoff in itertools.product([0,1],repeat=N):
    on_count = 0
    on_count = sum(sum(onoff[i-1] for i in s) % 2 == p for s,p in zip(switch,P))
    if on_count == M:
        count += 1

print(count)

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

ans = 0

for i in range(2 ** N):
  bin_i = bin(i)[2:].zfill(N)
  
  m = 0
  for j in range(M):
    x = 0
    for l in range(1,S[j][0] + 1):
      if bin_i[S[j][l] - 1] == "1":
        x += 1
        
    if x % 2 != P[j]:
      m = 1
      
    
  if m == 0:
    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()))
ans = 0
for i in range(2**N):
  switch_pattern = bin(i)[2:].zfill(N)
  succes = 1
  for j in range(M):
    switch_on = 0
    for k in KS[j]:
      if switch_pattern[k-1] == '1':
        switch_on += 1
    if switch_on % 2 != P[j]:
      succes = 0
      break
  if succes == 1:
      ans += 1
print(ans)

Solution (Python):
mod = 10 ** 9 + 7
mod2 = 2**61+1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

def iip(listed=True):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iip_ord():
    return [ord(i) - ord("a") for i in input()]


def main():
    ans = solve()
    if ans is not None:
        print(ans)

def solve():
    N, M = iip(False)
    

    A = []
    P = []
    for i in range(M):
        A.append(iip()[1:])

    for i, p in enumerate(iip()):
        P.append(p)

    pat = 0
    for i in range(2**N):
        for denkyuu in range(M):
            ns = 0
            sn = i
            for s in range(N):
                if s+1 in A[denkyuu]:
                    ns += sn % 2
                    
                sn //= 2
            if ns % 2 != P[denkyuu]:
                pat -=1
                
                break

        
        pat += 1

    print(pat)

    
    








def YesNo(s):
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):
    for i in s:
        print(i)

def split_print_space(s):
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)

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

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

bit = (1 << N)
cnt = 0



for i in range(bit):
    switch = [0] * (N+1)
    for j in range(N):
        isOn = (i >> j) & 1
        switch[j + 1] = isOn

    

    ok = True
    for k in range(M):
        t = KS[k][1:]
        c = 0
        for l in t:
            c += switch[l]

        

        if c % 2 != P[k]:
            ok = False
            break

    if ok:
        cnt += 1

print(cnt)

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

on = list(map(int,input().split()))
  
n = N
anscnt = 0
arr = [0 for i in range(N+1)]

for i in range(2 ** n):
  arr = [0 for i in range(N+1)]
  for j in range(n):  
    if ((i >> j) & 1):  
      arr[j+1] = 1
  ok = 1

  for k in range(M):
    a = List[k][0]
    cnt = 0
    for l in range(1,a+1):
      if arr[ List[k][l] ] == 1:
        cnt += 1
    if cnt%2 == on[k]:
      continue
    else:
      ok = 0
  if ok == 1:
    anscnt += 1
      
print(int(anscnt))

Solution (Python):
n,m = map(int,input().split())
base = [list(map(int,input().split())) for i in range(m)]
judge = list(map(int,input().split()))
ans = 0

for i in range(2**n):
  count = [0] * m
  sign = 0
  for j in range(n):
    if (i >> j) & 1:
      for k in range(m):
        for l in range(base[k][0]):
          if (j+1) == base[k][l+1]:
            count[k] = count[k] + 1
  
  for j in range(m):
    if (count[j]%2 != judge[j]):
      sign = 1
      break

  if sign == 0:
    ans = ans + 1
  
print(ans)

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

for i in range(2**N):
    for j in range(M):
        tmp = 0
        for s in switch[j][1:]:
            if i & 2**(s-1) == 2**(s-1):
                tmp = 1-tmp
        if tmp != p[j]:
            break
    else:
        ans += 1

print(ans)

Solution (Python):
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

n, m = load_list()
S = []
for _ in range(m):
    s = load_list()
    del s[0]
    S.append(s)
p = load_list()

def s2bit(s):
    bit = 0
    for e in s:
        bit |= 2**(e-1)
    return bit

cnt = 0
for bit in range(0, 2**n):
    flag = True
    for i in range(m):
        if not bin(s2bit(S[i]) & bit).count("1") % 2 == p[i]:
            flag = False
            break
    if flag:
        cnt += 1


print(cnt)

Solution (Python):
import sys

readline = sys.stdin.readline

def main():
    N, M = map(int, readline().split())

    S = []
    for i in range(M):
        k, *tmp = [int(i) for i in readline().split()]
        S.append(tmp)
    
    p = list(map(int, readline().split()))

    
    ans = 0
    for i in range(2**N):
        select = []
        for j in range(N):
            if (i>>j) & 1:
                select.append(j+1)
        
        for m in range(M):
            flag = 1
            if sum([1 for x in S[m] if x in select])%2 != p[m]:
                flag = 0
                break
        if flag  == 1:
            ans += 1
        
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)


n, m = map(int, input().split())
k = [0] * m
s = []
for i in range(m):
    a = list(map(int, input().split()))    
    k[i] = a[0]
    s.append(a[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
    bit = format(i, "01024b")[::-1]
    on = True
    for j in range(m):
        cnt = 0
        for k in s[j]:
            if bit[k - 1] == "1":
                cnt += 1
        if cnt % 2 != p[j]:
            on = False
            break
    if on:
        ans += 1

print(ans)

Solution (Python):

import sys
input = sys.stdin.readline










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

ans = 0

i = 0
while i < 2**N:
    bit = bin(i)[2:].zfill(N)
    check = True
    for j in range(M):
        swlist = KS[j][1:]
        cnt = 0
        for sw in swlist:
            if bit[sw-1] == "1":
                cnt += 1
        if cnt%2 != P[j]:
            check = False
            break
    if check:
        ans += 1
    i += 1

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    k = [None] * M
    s = [None] * M
    for i in range(M):
        line = tuple(map(int, input().split()))
        k[i], s[i] = line[0], line[1:]
    p = tuple(map(int, input().split()))

    ans = 0
    for bit in range(2 ** N):
        light_all = True
        
        sw = [None] * N
        for i in range(N):
            if bit & (1 << i):
                sw[i] = True
            else:
                sw[i] = False
        for i in range(M):
            n_on = 0
            for j in s[i]:
                n_on += sw[j - 1]
            if n_on % 2 == p[i]:
                pass
            else:
                light_all = False
        ans += light_all

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n, m = map(int, input().split())
ss = [set(list(map(int, input().split()))[1:]) for _ in range(m)]
ps = list(map(int, input().split()))

ans = 0
for bits in range(2 ** n):
    ons = set()
    for shift in range(n):
        if (bits >> shift) & 1 > 0:
            ons.add(shift + 1)

    ok = True
    for i in range(m):
        c = [s in ons for s in ss[i]].count(True)
        if c % 2 != ps[i]:
            ok = False
            break
    if ok:
        ans += 1

print(ans)

Solution (Python):
N,M = (int(x) for x in input().split())
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split())) 
switchstate = [False for i in range(1, N+1)]
count = 0
for i in range(2 ** (N)):
    broke = False
    for j in range(N):
        if i >> j & 1:
            switchstate[j] = True
        else:
            switchstate[j] = False
    for j in range(M):
        temp = []
        for k in range(len(ks[j])-1):
            temp.append(switchstate[ks[j][k+1]-1])
        if temp.count(True) % 2 != p[j]:
            broke = True
            break
    if broke == False:
        count += 1
print(count)

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


def check(bit):
    f = True
    for i in range(M):
        cnt = 0
        for si in range(len(S[i])):
            if si == 0:
                pass
            else:
                cnt += int(bit[S[i][si]-1])
        if cnt%2 != P[i]:
            f = False
    return f    
    

ans = 0
for i in range(2**N):
    bit = bin(i)[2:].zfill(N)
    if check(bit):
        ans += 1

print(ans)