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):
t = input().rstrip().split(' ')
switch = int(t[0])
lamp = int(t[1])
s = [list(map(int, input().split())) for _ in range(lamp)]
p = list(map(int, input().split()))
ans = 0

for i in range(2 ** switch):
    ptn = bin(i)[2:].rjust(switch, '0')
    light = True
    for j in range(lamp):
        temp = 0
        for n in range(1, s[j][0] + 1):
            if ptn[s[j][n] - 1] == '1':
                temp += 1
        if temp % 2 != p[j] % 2:
            light = False
    if light:
        ans += 1

print(ans)

Solution (Python):
t = input().rstrip().split(' ')
switch = int(t[0])
lamp = int(t[1])
s = [list(map(int, input().split())) for _ in range(lamp)]  
p = list(map(int, input().split()))
ans = 0

for i in range(2 ** switch):
  ptn = bin(i)[2:].rjust(switch, "0")
  light = True;
  for j in range(lamp):
    temp = 0
    for n in range(1, s[j][0] + 1):
      if ptn[s[j][n] - 1] == "1":
        temp += 1
    if temp % 2 != p[j] %2:
      light = False
  if light:
    ans += 1
print(ans)

Solution (Python):
import sys

n, m = map(int, sys.stdin.readline().split())
graph = [[] for _ in range(n)]
for i in range(m):
    for s in [int(x) for x in sys.stdin.readline().split()][1:]:
        graph[s-1].append(i)
*p, = map(int, sys.stdin.readline().split())

def main():
    cnt = 0
    for i in range(1 << n):
        bits = [0] * m
        for j in range(n):
            if i >> j & 1:
                for s in graph[j]:
                    bits[s] ^= 1
        for j in range(m):
            if bits[j] ^ p[j]: break
        else:
            cnt += 1
    print(cnt)

if __name__ ==  '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
km=[list(map(int, input().split())) for _ in range(m)]
p=list(map(int, input().split()))
e=0
for i in range(2 ** n):
    b=0
    d=0
    for j in range(n):  
        if ((i >> j) & 1):  
            b+= 10**j 
    if 1==1:
        b="0"*(n-len(str(b)))+str(b)
    for j in range(m):
        c=0
        for k in range(1,km[j][0]+1):
            b=str(b)


            f=int(b[(km[j][k]-1)])

            c+=f
        if c%2!=p[j]:
            break
        else:
            d+=1
    if d==m:
        e+=1
print(e)

Solution (Python):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
km=[list(map(int, input().split())) for _ in range(m)]
p=list(map(int, input().split()))
e=0
for i in range(2 ** n):
    b=0
    d=0
    for j in range(n):  
        if ((i >> j) & 1):  
            b+= 10**j 
    if 1==1:
        b="0"*(n-len(str(b)))+str(b)
    for j in range(m):
        c=0
        for k in range(1,km[j][0]+1):
            b=str(b)


            f=int(b[(km[j][k]-1)])

            c+=f
        if c%2!=p[j]:
            break
        else:
            d+=1
    if d==m:
        e+=1
print(e)

Solution (Python):
def switches(N, M, array, P):
    count = 0
    for i in range(0,2**N):
        flag = 0
        for j in range(M):
            sum = 0
            for k in range(1,array[j][0]+1):
                if format(i, '0'+str(N)+'b')[array[j][k]-1] == '1':
                    sum += 1
            
            if sum%2 == P[j]:
                flag += 1
            
        if flag == M:
            count += 1

    return count


if __name__ == "__main__":
    N,M = map(int, input().split())
    array = []
    for i in range(M):
        array.append(list(map(int, input().strip().split())))
    P = list(map(int, input().strip().split()))
    print(switches(N,M,array,P))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def is_nth_set(x, n):
    if x & (1 << n):
        return 1
    else:
        return 0


def main():
    N, M = map(int, input().split())
    S = []
    for _ 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 pattern in range(2 ** N):
        switch = []
        for i in range(N):
            switch.append(is_nth_set(pattern, i))

        for i in range(M):
            cnt = 0
            for s in S[i]:
                cnt += switch[s]
            if cnt % 2 != P[i]:
                break
        else:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):










mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    
    
    A = []
    for i in range(m):
        A.append(list(map(lambda x: int(x) - 1, input().split()))[1:])
    P = readInts()
    ans = 0

    for bit in range(1 << n):
        ok = True
        for i in range(m):
            con = 0
            for v in A[i]:
                
                if bit & 1 << v:
                    con += 1
            if con % 2 != P[i]:
                ok = False
        if ok:
            ans += 1
    print(ans)


if __name__ == '__main__':
  main()

Solution (Python):


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

ans = 0

for bits in range(2 ** n):
    ok = True
    for i, k in enumerate(K):
        ok = ok and sum((bits >> (s - 1)) & 1 for s in k[1:]) % 2 == P[i]
    if ok:
        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()))

ans = 0
for i in range(1<<n):
    isOn = []
    for j in range(n):
        if i & (1<<j):
            isOn.append(j+1)

    flag = True
    for j in range(m):
        count = 0
        for v in s[j]:
            if v in isOn:
                count += 1
        if count % 2 != p[j]:
            flag = False
    if flag:
        ans += 1

print(ans)

Solution (Python):
n,m=map(int,input().split())
A=[]
for _ in range(m):
    A.append([i-1 for i in list(map(int,input().split()))[1:]])
P=list(map(int,input().split()))
ans=0
for bit in range(1<<n):
    for j in range(m):
        now=0
        for i in A[j]:
            if bit & 1<<i: now+=1
        if now%2!=P[j] : break
        if j==m-1: 
            
            ans+=1


print(ans)

Solution (Python):
n,m=map(int,input().split())
A=[]
for _ in range(m):
    A.append([i-1 for i in list(map(int,input().split()))[1:]])
P=list(map(int,input().split()))
ans=0
for bit in range(1<<n):
    for j in range(m):
        now=0
        for i in A[j]:
            if bit & 1<<i: now+=1
        if now%2!=P[j] : break
        if j==m-1: 
            
            ans+=1


print(ans)

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

cnt = 2 ** N
ans = 0

sum = [0] * M

for j in range(M):
    for x in S[j]:
        sum[j] += 2 ** (x - 1)

for i in range(cnt):
    flg = 1
    for j in range(M):
        calc = sum[j] & i
        sum_str = bin(calc)
        div = sum_str.count('1') % 2
        if P[j] == div:
            continue
        else:
            flg = 0
            break
    if flg == 1:
        ans += 1
print(ans)

Solution (Python):
sw, li = [int(i) for i in input().split(" ")]
sw_lists = []
sw_arr = [1 for _ in range(sw)]
ans = 0

for i in range(li):
    sw_list = []
    sw_list = [int(j) - 1 for j in input().split(" ")][1:]
    sw_lists.append(sw_list)

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

for i in range(2 ** sw):
    ena_sw = [0 for _ in range(sw)]
    ena_nums = []

    for j in (range(sw)):
        if (i >> j) & 1:
            ena_sw[j] = 1
    
    for j in sw_lists:
        ena_num = []
        for k in j:
            ena_num.append(ena_sw[k])
        ena_nums.append(ena_num)
    
    for ena_num,mod in zip(ena_nums, sw_mod):
        if (sum(ena_num) % 2) != mod:
            break
    else:
        ans += 1
print(ans)

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

Solution (Python):
N, M = map(int, input().split())
lamps = []
for i in range(M):
    row = [int(e) for e in input().split()]
    lamps.append(row[1:])
p = [int(e) for e in input().split()]

ans = 0
for i in range(1 << N):
    ok = True
    for j in range(M):
        c = 0
        for id in lamps[j]:
            if (i >> (id - 1)) & 1:
                c += 1
        c %= 2
        if c != p[j]:
            ok = False
    if ok:
        ans += 1

print(ans)

Solution (Python):
N,M=map(int,input().split())
s=[list(map(int,input().split()))[1:] for m in range(M)]
p=list(map(int,input().split()))
count=0
for bit in range(1<<N):
    flag=True
    for m in range(M):
        on=0
        for n in range(N):
            if (bit>>n)&1 and n+1 in s[m]:
                on+=1
        if on%2!=p[m]:
            flag=False
    if flag:
        count+=1
print(count)

Solution (Python):
N,M=map(int,input().split())
s=[list(map(int,input().split()))[1:] for m in range(M)]
p=list(map(int,input().split()))
count=0
for i in range(1<<N):
    flag=True
    for m in range(M):
        on=0
        for n in range(N):
            if (i>>n)&1 and n+1 in s[m]:
                on+=1
        if on%2!=p[m]:
            flag=False
    if flag:
        count+=1
print(count)

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

ans=0
for i in range(2**n):
    num=format(i,"b").zfill(n)
    point=0
    for j in range(m):
        cnt=0
        for k in A[j]:
            if num[k-1]=="1":cnt +=1
        if cnt%2==P[j]:point +=1
    if point==m:ans +=1
print(ans)

Solution (Python):
n, m = map(int, input().split())
ss = []
for i in range(m):
    s = list(map(int, input().split()))
    x = 0
    for i in range(1, len(s)):
        x |= 1 << (s[i] - 1)
    ss.append(x)
pp = list(map(int, input().split()))

ans = 0
for x in range(2 ** n):
    non = 0
    for i in range(m):
        a = ss[i] & x
        nb = 0
        while a != 0:
            if a & 1 == 1:
                nb += 1
            a >>= 1
        if nb % 2 == pp[i]:
            non += 1
    if non == m:
        ans += 1
print(ans)

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

S=[[0]*N for _ in range(M)]
for i in range(M):
  ks=map(int, input().split())
  for j,s in enumerate(ks):
    if j==0:
      continue
    S[i][s-1]+=1


P=list(map(int, input().split()))
S=np.array(S)
P=np.array(P)

ans=0
for i in range(2**N):
  now=np.zeros(M)
  for j in range(N):
    if i>>j&1==1:
      
      now+=S[:,j]
  
  ans+=int(((now%2)==P).all())
  

print(ans)

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

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



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:
        res += 1

print(res)

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


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

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

for i in range(2**n):
    on = [0]*n
    j = 0
    while i > 0:
        if i&1:
            on[j] = 1
        i = i >> 1
        j += 1
    cnt = [0]*m
    flag = 1
    for j in range(m):
        for s in S[j]:
            cnt[j] += on[s-1]
        if (cnt[j]-P[j])&1:
            flag = 0
    ans += flag
print(ans)

Solution (Python):
N, M = [int(x) for x in input().split()]
K = [[0]*N]*M
for i in range(M):
  K[i] = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]
total = 0
for i in range(2 ** N):
    lamp = [0] * N
    for j in range(N):
        if ((i >> j) & 1):
            lamp[j] = 1
    flag = True
    for x in range(M):
      result = 0
      for y in K[x][1:]:
        if lamp[y-1] == 1:
          result += 1
      result %= 2
      if result != P[x]:
        flag = False
    if flag:
      total += 1
print(total)

Solution (Python):
n,m = [int(x) for x in input().split()]
ks = []
for _ in range(m):
    ks.append([int(x) for x in input().split()])
p = [int(x) for x in input().split()]
ans = 0
for i in range(2**n):
    li = []
    flag = True
    for j in range(n):
        if (i>>j) & 1:
            li.append(1)
        else:
            li.append(0)
    
    for o,j in enumerate(ks):
        cnt = 0
        for l in range(1,j[0]+1):
            if li[j[l]-1]==1:
                cnt+=1
        if cnt%2!=p[o]:
            flag = False
    if flag:
        ans+=1
print(ans)

Solution (Python):
N, M = [int(x) for x in input().split()]
K = [[0]*N]*M
for i in range(M):
  K[i] = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]
total = 0
for i in range(2 ** N):
    lamp = [0] * N
    for j in range(N):
        if ((i >> j) & 1):
            lamp[j] = 1
    flag = True
    for x in range(M):
      result = 0
      for y in K[x][1:]:
        if lamp[y-1] == 1:
          result += 1
      result %= 2
      if result != P[x]:
        flag = False
    if flag:
      total += 1
print(total)

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

cnt = 2 ** N
ans = 0

for i in range(cnt):
    flg = 1
    for j in range(M):
        s = S[j]
        sum_s = 0
        for x in s:
            sum_s += 2 ** (x - 1)
        calc = sum_s & i
        sum_str = bin(calc)
        div = sum_str.count('1') % 2
        if P[j] == div:
            continue
        else:
            flg = 0
            break
    if flg == 1:
        ans += 1
print(ans)

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


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

p = [int(i) for i in input().split()]
count = 0
for i in range(2 ** n):
  state = [0 for _ in range(m)]
  for j in range(n):
    
    if (i >> j) & 1:
      for k in s[j]:
        state[k] = (state[k] + 1) % 2
  if state == p:
    count += 1
print(count)

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 i in range(2 ** N):
    for m in range(M):
        switch = 0
        for j in range(N):
            if (i >> j) & 1:
                if j + 1 in s[m]:
                    switch += 1
        if switch % 2 != p[m]:
            break
    else:
        count += 1
print(count)

Solution (Python):
N,M=map(int,input().split())
s=[list(map(int,input().split()))[1:] for m in range(M)]
p=list(map(int,input().split()))
count=0
for i in range(1<<N):
    for m in range(M):
        switch=0
        for j in range(N):
            if (i>>j)&1 and j+1 in s[m]:
                switch+=1
        if switch%2!=p[m]:
            break
    else:
        count+=1
print(count)

Solution (Python):
import itertools
def main():
    n,m = map(int,input().split())
    S = []
    for _ in range(m):
        s = list(map(int,input().split()))
        s.pop(0)
        S.append(s)
    p = list(map(int,input().split()))
    status = [[0,1] for i in range(n)]
    cnt = 0
    for on in itertools.product(*status):
        flag = 0
        for i in range(m):
            s = 0
            for j in range(len(S[i])):
                if on[S[i][j]-1]==1:
                    s += 1
            if s%2==p[i]:
                flag += 1
                if flag==m:
                    cnt += 1
                continue
            else:
                break
    print(cnt)
        

if __name__ == "__main__":
    main()

Solution (Python):
from itertools import product
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
for i in product(range(2), repeat=n):
    for j in range(m):
        total = 0
        for k in ks[j][1:]:
            total += i[k-1]
        if total%2!=p[j]:
            break
    else: ans+=1
    
print(ans)

Solution (Python):

def inputlist(): return [int(k) for k in input().split()]

N,M = inputlist()
switch = [0]*M
k = [0]*M
for i in range(M):
    li = inputlist()
    k[i] = li[0]
    switch[i] = li[1:]
p = inputlist()

ans = 0

for i in range(2**N):
    s = bin(i)
    s = s[2:]
    if len(s) < N:
        for y in range(N-len(s)):
            s = '0'+s
    co = 0
    for j in range(M):
        count = 0
        for t in range(k[j]):
            if s[switch[j][t] - 1] == '1':
                count +=1
        if count % 2 == p[j]:
            co +=1
    if co == M:
        ans +=1

print(ans)

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

ans = 0
for bit in range(1 << N):
    
    flag = True
    for i in range(M):
        sum = 0
        for j in S[i]:
            if bit & (1 << (j-1)):
                sum += 1
        if sum%2 != p[i]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

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

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

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

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

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

def dfs(cur, switch):
    light = [0] * m
    for i in range(n):
        if switch[i]==1:
            for j in range(m):
                if i+1 in t[j]:
                    light[j] = 1-light[j]
    if light == p:
        ret = 1
    else: ret = 0

    if cur == n:
        return ret
    else:
        switch1 = switch.copy()
        switch1[cur] = 1
        return dfs(cur+1, switch) + dfs(cur+1, switch1)

print(dfs(0, [0] * n))

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

res = 0
for i in range(2 ** N):
    ok = True

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

    else:
        res += 1

print(res)

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

for i in range(2 ** N):
  sw = [0]*N
  for j in range(N):
    if ((i >> j) & 1):
      sw[j] = 1
  frg = True
  for j in range(M):
    a = ks[j][0]
    aa = 0
    for k in range(1,a+1):
      aa += sw[ks[j][k]-1]
    if aa%2 != p[j]:
      frg = False
  if frg:
    c += 1
    
print(c)

Solution (Python):
N,M=map(int,input().split())
k=[]
s=[]
ans=0

for i in range(M):
    l=list(map(int,input().split()))
    k.append(l[0])
    s.append(l[1:])
p=list(map(int,input().split()))

for i in range(2**N): 
    light=0
    b=bin(i)[2:].zfill(N) 
    for j in range(M): 
        cond=0
        for l in range(k[j]): 
            cond+=(int(b[s[j][l]-1]))
        if cond%2==p[j]:
            light+=1
    if light==M:
        ans+=1
print(ans)

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

ans = 0
for i in range(2 ** N):
    flag = True
    for m in range(M):
        _sum = 0
        for j in range(N):
            if i >> j & 1:
                _sum += K[m][j]
        if (_sum % 2) != p[m]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Solution (Python):
N, M = map(int, input().split())
s_setlist = []
for i in range(M):
    k, *s = list(map(int, input().split()))
    s_setlist.append(set(s))
plist = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    on = set()
    for j in range(N):
        if ((i >> j) & 1):
            on.add(j+1)
    light_list = [len(on&s_setlist[k])%2==plist[k] for k in range(M)]
    if all(light_list):
        ans += 1
print(ans)

Solution (Python):


def main():
    n, m = map(int, input().split())
    lamp = []
    for _ in range(m):
       lamp.append([int(i)-1 for i in input().split()][1:]) 
    p = [int(i) for i in input().split()]
    cnt = 0
    for i in range(1<<n):
        partition = [0 for _ in range(n)]
        for j in range(n):
            if i>>j & 1:
                partition[j] = 1
            
        
        flag = True
        for j in range(m):
            s = 0
            
            for k in range(len(lamp[j])):
                v = lamp[j][k]
                if partition[v]:
                    s += 1
            if s%2 != p[j]:
                flag = False
        if flag:
            cnt += 1
    print(cnt)
main()

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


cond = [bin(i)[2:].zfill(n) for i in range(2**n)]

ans = 0
for i in range(2**n):
    cond_sw = cond[i]
    flag = True
    for j in range(m):
        tar_bulb = bulb[j]
        cnt = 0
        for k in range(len(bulb[j])):
            if cond_sw[tar_bulb[k]-1] == "1":
                cnt += 1
        if cnt % 2 != p[j]:
            flag = False
    if flag:
        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(1<<N):
    cond = [0]*N
    for j in range(N):
        if 1&(i>>j):  
            cond[j] = 1
    
    flag = True
    
    for i in range(M):
        cnt = 0
        for j in switch[i][1:]:
            cnt +=  cond[j-1]
        if cnt%2 != P[i]:
            flag = False
            break
    
    
    ans += flag

print(ans)

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

for b in range(1 << n):

    sw = [0] * n
    for i in range(n):
        if b & (1 << i): sw[i] = 1

    status = True
    for i in range(m):
        cnt1 = 0
        for j in s[i]:
            if sw[j - 1] == 1: cnt1 += 1
        if cnt1 % 2 != p[i]: status = False
    
    if status: cnt0 += 1

print(cnt0)

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

ans = 0
for i in range(1<<n):
  flag = True
  for j in range(m):
    l = light[j][1:]
    count = 0
    for s in l:
      if i & (1<<(s-1)):
        count += 1
    if count%2 != p[j]:
      flag = False
  if flag==True:
    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(1<<N):
    flag = True
    for j in range(M):
        s = ks[j][1:]
        count = 0
        for v in s:
            if i & (1<<(v-1)):
                count += 1
        if count % 2 != p[j]:
            flag = False
    
    if flag:
        ans += 1

print(ans)

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

res = 0
for bit in range(2 ** n): 
  cc1 = 0
  for i in range(m): 
    k = S[i][0]
    cc = 0
    for j in range(1, k+1):
      if (bit >> (S[i][j]-1)) & 1:
        cc += 1
    if cc%2 == P[i]:
      cc1 += 1
  if cc1 == m:
    res += 1
print(res)

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()))
c = 0
from collections import deque
for i in range(2**N):
    bitlist = deque()
    for j in range(N):
        if ((i >> j) & 1): 
            bitlist.appendleft(1)
        else:
          	bitlist.appendleft(0)
    bitlist = list(bitlist)
    e = 0
    for ii in range(M):
        d = 0
        k = KS[ii][0]
        s = KS[ii][1:]
        for l in s:
            d += bitlist[l-1]
        d = d%2
        if d != P[ii]:
            e = 1
            break
    if e == 0:
        c += 1
print(c)

Solution (Python):
n,m = map(int,input().split())
light = [list(map(int,input().split())) for _ in range(m)]
p = list(map(int,input().split()))
ans = 0
for i in range(2**n):
    binstr = list(reversed(format(i, '010b')))
    lightnum = 0
    for j in range(m):
        cnt = 0
        K = light[j][0]
        for k in range(1,K+1):
            s = light[j][k]
            if binstr[s-1] == '1':
                cnt += 1
        if p[j] == cnt%2:
            lightnum += 1
    if lightnum == m:
        ans += 1
print(ans)

Solution (Python):


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

l_k = []
switches = []
for _ in range(M):
    line = list(map(int, input().split()))
    l_k.append(line[0])
    s = [i - 1 for i in line[1:]]
    switches.append(s)
l_p = list(map(int, input().split()))




res = 0
for num in range(2 ** N):
    on_all = True
    for i in range(M):
        n_on = 0
        for s in switches[i]:
            if num & (1 << s):
                n_on += 1
        if n_on % 2 != l_p[i]:
            on_all = False
    if on_all:
        res += 1

print(res)

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 bit in range(2**n):
  ok=True
  for j in range(m):
    c=0
    k=s[j][0]
    for l in range(1,k+1):
      if (bit &(1<<(s[j][l]-1))):c+=1
    if c%2!=p[j]:ok=False
  if ok:ans+=1
print(ans)

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

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

Solution (Python):
N,M = map(int,input().split())
K = []
S = []
for _ in range(M):
    x = input().split()
    k = int(x[0])
    K.append(k)
    S.append([int(x[i]) for i in range(1,k+1)])

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

c = 0
for i in range(2 ** N):
    L = [((i >> j) & 1) for j in range(N)]
    T = "y"
    for j in range(M):
        s = 0
        for k in range(K[j]):
            s += L[S[j][k]-1]
        if s%2 != p[j]:
            T = "n"
            break
    if T == "y":
        c +=1
        
print(c)

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

count=0
for i in range(1<<n):
    f = True
    for j in range(m):
        pc = 0
        sw = ks[j][1:]
        for s in sw:
            s-=1
            if i&(1<<s):
                pc ^= 1
        if pc != p[j]:
            f = False
    if f:
        count += 1
print(count)

Solution (Python):
import sys


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


sys.setrecursionlimit(10 ** 9)


def main():
    N, M = map(int, input().split())
    S = [list(map(int, input().split())) for _ in range(M)]
    P = list(map(int, input().split()))
    answer = 0
    for i in range(2 ** N):
        switch = [0 for _ in range(M)]
        for j in range(N):
            for m in range(M):
                if (i >> j) & 1:
                    if (j + 1) in S[m][1:]:
                        switch[m] += 1
        check = 0
        for m in range(M):
            if switch[m] % 2 == P[m]:
                check += 1

        if check == M:
            answer += 1

    print(answer)


if __name__ == "__main__":
    main()