Problem:
 Score : 300 points    Problem Statement We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N , and the bulbs are numbered 1 to M .  Bulb i is connected to k_i switches: Switch s_{i1} , s_{i2} , ... , and s_{ik_i} . It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2 .  How many combinations of "on" and "off" states of the switches light all the bulbs?      Constraints  1 \leq N, M \leq 10  1 \leq k_i \leq N  1 \leq s_{ij} \leq N  s_{ia} \neq s_{ib} (a \neq b)  p_i is 0 or 1 .  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  M  k_1  s_{11}  s_{12}  ...  s_{1k_1}  :  k_M  s_{M1}  s_{M2}  ...  s_{Mk_M}  p_1  p_2  ...  p_M       Output Print the number of combinations of "on" and "off" states of the switches that light all the bulbs.        Sample Input 1 2 2
2 1 2
1 2
0 1      Sample Output 1 1   Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2 .  Bulb 2 is lighted when there is an odd number of switches that are "on" among the following: Switch 2 .   There are four possible combinations of states of (Switch 1 , Switch 2 ): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 1 .       Sample Input 2 2 3
2 1 2
1 1
1 2
0 0 1      Sample Output 2 0   Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2 .  Bulb 2 is lighted when there is an even number of switches that are "on" among the following: Switch 1 .  Bulb 3 is lighted when there is an odd number of switches that are "on" among the following: Switch 2 .   Switch 1 has to be "off" to light Bulb 2 and Switch 2 has to be "on" to light Bulb 3 , but then Bulb 1 will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print 0 .       Sample Input 3 5 2
3 1 2 5
2 2 3
1 0      Sample Output 3 8

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

def all_on(i: int):
  for j in range(M):
    count = 0
    for sw in s[j]:
      if i & (1<<(sw-1)):
        count += 1
    if count%2 != p[j]:
      return False
  return True

ans = 0
for i in range(1<<N):
  if all_on(i):
    ans += 1
print(ans)

Solution (Python):
n,m=map(int,input().split())
k=[]
s=[]
for _ in range(m):
  tmp=list(map(lambda x: int(x)-1,input().split()))
  k.append(tmp[0]+1)
  s.append(tmp[1:])
p=list(map(int,input().split()))

count=0
for i in range(2**n):
  on=[]
  lamp=[False]*m
  for j in range(n):
    if ((i >> j) & 1):
      on.append(j)
  
  for la in range(m):
    judge=0
    for x in on:
      for y in s[la]:
        if x==y:
          judge+=1
    if judge%2==p[la]:
      lamp[la]=True
  if all(lamp):
    count+=1

print(count)

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

related_switch = [[] for _ in range(M)]
for i in range(M):
    s = list(map(lambda x: int(x)-1,input().split()))
    related_switch[i] = s[1:]

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

ans = 0
for status in range(1<<N):
    on = []
    for mask in range(N):
        if (1<<mask)&status:
            on.append(mask)
    for i,s in enumerate(related_switch):
        if len(set(s)&set(on))%2 != p[i]:
            break
    else:
        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()))
count = 0

for i in range(2**n):
  SUMLIST = []
  SUM = 0
  check = 0
  l = [0]*n
  for j in range(n):
    if ((i >> j)&1):
      l[n-j-1] = 1
  
  for switch in ks:
    for each in switch[1:]:
      SUM += (l[each-1])
    SUMLIST.append(SUM)
    SUM = 0
  
  for i in range(m):
    if SUMLIST[i]%2 == p[i]:
      check += 1
 
  if check == m:
    count += 1

print(count)

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

def bit_all():
    ret = 0
    for x in range(2 ** N):
        b = str(format(x, '010b'))
        add = 1
        for i in range(M):
            count = 0
            for j in s[i]:
                j -= 1
                if b[-(j + 1)] == "1": 
                    count += 1
            if count % 2 != p[i]:
                add = 0
        ret += add
    return ret

ans = bit_all()
print(ans)

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

k = []
s = []
ans = 0

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

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

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

print(ans)

Solution (Python):
def readinput():
    n,m=list(map(int,input().split()))
    lmpSw=[]
    for _ in range(m):
        l=list(map(int,input().split()))
        lmpSw.append(l[1:])
    p=list(map(int,input().split()))
    return n,m,lmpSw,p

def main(n,m,lmpSw,p):
    lmpSwBit=[0]*m
    for i in range(m):
        swBit=0
        for sw in lmpSw[i]:
            swBit+=2**(sw-1)
        lmpSwBit[i]=swBit

    lmpStat=[]
    for i in range(m):
        stat=[0 for x in range(2**n)]
        lmpStat.append(stat)
    

    allon=0
    for swStat in range(2**n):
        
        count=0
        for lmp in range(m):
            
            swBit=lmpSwBit[lmp]
            b=1
            for sw in range(n):            
                if(swBit&b==b) and (swStat & b)==b:
                    lmpStat[lmp][swStat]+=1
                b=b*2
            lmpStat[lmp][swStat]+=p[lmp]
            if(lmpStat[lmp][swStat]%2==0):
                count+=1
        if(count==m):
            allon+=1
    return allon


if __name__=='__main__':
    n,m,lmpSw,p=readinput()
    ans=main(n,m,lmpSw,p)
    print(ans)

Solution (Python):
n, m = map(int, input().split())
s = []
for i in range(m):
    line = list(map(int, input().split()))
    s.append(line[1:])
p = list(map(int, input().split()))
ans = 0
for pat in range(2**n):
    light_flag = True
    for i in range(m):
        tot = 0
        for sw in s[i]:
            if pat & (2 ** (sw - 1)):
                tot += 1
        if tot % 2 != p[i]:
            light_flag = False
    if light_flag:
        ans += 1
print(ans)

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

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

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

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

D=[0]*M




count=0

even=0
odd=0

for i in range(2 **N):
    D=[0]*M
    ON_SW=[0]*M
    
    for j in range(N):
        if ((i >> j) & 1):
            
            for k in range(M):
                for l in range(len(S[k])):
                    if j+1==S[k][l]:
                        ON_SW[k]+=1
                        
    
    
            
    flag=True
    for j in range(M):
        
        if ON_SW[j]%2==P[j]:
            pass
        else:
            flag=False
        
    if flag==True:
        
        count+=1
    
    
print(count)

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

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

s = []
for i in range(M):
    _, *tmp_s = map(int, input().split())
    s.append(tmp_s)
    
p = list(map(int, input().split()))

import numpy as np

s_matrix = []

for i in range(M):
    s_matrix.append([1 if x+1 in s[i] else 0 for x in range(N)])
    
s_matrix = np.array(s_matrix)

ans = 0

for i in range(2**N):
    on_off_pattern = list(format(i, '0%db' %N))
    on_nums = np.dot(s_matrix, np.array(list(map(int, on_off_pattern))))
    on_nums_mod2 = on_nums % 2

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

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

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

  t_cnt=0
  for j in range(m):
    on_l=0
    for x in k[j][1:]:
      x-=1
      if l[x]==1:
        on_l+=1
    if on_l%2==p[j]:
      t_cnt+=1

  if t_cnt==m:
    cnt+=1

print(cnt)

Solution (Python):













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


k = []
s = []

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


ans = 0


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

Solution (Python):
N,M = map(int,input().split())
bulbs = []
for _ in range(M):
  bulbs.append(list(map(int,input().split())))
P = list(map(int,input().split()))
res = 0
for i in range(1<<N):
  on = []
  for j in range(N):
    if (i>>j)&1:
      on.append(j)

  ok = True
  for i,b in enumerate(bulbs):
    b = [ k-1 for k in b[1:] ]
    p = P[i]
    o = 0
    for s in on:
      if s in b: o += 1
    if o%2 != p:
      ok = False
      break

  if ok:
    res += 1

print(res)

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(0,1<<n):
    cnt = [0]*m
    for j in range(n):
        if (i>>j)&1:
            for k in range(m):
                if j + 1 in ks[k][1:]:
                    cnt[k] += 1

    temp = 0
    for i in range(m):
        if cnt[i] % 2 == p[i]:
            temp += 1
    if temp == m:
        ans += 1

print(ans)

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


def solve():
    N, M = map(int, input().split())
    ks = [[] for _ in range(M)]
    for i in range(M):
        k, *s = map(int, input().split())
        ks[i] = list(s)
    p = list(map(int, input().split()))
    comb = itertools.product([0, 1], repeat=N)

    ans = 0
    for c in comb:
        f = True
        for i in range(M):
            count = 0
            for j in ks[i]:
                count += c[j - 1]
            if count % 2 != p[i]:
                f = False
                break
        if f:
            ans += 1

    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import itertools
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

ans = 0
for t in itertools.product([0, 1], repeat=n):
    t = list(t)
    bl = True
    for i in range(m):
        cnt = 0
        for j in k[i][1::]:
            cnt += t[j - 1]
        if cnt % 2 != p[i]:
            bl = False
    if bl:
        ans += 1
print(ans)

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    q = [list(map(int, input().split())) for _ in range(m)]
    p = list(map(int, input().split()))

    ans = 0
    for i in range(1 << n):
        check = True
        for j in range(m):
            ki = q[j][0]
            tmp_c = 0
            for k in range(1, ki + 1):
                if i & (1 << (q[j][k] - 1)):
                    tmp_c += 1
            if tmp_c % 2 != p[j]:
                check = False
                break
        if check:
            ans += 1
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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

ans = 0

for i in range(2**N):
    count = [0]*M
    for j in range(N) :
        if (i>>j)&1 == 1 :
            for k in range(M) :
                if j+1 in s[k][1:] :
                    count[k] += 1
    count = [i%2 for i in count]
    if count == p :
        ans += 1
print(ans)

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

ans = 0
for i in product([0,1],repeat=n):
    ac = True
    for k,b in enumerate(lamp):
        tmp = 0
        for a in b[1:]:
            tmp += i[a-1]
        if p[k] != tmp%2:
            ac = False
            break
    if ac:
        ans += 1
print(ans)

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

p = list(map(int, input().split()))
ans = 0
for _ in range(m):
  del s[_][0]

for i in range(2 ** n): 
  on = [0]*m
  for j in range(n):
    if ((i>>j)&1): 
      for __ in range(m):
        if (j+1) in s[__]:
          on[__] += 1
  for _ in range(m):
    on[_] %= 2
  if p == on:
    ans += 1
print(ans)

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

k = []
p = []
swt = []
result = 0

for num in range(N):
    swt.append(0)

for num in range(M):
    k.append(list(map(int,input().split())))

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




for i in range(2**N):
    for j in range(N):
        if(i&(1<<j)):
            swt[j] = 1

    
    for l1 in range(M):
        count = 0
        for l2 in range(k[l1][0]):
            count += swt[k[l1][l2+1]-1]

        if count%2 != p[l1]:
            for num in range(N):
                swt[num]=0
            break
        if l1==M-1:
            result +=1
            for num in range(N):
                swt[num]=0
print(result)

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

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

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

count = 0

for i in range(1<<n):
  tmp = [0] * m
  for j in range(n):
    if i & (1<<j):
      for k in range(m):
        if j+1 in s[k]:
          tmp[k] += 1
  c = 0
  for i in range(m):
    if tmp[i] % 2 == p[i]:
      c += 1
  if c == m:
    count += 1

print(count)

Solution (Python):


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

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

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



count = 0
for i in range(2**N):
    b = bin(i)[2:][::-1]
    switch = []
    for j in range(len(b)):
        if b[j] == "1":
            switch.append(j+1)
    
    
    f = 0
    for j in range(M):
        AND = len(list(set(switch) & set(s[j])))
        
        if (AND % 2 == p[j]):
            f += 1
    
    if f == M:
        count += 1
    
                
    
    

print(count)

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

button=[0]*N
lit=[0]*M
x=pow(2,N)
total=0
for i in range(x):
    for j in range(N):
        if (i>>j)&1:
            button[j]=1
        else:
            button[j]=0
    for j in range(M):
        for k in range(1,ks[j][0]+1):
            if button[ks[j][k]-1]:
                lit[j]+=1
    count=0
    for j in range(M):
        if lit[j]&1==p[j]:
            count+=1
    if count==M:
        total+=1
    for j in range(M):
        lit[j]=0
print(total)

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):
        a = []
        flag = True
        for j in range(n):
            a .append(i>>j & 1)
        ok = 0
        for j in range(m):
            switch = 0
            for s in ks[j][1:]:
                switch += a[s - 1]
            if switch % 2 != p[j]:
                flag = False
        if flag:
            ans +=1
            
    print(ans)
                
    
if __name__ == '__main__':
    main()

Solution (Python):

def main():
    import sys, itertools as ite
    N, M = map(int, sys.stdin.readline().split())
    KS = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
    P = tuple(map(int, sys.stdin.readline().split()))
    
    
    
    SWS = tuple(ite.product([0,1], repeat=N)) 
    
    def judge(on_off):
        for i in range(M):
            on_cnt = 0
            for s in KS[i][1:]:
                on_cnt += on_off[s-1]
            if on_cnt %2 !=P[i]:
                return 0
        else:
            return 1
    ans = 0
    for on_off in SWS:
        ans +=judge(on_off)
    print(ans)






if __name__=='__main__':
    main()

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

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

print(ans)

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

res=0
for bit in range(2**n):
  for i in range(m):
    cnt=0
    for sw in s[i]:
      if (bit >> (sw-1) & 1):
        cnt += 1
    if cnt % 2 != p[i]:
      break
  else:
    res+=1
print(res)

Solution (Python):
def main():
    N,M = map(int, input().split())
    s = [[int(x) for x in input().split()][1:] for _ in range(M)]
    p = [int(x) for x in input().split()]
    count=0
    for i in range(2**N):
        switch=[0]*N
        sw = bin(i)[2:]
        sw = "0"*(N-len(sw))+sw
        
        
            
        All=0   
        for j in range(M):
            Sum=0
            for k in s[j]:
                
                if int(sw[k-1])==1:
                    Sum+=1
            if Sum%2 == p[j]:
                All+=1
        if All==M:
            count+=1
    print(count)

main()

Solution (Python):
def main():
    n, m = map(int, input().split())
    lamps = [list(map(lambda x:int(x)-1, input().split()))[1:] for _ in range(m)]
    p = list(map(int, input().split()))
    res = 0
    for i in range(2**n):
        
        
        for l in range(m):
            s_on = 0
            for j in range(n): 
                
                if(i >> j) & 1 and j in lamps[l]:
                    s_on += 1
            if s_on % 2 != p[l]:
                break
        
        else:
            res += 1
    print(res)
    
if __name__ == '__main__':
    main()

Solution (Python):
n, m =map(int, input().split())
from itertools import product
s = [0,1]
ptns = sorted(list(product(s, repeat=n)), reverse=1)

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

cnt=0
check=0
rem=list(map(int, input().split()))
for i in ptns:
  for s in range(m): 
    check=0
    for t in lis[s]: 
      if i[t-1]==1:
        check+=1
    if check%2!=rem[s]:
      break
    else:
      continue
    break
  else:
    cnt+=1
print(cnt)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M = map(int, readline().split())
k = []
for i in range(M):
  swich = list(map(int,readline().split()))
  swich.pop(0)
  k.append(swich)
p = list(map(int,readline().split()))
count = 0
for bit in range(1 << N):
  ans = []
  for i in range(N):
    if (bit >> i) & 1:
      ans.append(i+1)
  for j in range(M):
    check = sum(1 for s in k[j] if s in ans)
    if check % 2 != p[j]:
      break
    if j == M-1:
      count+=1
print(count)

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

ans = 0
for b in range(1 << N):
    for i in range(M):
        on = 0
        for j in range(N):
            if j + 1 not in s[i]:
                continue
            if b & (1 << j):
                on += 1
        if on % 2 != p[i]:
            break
    else:
        ans += 1

print(ans)

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

ans=0
for i in range(2**N):
    ls = [1]*N
    for j in range(len(ls)):
        if (i >> j) & 1:
            ls[j] = 0
    count2=0
    count3=0
    for line in K:
        i=1
        count1=0
        while i<len(line):
            if ls[line[i]-1]==1:
                count1+=1
            i+=1
        if count1%2==P[count3]:
            count2+=1
        count3+=1
    ans+=1*(count2==M)


print(ans)

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

def solve():
    n, m = map(int,input().split())
    
    swi = []
    for i in range(m):
        li = list(map(int,input().split()))
        a = 0
        for j in range(1,li[0]+1):
            a += 1 << li[j]-1
        swi.append(a)
    p = list(map(int,input().split()))
    ans = 0
    for i in range(1 << n):
        for j in range(m):
            a = i & swi[j]
            if p[j] != bin(a).count("1")%2:
                break
        else:
            ans += 1
    print(ans)
        
"""
    print(swi)
    print(p)
"""
if __name__ == "__main__":
    solve()

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):
    sw = [0]*m
    for j in range(m):
        num = 0
        for k in range(n):
            if (i>>k)&1:
                if k+1 in s[j][1:]:
                    num += 1
        if num%2 == p[j]:
            sw[j] = 1
    if 0 in sw:
        pass
    else:
        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 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):
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):
    sw = [0]*m
    for k in range(m):
        num = 0
        for j in range(n):
            if (i>>j)&1:
                if j+1 in s[k][1:]:
                    num += 1
        if num%2 == p[k]:
            sw[k] = 1
    if 0 in sw:
        pass
    else:
        ans += 1
print(ans)

Solution (Python):
n, m = map(int,input().split())
X = []
for _ in range(m):
  k, *A = list(map(int,input().split()))
  b = 0
  for a in A:
    b += 1 << (a-1)
  X.append(b)
P = list(map(int,input().split()))

ans = 0
for i in range(1<<n):
  for x, p in zip(X,P):
    y = i & x
    c = bin(y).count("1") % 2
    if c != p:
      break
  else:
    ans += 1
print(ans)

Solution (Python):
n, m = map(int,input().split())
X = []
for _ in range(m):
  k, *A = list(map(int,input().split()))
  b = 0
  for a in A:
    b += 1 << (a-1)
  X.append(b)
P = list(map(int,input().split()))

ans = 0
for i in range(1<<n):
  for x, p in zip(X,P):
    y = i & x
    c = bin(y).count("1") % 2
    if c != p:
      break
  else:
    ans += 1
print(ans)

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

ans = 0
for i in range(2**N):
    lamp=0
    for j in range(M):
        switch = 0
        for k in s[j]:
            k-=1
            if i&(1<<k):
                switch^=1
        if switch == p[j]:
            lamp+=1
    if lamp==M:
        ans+=1
print(ans)

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

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

Solution (Python):
import numpy as np

n, m = map(int, input().split())
x = np.array([[0]*(n+1) for i in range(m)])
for i in range(m):
    a = list(map(int, input().split()))
    x[i, 0:(a[0]+1)] = a
    
p = list(map(int, input().split()))
ans = 0

for i in range(2**n):
    switch = []
    counter = 1
    for j in range(n):
        if (i>>j & 1):
            switch.append(j+1)


    for l in range(m):
        set_switch = set(switch) & set(x[l,1:])
        if len(set_switch) % 2 == p[l]:
            counter *= 1
        else:
            counter *= 0
    ans += counter
print(ans)

Solution (Python):
def solve(N, M, K, S, P):
    ret = 0
    for i in range(pow(2, N)):
        turned_on_switches = []
        for j in range(N):
            if i >> j & 1:
                turned_on_switches.append(j)
        for k in range(M):
            kth_turned_on_lights_num = 0
            for s in S[k]:
                kth_turned_on_lights_num += 1 if s - 1 in turned_on_switches else 0
            if kth_turned_on_lights_num % 2 != P[k]:
                break
        else:
            ret += 1
    print(ret)

if __name__ == "__main__":
    N, M = map(int, input().split())
    K = []
    S = []
    for _ in range(M):
        tmp = list(map(int, input().split()))
        K.append(tmp[0])
        S.append(tmp[1:])
    P = list(map(int, input().split()))
    solve(N, M, K, S, P)

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

count = 0
for i in range(0,pow(2,N),1):
    lamps = [0]*(M+1)
    for j in range(1,N+1,1):
        if((i>>(j-1))&1):
            for k in range(0,len(switch[j]),1):
                lamps[switch[j][k]]+=1
    is_OK = True
    for j in range(1,M+1,1):
        if lamps[j]%2 != p[j]:
            is_OK=False
            break
        
    if is_OK:
        count+=1
print(count)

Solution (Python):
from itertools import combinations

N, M = map(int, input().split())
S = []

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

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

for i in range(N+1):
    for c in combinations(range(N), i):
        flag = True
        state = [0] * N
        for n in c:
            state[n] = 1
        for p, s in zip(P,S):
            a = 0
            for k in s:
                a += state[k-1]
            if a % 2 != p:
                flag = False
                break
        
        if flag:
            ans += 1
print(ans)

Solution (Python):
def main():
  n, m = map(int,input().split())
  light = [[0]*n for _ in range(m)]
  for i in range(m):
    kk = list(map(int, input().split()))
    k = kk.pop(0)
    for j in range(k):
      light[i][kk[j]-1] = 1
  p = list(map(int, input().split()))

  ans = 0
  for i in range(2**n): 
    sw = [0]*n
    for j in range(n):
      if ((i >> j) & 1):
        sw[j] = 1

    flag = True
    for j in range(m):
      cnt = 0
      for k in range(n):
        if sw[k] == 1 and light[j][k] == 1:
          cnt += 1
      if cnt % 2 != p[j]:
        flag = False
        break
    if flag:
      ans += 1
    
  print(ans)

if __name__ == '__main__':
  main()

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

ans = 0
for i in range(2**N):
    tmp = 0 
    for idx, light in enumerate(lights):
        on_switch = 0
        for j in range(N):
            if i >> j & 1:
                if j+1 in light:
                    on_switch += 1
        if on_switch % 2 == P[idx]:
            tmp += 1
    if tmp == M:
        ans += 1
print(ans)

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

for i in range(2 ** n):
    all = 1
    switch = [0] * n
    st = bin(i)[2:]
    st = "0" * (n - len(st))+st
    
    for j in range(n):
        if st[j] == "1":
            switch[j] = 1
    for j in range(m):
        tmp = 0
        for check in s[j]:
            if switch[check-1] == 1:
                tmp += 1
        if tmp % 2 != p[j]:
            all *= 0
    if all:
        ans += 1
print(ans)

Solution (Python):
def m():
    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 b in range(1 << N):
        mask = bin(b)[2:].zfill(N)
        light = [False] * M
        for j in range(M):
            on = 0
            for k in range(1, K[j][0] + 1):
                if mask[K[j][k] - 1] == '1':
                    on += 1
            if (on % 2) == P[j]:
                light[j] = True
        if all(light):
            ans += 1
    return ans


print(m())

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

s = bin(0)[2:].zfill(n)
ans = 0

for i in range(2 ** n):
    cnt = 0
    for j in range(m):
        on = 0
        for k in range(1, k_s[j][0] + 1):
            if s[k_s[j][k] - 1] == '1':
                on += 1
            if k == k_s[j][0]:
                if on % 2 == p[j]:
                    cnt += 1
    if cnt == m:
        ans += 1
    s = bin(int(s, 2) + 1)[2:].zfill(n)
print(ans)

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

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

*P, = map(int, input().split())
ans = 0
for i in range(2 ** N):
    
    chk = True
    for m in range(M):
        on_off_cnt = 0
        for s in swi[m]:
            if i >> s & 1:
                on_off_cnt += 1
        if on_off_cnt % 2 != P[m]:
            chk = False
    if chk == True:
        ans += 1
print(ans)