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())
switches=[list(map(int, input().split())) for _ in range(M)]
p=list(map(int, input().split()))
ans=0
for i in range(2**N):
  on=[0 for _ in range(N)]
  tmp=i
  for j in range(N):
    if tmp%2==1:
      on[j]=1
    tmp=tmp//2
  flag=True
  for j in range(M):
    switch=switches[j]
    cnt=0
    for k in range(1, switch[0]+1):
      cnt+=on[switch[k]-1]
    if cnt%2!=p[j]:
      flag=False
      break
  if flag:
    ans+=1
print(ans)

Solution (Python):
num_of_switch,num_of_denkyu = map(int,input().split())

denkyu_switch_connection = []
for denkyu in range(num_of_denkyu):
    denkyu_switch_connection.append(list(map(lambda x:int(x)-1,input().split())))
    del denkyu_switch_connection[denkyu][0]

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


ans=0
for pattern in range(2**num_of_switch):
    denkyu_True_or_False=[False for _ in range(num_of_denkyu)]
    switch_on_off = list(map(int,list(str(bin(pattern)).replace("0b","").zfill(num_of_switch))))
    
    for i in range(num_of_denkyu):
        count=0
        for j in range(len(denkyu_switch_connection[i])):
            if switch_on_off[denkyu_switch_connection[i][j]]==1:
                count += 1
        
        if count%2 == surplus[i]:
            denkyu_True_or_False[i]=True
        else:break

    if False not in denkyu_True_or_False:
        ans+=1
print(ans)

Solution (Python):
num_of_switch,num_of_denkyu = map(int,input().split())
denkyu_switch = []
for denkyu in range(num_of_denkyu):
    denkyu_switch.append(list(map(lambda x:int(x)-1,input().split())))
    del denkyu_switch[denkyu][0]
surplus = list(map(int,input().split()))


ans=0
for i in range(2**num_of_switch):
    denkyu_on_off=[False for _ in range(num_of_denkyu)]
    switch_on_off = list(map(int,list(str(bin(i)).replace("0b","").zfill(num_of_switch))))


    for denkyu in range(len(denkyu_switch)):
        count=0
        for switch in range(len(denkyu_switch[denkyu])):
            
            if switch_on_off[denkyu_switch[denkyu][switch]]==1:
                count += 1
        
        if count%2 == surplus[denkyu]:
            denkyu_on_off[denkyu]=True
        else:break

    if False not in denkyu_on_off:
        ans+=1
print(ans)

"""
5 3
1 3
2 1 2
1 3
0 0 1
"""

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
baai=2**n

for i in range(baai):
  sta=str(bin(i)[2:].zfill(n))
  
  temp=0
  for t,j in enumerate(k): 
    wa=0
    for x in j[1:]:
      wa+=int(sta[x-1])
    if wa%2==p[t]: 
      
      temp+=1
  if temp==m:
    ans+=1
print(ans)

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

from copy import copy
on_off = []
def search(l, on):
  new_l = copy(l)  
  new_l.append(on)
  if len(new_l) < n:
    search(new_l, 1)
    search(new_l, 0)
  else:
    on_off.append(new_l)
search([], 0)
search([], 1)

ans = 0
for states in on_off:
  for j in range(m):
    s = 0
    for i in range(n):
      if states[i] == 1 and i in lights[j]:
        s += 1
    if s % 2 != p[j]:
      break
  else:
    ans += 1
print(ans)

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

Solution (Python):
N,M=map(int,input().split())
k=[]
for j in range(0,M):
    k.append([int(x) for x in input().split()])
    k[j]=k[j][1:]
p=[int(x) for x in input().split()]
condition=[0]*M
sum_=0
for u in range(0,2**N):
    switch=list(bin(u)[2:].zfill(N))
    for i in range(0,M):
        condition[i]=0
        for j in k[i]:
            condition[i] += int(switch[j-1])
        condition[i] = condition[i] % 2
    
    sum_ += (condition==p)
print(sum_)

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

prod = list(itertools.product([0,1], repeat = N))
cnt = 0
for i in range(len(prod)):
  judge = True
  for j in range(M):
    temp = 0
    for k in range(K[j][0]):
      if prod[i][K[j][k+1]-1] == 1:
        temp += 1
    if temp % 2 != P[j]:
      judge = False
  if judge == True:
    cnt += 1

print(cnt)

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):
  on = bin(i)[2:].zfill(n)
  for s,p in zip(L,P):
    if sum(int(on[sij-1]) for sij in s) % 2 != p:
      break
  else:
    ans += 1
print(ans)

Solution (Python):
K = []
S = []
N,M = map(int,input().split())
for i in range(M):
    tmp = [int(i) for i in input().split()]
    K.append(tmp[0])
    tmp.pop(0)
    S.append(tmp)
P = [int(i) for i in input().split()]
List = []
for i in range(2**N):
    tmp = []
    for j in range(N):
        if ((i>>j) & 1):
            tmp.append('1')
        else:
            tmp.append('0')
    List.append(tmp)

for i in range(M):
    kouho = []
    for j in range(len(List)):
        cnt = 0
        for k in range(len(List[j])):
            if List[j][k] == '1':
                if k+1 in S[i]:
                    cnt += 1
        if cnt % 2 != P[i] and not List[j] in kouho:
            kouho.append(List[j])
    for x in kouho:
        List.remove(x)
print(len(List))

Solution (Python):
N, M = map(int, input().split())
K = []
S = []
ans = 0
for _ in range(M):
    tmp = list(map(int, input().split()))
    k, s = tmp[0], tmp[1:]
    K.append(k)
    S.append(s)
P = [int(p) for p in input().split()]
for i in range(2**N):
    cnt = [0]*M
    f = 0
    for m, s in enumerate(S):
        for j in s:
            if ((i >> (j-1)) & 1):
                cnt[m] += 1
        for m in range(M):
            if cnt[m] % 2 != P[m]:
                f = 0
                break
            f = 1
    if f:
        ans += 1
    
print(ans)

Solution (Python):
import itertools
N,M = map(int,input().split())
B = {}
for i in range(1,M+1):
    row = list(map(int,input().split()))
    row.pop(0)
    B[i] = row
P = list(map(int,input().split()))
P.insert(0,-1)
cnt = 0
for x in itertools.product((0,1),repeat=N):
    ind = 1
    for i in range(1,M+1):
        sw = 0
        for j in B[i]:
            if x[j-1]==1:
                sw += 1
        if sw%2!=P[i]:
            ind = 0
            break
    if ind==1:
        cnt += 1
print(cnt)

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(2 ** N):
    is_ok = True
    for j in range(M):
        bit_sum = 0
        r_bin = list(map(int, reversed(bin(i)[2:].rjust(N, '0'))))
        for s in ks[j][1:]:
            bit_sum += r_bin[s - 1]
        if bit_sum % 2 != p[j]:
            is_ok = False
    if is_ok:
        res += 1

print(res)

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

ans = 0
for patterns in range(2**n):
    ptn = bin(patterns)[2:].rjust(n, '0')
    light = True
    for i in range(m):
        num = 0
        for j in range(len(k[i])):
            num += int(ptn[k[i][j] - 1])
        if ((num+p[i]) % 2 == 1):
            light = False
    if light:
        ans += 1
print(ans)

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


ret = 0
for i in range(2 ** N):
    on = list(map(int, bin(i)[2:]))

    on = ([0] * N + on)[-N:]

    for si, pi in zip(s, p):
        if sum(on[sij] for sij in si) % 2 != pi:
            break
    else:
        ret += 1
print(ret)

Solution (Python):
n, m = map(int, input().split())
switch = [format(i, '010b') for i in range(2**n)]
s = [[int(j) for j in input()[1:].split()] for i in range(m)]
p = [int(i) for i in input().split()]
ans = 0

for sw in switch:
    for pi, si in zip(p, s):
        total = 0
        for x in si:
            total += int(sw[-x])
        if total % 2 != pi:
            break
    else:
        ans += 1
print(ans)

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

ret = 0
for i in range(2 ** N):
    on = list(map(int, bin(i)[2:]))
    on = ([0] * N + on)[-N:]
    for si, pi in zip(s, p):
        if sum(on[sij] for sij in si) % 2 != pi:
            break
    else:
        ret += 1
print(ret)

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()))
count = 0

for _ in range(2 ** n):
    pattern = list(map(int, list(bin(_)[2:].zfill(n))))
    if all(sum(pattern[sw2 - 1] for sw2 in ss ) % 2 == pp for ss, pp in zip(s, p)):
        count += 1
print(count)

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

a = [0 for _ in range(N)]
ans = 0
p = 0


for i in range(M):
    x = plist[i]
    p |= x << i



for i in range(M): 
    k = ks[i][0]
    for j in range(1, k+1): 
        s = ks[i][j] - 1 
        a[s] |= 1 << i 


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

print(ans)

Solution (Python):
N,M = map(int, input().split())
S = []
for _ in range(M):
  s_list = ['0' for _ in range(N)]
  for s in list(map(int, input().split()))[1:]:s_list[s-1] = '1'
  S.append(int(''.join(s_list),2))

P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
  flag = True
  for idx, s in enumerate(S):
    if bin(i&s)[2:].count('1')%2 != P[idx]:
      flag = False
      break
  if flag is True: ans += 1
print(ans)

Solution (Python):

N,M=map(int,input().split())
S =[[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):
  x=bin(i)[2:]
  x="0"*(N-len(x))+x
  for j in range(M):
    tmp=0
    for k in range(1,S[j][0]+1):
      tmp+=int(x[N-S[j][k]:N-S[j][k]+1])
    if tmp%2 != p[j]:
      break
    if j==M-1:
      ans+=1
    
print(ans)

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

n_pattern = 2 ** n
count = 0
for i in range(n_pattern):
    for j in range(m):
        current = 0
        for k in range(ks[j][0]):
            current += 2 ** (ks[j][k + 1] - 1)
        mod = bin(i & int(current)).count('1') % 2
        if mod != p[j]:
            break
        if j == m - 1:
            count += 1
print(count)

Solution (Python):
while True:
    try:
        N, M = map(int, input().split())
        
        K = []
        S = []
        for _ in range(M):
            k, *s = map(int, input().split())
            K.append(k)
            S.append(list(map(lambda x:x-1, s)))
        
        p = list(map(int, input().split()))
        ans = 0
        
        for i in range(1<<N):
            flag = True
            for j in range(M):
                cnt = 0
                for k in S[j]:
                    if (i >> k) & 1:
                        cnt += 1
                if cnt%2 != p[j]:
                    flag = False
                    break
            if flag:
                ans += 1
                
        print(ans)
    except:
        break

Solution (Python):

import itertools

def solve():
    N, M = list(map(int, input().split()))
    Ks, Ss = [], []
    for i in range(M):
        _in = list(map(int, input().split()))
        Ks.append(_in[0])
        Ss.append(_in[1:])
    Ps = list(map(int, input().split()))

    
    switches = itertools.product([0,1], repeat=N)
    ans = 0
    for switch in switches:
        is_ok = True
        for i in range(M):
            on_num = 0
            for s in Ss[i]:
                if switch[s-1] == 1:
                    on_num += 1
            if on_num%2 != Ps[i]:
                is_ok = False
                break
        
        if is_ok:
            ans += 1

    print(ans)
    



if __name__ == "__main__":
    solve()

Solution (Python):
N, M = map(int, input().split())
K, S = [], []
for _ in range(M):
	k, *s = map(int, input().split())
	K.append(k)
	S.append(list(map(lambda x: x-1, s)))
p = list(map(int, input().split()))
res = 0
for i in range(1<<N):
	flag = True
	for j in range(M):
		cnt = 0
		for k in S[j]:
			if (i >> k) & 1:
				cnt += 1
		if cnt%2 != p[j]:
			flag = False
			
	if flag: res += 1
print(res)

Solution (Python):
from itertools import product

n, m = map(int, input().split())
ks = {}
for i in range(m):
    tmp = list(map(int, input().split()[1:]))
    ks[i] = [t-1 for t in tmp]
p = list(map(int, input().split()))

onoffs = []
for onoff in product('01', repeat=n):
    _ = [int(bin) for bin in onoff]
    onoffs.append(_)

res = 0
for i in range(len(onoffs)):
    tmp = 0
    for j in range(m):
        obj = []
        for k in ks[j]:
            obj.append(onoffs[i][k])
        if sum(obj) % 2 == p[j]:
            tmp += 1
    if tmp == m:
        res += 1

print(res)

Solution (Python):
import itertools

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

k = []
s = []


for i in range(m):
    items = [int(item) for item in input().split()]
    k.append(items[0])
    s.append(items[1:])

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

count = 0

for switch in range(2 ** n):
    for l in range(m):
        ons = 0
        for j in s[l]:
            if switch >> (j - 1) & 1:
                ons += 1
        if ons % 2 != p[l]:
            break
    else:
        count += 1
print(count)

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 switch in range(1 << n):
    target = str(bin(switch))[2:]
    if len(target) < n:
        target = "0"*(n-len(target)) + target
    flag = True
    for i in range(m):
        count = 0
        for j in ks[i][1:]:
            if target[j-1] == "1":
                count += 1

        if count % 2 != p[i]:
            flag = False
    if flag:
        ans += 1
print(ans)

Solution (Python):
def slove():
    import sys
    import itertools
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    s = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    p = list(map(int, input().rstrip('\n').split()))
    ls = [True, False]
    a_cnt = 0
    for it in itertools.product(ls, repeat=n):
        b = True
        for i, v in enumerate(s):
            cnt = 0
            for j, vv in enumerate(v):
                if j != 0:
                    if it[vv-1]:
                        cnt += 1
            if p[i] != cnt % 2:
                b = False
                break
        if b:
            a_cnt += 1
    print(a_cnt)


if __name__ == '__main__':
    slove()

Solution (Python):
N, M = map(int, input().split())
K_S = [[int(i) for i in input().split()] for _ in range(M)]
P = [int(i) for i in input().split()]
tot_cnt = 0

def check(combo):
    '''combo is list of string and returns boolean'''
    cnt = 0
    for i in range(M):
        tot = 0
        for j in K_S[i][1:]:
            tot += int(combo[j - 1])
        cnt += 1 if tot % 2 == P[i] else 0
    return cnt == M

for i in range(2**N):
    combo = list("{:010b}".format(i))[::-1]
    if check(combo):
        tot_cnt += 1

print(tot_cnt)

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(2 ** n):
    state = "{:010b}".format(i)[::-1]
    for j in range(m):
        count = 0
        for si in s[j]:
            count += int(state[si-1])
        if count % 2 != p[j]:
            break
    else:
        ans += 1
print(ans)

Solution (Python):
n,m=[int(i) for i in input().split()]
bulbs=[]
ans=0
for i in range(m):
    a=[int(i) for i in input().split()]
    bulbs.append(a[1:])
p=[int(i) for i in input().split()]
config=[]

for i in range(2**n):
    state=[]
    for j in range(n):
        if(((i)&(1<<j))):
            state.append(1)
        else:
            state.append(0)
    config.append(state)
for i in range(len(config)):
    tot=0
    for j in range(len(bulbs)):
        ct=0
        for k in range(len(bulbs[j])):
            if(config[i][bulbs[j][k]-1]==1):
                ct+=1
        if(ct%2==p[j]):
            tot+=1
    if(tot==m):
        ans+=1
print(ans)

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

def judge(M,s,p,li_state):
  for i in range(M):
    sum_light=0
    for j in s[i]:
      if li_state[j-1]:sum_light+=1
    if sum_light%2!=p[i]:
      return False
  return True

def excute_numofLighton(i,M,N,s,p,li_state,num):
  if i>=N:
    if judge(M,s,p,li_state):
      num+=1
    return num
  li_state[i]=1
  num=excute_numofLighton(i+1,M,N,s,p,li_state,num)
  li_state[i]=0
  num=excute_numofLighton(i+1,M,N,s,p,li_state,num)
  return num

li_state =[0]*N
ans = 0
ans = excute_numofLighton(0,M,N,s,p,li_state,ans)
print(ans)

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

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

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

ans = 0
for bit in range(2 ** n):
    on_light_cnt = 0
    for i in range(m):
        on_switch_cnt = 0
        for j in s[i]:
            if (bit >> (j - 1)) & 1 == 1:
                on_switch_cnt += 1

        if on_switch_cnt % 2 == p[i]: 
            on_light_cnt += 1
    if on_light_cnt == m: ans += 1

print(ans)

Solution (Python):
N, M = map(int, input().split())
kLst = [list(map(int, input().split())) for i in range(M)]
pLst = list(map(int, input().split()))
ans = 0
dLst = [0] * N

def dfs(n, v, ans):
    dLst[n - 1] = v
    if N == n:
        tLst = [0] * M
        for i in range(M):
            cnt = 0
            for j in range(kLst[i][0]):
                if dLst[kLst[i][j + 1] - 1] == 1:
                    cnt += 1
            tLst[i] = cnt % 2
        s = True
        for i in range(M):
            if tLst[i] != pLst[i]:
                s = False
                break
        if s:
            ans += 1
        return ans
    ans = dfs(n + 1, 0, ans)
    ans = dfs(n + 1, 1, ans)
    return ans

print(dfs(0, 0, ans))

Solution (Python):
n, m = map(int, input().split())
bulbs = []
for _ in range(m):
    _, *s = list(map(int, input().split()))
    bulbs.append(s)
ps = list(map(int, input().split()))

count = 0
for i in range(2**n):
    switches = []
    for _ in range(n):
        switches.append(i % 2)
        i //= 2
    ok = True
    for s, p in zip(bulbs, ps):
        res = p
        for b in s:
            res += switches[b - 1]
        if res % 2 == 1:
            ok = False
    if ok:
        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()))[1:])
p = list(map(int, input().split()))

ans = 0
for i in range(2**n):
    i_bin = "{:010b}".format(i)[::-1]
    for m_i in range(m):
        bulb_sum = 0
        for x in s[m_i]:
            bulb_sum += int(i_bin[x-1])
        if bulb_sum % 2 != p[m_i]:
            break
    else:
        ans += 1

print(ans)

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

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

sl = [0] * n

count = 0

for t in range(2**n):
		
	
	
	test = True
	for o in range(m):
		on = 0
		for q in kl[o]:
			on += sl[q-1]
		
		if pl[o] != on % 2:
			test = False
		
	if test:
		count += 1
	
	for i in range(n):
		if sl[i] == 0:
			sl[i] = 1
			for j in range(i):
				sl[j] = 0
			break
	

print(count)

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

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


switch = [0 for i in range(N)] 


def search(N,M,light,p,l,switch):
    if l<N:
        l += 1
        a=search(N,M,light,p,l,switch)
        switch[l-1]+=1 
        b = search(N,M,light,p,l,switch)
        return a+b
    else:
        flag = 0
        for i in range(M):
            a = 0
            for j in range(light[i][0]):
                a +=switch[light[i][j+1]-1]
            if a%2 == p[i]:
                continue
            else:
                flag = 1
                break
        if flag == 0:
            return 1
        else:
            return 0
  

ans = search(N,M,light,p,0,switch)
print(ans)

Solution (Python):
import collections 
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n,m = inpl()
s = [0] * m
for i in range(m):
    s[i] = inpl()
p = inpl()
ans = 0

for flag in itertools.product([0,1], repeat=n):
    cnt = 0
    bb = [False] * n
    for i,j in enumerate(flag):
        if j :
            bb[i] = True
    for i in range(m):
        tmp = 0
        for j in range(1,len(s[i])):
            if bb[s[i][j]-1] == True:
                tmp += 1
        if tmp % 2 == p[i]:
            cnt += 1
    if cnt == m:
        ans += 1
print(ans)

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

swi = []
for _ in range(M):
    k, *s_list = list(map(int, input().split()))
    temp_num = 0
    for s in s_list:
        temp_num += 1 << (s-1)
    swi.append(temp_num)

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

ans = 0
for i in range(1 << N):
    for s, p in zip(swi, p_list):
        swi_on = i & s
        if bin(swi_on).count('1') % 2 != p:
            break
    else:
        ans += 1

print(ans)

Solution (Python):
n,m = map(int,input().split())
 
binary = 2**(n)
 
lamps={i:[] for i in range(m)}
 
 
for i in range(m):
    temp=list(map(int,input().split()))
    lamps[i]=[temp[1:]]
ps=list(map(int,input().split()))
 
for i,p in enumerate(ps):
    lamps[i].append(p)
 
 
pattern=0
for i in range(binary,binary*2):
    check_flg=True
    i_binary = bin(i)
    switch = list(map(int, list(i_binary[2:])))
    for sws, on_flg in lamps.values():
        sums=0
        for s_index in sws:
            if switch[s_index] == 1:
                sums+=1
        if sums%2!=on_flg:
            check_flg=False
            break
    if check_flg:
        pattern+=1
print(pattern)

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

binary = 2**(n)

lamps={i:[] for i in range(m)}


for i in range(m):
    temp=list(map(int,input().split()))
    lamps[i]=[temp[1:]]
ps=list(map(int,input().split()))

for i,p in enumerate(ps):
    lamps[i].append(p)


pattern=0
for i in range(binary,binary*2):
    check_flg=True
    i_binary = bin(i)
    switch = list(map(int, list(i_binary[2:])))
    for sws, on_flg in lamps.values():
        sums=0
        for s_index in sws:
            if switch[s_index] == 1:
                sums+=1
        if sums%2!=on_flg:
            check_flg=False
            break
    if check_flg:
        pattern+=1
print(pattern)

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

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


switch = [0 for i in range(N)] 


def search(N,M,light,p,l,switch):
    if l<N:
        l += 1
        a=search(N,M,light,p,l,switch)
        switch[l-1]+=1 
        b = search(N,M,light,p,l,switch)
        return a+b
    else:
        flag = 0
        for i in range(M):
            a = 0
            for j in range(light[i][0]):
                a +=switch[light[i][j+1]-1]
            if a%2 == p[i]:
                continue
            else:
                flag = 1
                break
        if flag == 0:
            return 1
        else:
            return 0
  

ans = search(N,M,light,p,0,switch)
print(ans)

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

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


light = [0 for i in range(N)] 



def search(N,M,switch,p,l,light):
    if l<N:
        l += 1
        a=search(N,M,switch,p,l,light)
        light[l-1]+=1 
        b = search(N,M,switch,p,l,light)
        return a+b
    else:
        flag = 0
        for i in range(M):
            a = 0
            for j in range(switch[i][0]):
                a +=light[switch[i][j+1]-1]
            if a%2 == p[i]:
                continue
            else:
                flag = 1
                break
        if flag == 0:
            return 1
        else:
            return 0
  

ans = search(N,M,switch,p,0,light)
print(ans)

Solution (Python):

import sys
MOD = 2  

def solve(S, k, p, M, N):
    count = 0
    for sw in range(2**N):
        sw_str = bin(sw)[2:].zfill(N)
        sw_list = list(map(int, list(sw_str)))
        isGood = True
        for i in range(M):
            bsum = 0
            for j in range(k[i]):
                bsum += sw_list[S[i][j]]
            if bsum % 2 != p[i]:
                isGood = False
                break
        if isGood:
            count += 1

    print(count)
    return 

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    k = [0] * M
    p = [0] * M
    S = []
    for i in range(M):
        k[i] = int(next(tokens))
        S += [ [int(next(tokens))-1 for j in range(k[i]) ] ]
    for i in range(M):
        p[i] = int(next(tokens))

    solve(S, k, p, M, N)

if __name__ == '__main__':
    main()

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

for i in range(m):
    for j in [int(_) for _ in input().split()][1:]:
        k[j-1].append(i)

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



p2=[False]*m
c=0
for i in range(2**n):
    l=format(i,"0>10b")[-n:]
    
    t=copy.deepcopy(p)
    
    
    for j in range(n):
        if l[j]=="1":
            for h in k[j]:
                t[h]= not t[h]
    
    if t==p2:
        c+=1
print(c)

Solution (Python):
def slove():
    import sys, itertools
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    ks = []
    for i in range(m):
        ks.append(list(map(int, input().rstrip('\n').split())))
    p = list(map(int, input().rstrip('\n').split()))
    ls = [True, False]
    all_cnt = 0
    for i in itertools.product(ls, repeat=n):
        b = True
        for j, v in enumerate(ks):
            cnt = 0
            for k, s in enumerate(v):
                if k != 0:
                    if i[s-1]:
                        cnt += 1
            if p[j] != cnt % 2:
                b = False
                break
        if b:
            all_cnt += 1
    print(all_cnt)


if __name__ == '__main__':
    slove()

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

p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    for j in range(M):
        bitmask = 0b0
        for sw in lst[j][1::]:
            bitmask += 2**(sw-1)
        on_count = bin(bitmask & i).count("1")
        
        if p[j] != on_count % 2:
            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()))
c = 0
a = 0
for a in range(2**n):
  a2 = format(a, 'b').zfill(n)
  d = 0
  for i in range(m):
    o = 0
    for j in range(S[i][0]):
      o += int(a2[S[i][j+1]-1])
    if o % 2 == P[i]:
      d += 1
  if d == m:
    c += 1
print(c)

Solution (Python):
import numpy as np
N, M = map(int, input().split())

S = []
for m in range(M):
    l = list(map(int, input().split()))
    S.append(np.array(l[1:], dtype = int) - 1)
P = list(map(int, input().split()))

cnt = 0
for n in range(2 ** N):
    tmp = np.array(list(map(int, list(format(n, 'b').zfill(N)))), dtype = int)
    f = True
    for m in range(M):
        
        if tmp[S[m]].sum() % 2 != P[m]:
            f = False
            break

    if f: cnt += 1

print (cnt)

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

switch = [['0'], ['1']]

for i in range(N-1):
    tmp = []
    for j in switch:
        tmp.append(j+['0'])
        tmp.append(j+['1'])
    switch = tmp 

ans = 0

for i in switch:
    false = 0
    for j in range(M):
        cnt = 0 
        for k in range(s[j][0]):
            if i[s[j][1+k]-1] == '1':
                cnt += 1
        if cnt%2 != p[j]:
            false += 1 
    if false == 0:
        ans += 1 
print(ans)