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_list = []
s_list = []
for _ in range(M):
    input_list = list(map(int,input().split()))
    k_list.append(input_list[0])
    s_list.append(input_list[1:])
p_list = list(map(int,input().split()))


on_num_dict = {} 
for m in range(M):
    num_list = [i for i in range(k_list[m]+1) if i%2==p_list[m]]
    on_num_dict[m] = num_list

ans = 0
for i in range(2**N): 
    flag = 1
    bin_list = list(format(i, '0'+str(N)+'b'))
    for m in range(M): 
        on_switch = [int(bin_list[s-1]) for s in s_list[m]] 
        on_switch_num = sum(on_switch)
        if on_switch_num in on_num_dict[m]:
            flag = 1
        else:
            flag = 0
            break
    if flag == 1:
        ans+=1
print(ans)

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

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

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

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

print(ans)

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

switch = []

for _ in range(M):
    k, *sss = list(map(int,input().split()))
    t = 0
    for s in sss:
        t += 1 << (s-1)
    switch.append(t)
    
p = list(map(int,input().split()))


cnt = 0
for i in range(1 << N):
    for sw, pp in zip(switch, p):
        t = i&sw
        c = bin(t).count("1")
        if c % 2 != pp:
            break
    else:
      cnt += 1
print(cnt)

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


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




ans = 0

for i in range(1 << N):
    
    for m in range(M):
        cnt = 0
        for s in S[m]:  
            if i & (1 << (s-1)) != 0:
                cnt += 1
        if cnt % 2 != P[m]:
            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(1 << N):
    
    for m in range(M):
        cnt = 0
        for s in S[m]:  
            if i & (1 << (s-1)) != 0:
                cnt += 1
        if cnt % 2 != P[m]:
            break
    else:
        ans += 1

print(ans)

Solution (Python):
def switches(N: int, M: int, sw: list, P: list)->int:
    count = 1 << N
    sw_state = [0] * N
    li_state = [0] * M
    for i in range(1 << N):
        for j in range(N):
            sw_state[j] = 1 if (i & 1) != 0 else 0
            i >>= 1

        for m in range(M):
            li_state[m] = 0
            for si in sw[m][1:]:
                li_state[m] += sw_state[si-1]

            if li_state[m] % 2 != P[m]:
                break
        else:
            continue

        count -= 1

    return count


if __name__ == "__main__":
    M = 0

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

    ans = switches(N, M, sw, P)
    print(ans)

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

p = list(map(int, input().split()))
ans = 0
for i in range(1<<n):
    p_ = p[:]
    for j in range(n):
        if not (i & (1<<j)):
            continue
        for k in range(m):
            if j+1 in a[k]:
                p_[k] ^= 1
    ans += (max(p_) == 0)
print(ans)

Solution (Python):
n,m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
  ans += 1
  for key,j in enumerate(s):
    on = 0
    for k in j[1:]:  
      if ((i >> (k-1)) & 1):
        on += 1
    if (on % 2) != p[key]:
      ans -= 1
      break
      
print(ans)

Solution (Python):
def hantei(n,m,s,k,p):
  b = 0
  for l in range(m):
    a = 0
    for x in range(k[l][0]):
      a += s[k[l][x+1]-1]
    if a%2 != p[l]:
      b = 1
  if b == 0:
    return True
  else:
    return False

n,m = map(int,input().split())
k = []
for _ in range(m):
  k.append(list(map(int,input().split())))
p = list(map(int,input().split()))
c = 0
for _ in range(2**n):
  s = [0] * n
  ll = len(bin(_))
  for i in range(ll):
    if i >= 2:
      s[n-ll+i] = int(bin(_)[i])
  if hantei(n,m,s,k,p):
    c += 1
print(c)

Solution (Python):

import numpy as np
N, M = map(int, input().split())
L = []
for i in range(M):
    
    *a, = map(int, input().split())
    L.append(a[1:])
*P, = map(int, input().split())

ans = 0
for n in range(2 ** N):
    tmp = np.array([n >> s & 1 for s in range(N)])
    S = []
    for i in L :
        s = sum(tmp[np.array(i) - 1]) % 2
        S.append(s)
    if P == S :
        ans += 1
print(ans)

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

all_on = 0
for sp in itertools.product([0, 1], repeat=n):
    on = 0
    
    for i in range(m):
        cnt = 0
        
        for j in range(len(s[i])):
            if sp[s[i][j]-1] == 1:
                cnt += 1
        
        if cnt % 2 == p[i]:
            on += 1
    
    if on == m:
        all_on += 1

print(all_on)

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

ans = 0

for bit in range((1 << N)) :
    A = []
    for k in range(N) :
        if bit & (1 << k) :
            A.append(k)
    
    for i in range(M) :
        cnt = 0
        for j in range(len(S[i])) :
            if S[i][j] in A :
                cnt += 1
        if (cnt % 2) != P[i] :
            break
    else :
        ans += 1
print(ans)

Solution (Python):

import numpy as np

N, M = map(int, input().split())
T = [[0 for i in range(M)] for j in range(N)]
for i in range(M):
        S = list(map(int, input().split()))
        for k in range(S[0]):
                T[S[k+1]-1][i] = 1


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

ans = 0
for k in range(2**N):
        Q = np.array([0 for val in range(M)])
        for j in range(N):
                if bin(k >> j)[-1] == '1':
                        Q += np.array(T[j])
                        Q = Q % 2

        if list(Q) == P:
                ans += 1

print(ans)

Solution (Python):
from itertools import product


def state_brute_force(state, count):
    state_list = [state for _ in range(count)]
    for s in product(*state_list):
        yield s


num_switch, num_lamp = map(int, input().split())
switches = [[0] * num_switch for _ in range(num_lamp)]

for n in range(num_lamp):
    i, *s = map(int, input().split())
    for si in s:
        switches[n][si - 1] = 1
condition = list(map(int, input().split()))

ans = 0
for on_off in state_brute_force([0, 1], num_switch):
    lamp_on = 0
    for i, lamp_switch in enumerate(switches):
        on_s = [si & state == 1 for si, state in zip(lamp_switch, on_off)]
        if on_s.count(True) % 2 == condition[i]:
            lamp_on += 1
    if lamp_on == num_lamp:
        ans += 1

print(ans)

Solution (Python):
n,m = map(int,input().split())
switch = []
for i in range(m):
    switch.append([i for i in map(int,input().split())])
amari = [i for i in map(int,input().split())]
a = 0
for i in range(2**n) :
    cnt = []
    for j in range(n):
        if ((i >> j)& 1) :
            p = j + 1
            cnt.append(p)

    ans = 0
    for h in range(m):
        count = 0
        for p in range(switch[h][0]) :
            if switch[h][p+1] in cnt :
                count += 1
        if count % 2 == amari[h] : ans += 1
    if ans == m:
        a += 1
print(a)

Solution (Python):
import itertools

N, M = map(int, input().split())
switches = []
for i in range(M):
    swi = input().split()
    swi = [int(x)-1 for x in swi][1:]
    switches.append(swi)
    
needs = [int(x) for x in input().split()]

ans = 0
def checkLightsUp(swi_ptn):
    for i in range(M):
        need = needs[i]
        cnt = 0
        for s in switches[i]:
            if swi_ptn[s] == 1:
                cnt  += 1
        if cnt % 2 != need:
            return False
    return True

for swi_ptn in itertools.product([0, 1], repeat=N):
    if checkLightsUp(list(swi_ptn)):
        ans += 1
print(ans)

Solution (Python):
def main():
    N, M = map(int, input().split())
    A = [0] * N
    for i in range(M):
        for s in list(map(int, input().split()))[1:]:
            A[s - 1] |= 1 << i
    p = 0
    for i, j in enumerate(list(map(int, input().split()))):
        p |= j << i
    ans = 0
    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)


main()

Solution (Python):
def main():
    N, M = map(int, input().split())
    A = [0] * N
    for i in range(M):
        ks = list(map(int, input().split()))
        for s in ks[1:]:
            A[s - 1] |= 1 << i
    p = 0
    for i, j in enumerate(list(map(int, input().split()))):
        p |= j << i
    ans = 0
    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)


main()

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

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

x = 0
import copy


for switch_cond in range(2**n):
    s = []

    for i in range(n):
        if switch_cond%2 == 0:
            s.append("off")
            switch_cond = switch_cond//2
        else:
            s.append("on")
            switch_cond = (switch_cond-1)//2
    for j in range(m):
        ss = copy.deepcopy(s)
        for r in range(n):
            if r+1 not in t[j][1:]:
                ss[r]="off"           
        if (ss.count("on"))%2 != p[j]:
            break
    else:
        x += 1
print(x)

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

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

x = 0
import copy


for switch_cond in range(2**n):
    s = []

    for i in range(n):
        if switch_cond%2 == 0:
            s.append("off")
            switch_cond = switch_cond//2
        else:
            s.append("on")
            switch_cond = (switch_cond-1)//2
    
    for j in range(m):
        ss = copy.deepcopy(s)
        for r in range(n):
            if r+1 not in t[j][1:]:
                ss[r]="off"
        
        
        
              
        if (ss.count("on"))%2 != p[j]:
            
            break
    else:
        
        x += 1
print(x)

Solution (Python):
import itertools
 
N, M = map(int, input().split())
 
S = []
for i in range(M):
    k, *s = map(int, input().split())
    S.append(s)
    
P = [int(i) for i in input().split()]
 
A = [0, 1]
ans = 0
for i in itertools.product(A, repeat = N):
    flag = 0
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i[s - 1] == 1:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
        
print(ans)

Solution (Python):



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

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

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

ret = 0
all = [(str(bin(i)))[2:].zfill(n) for i in range(2 ** n)]
all = [[int(i) for i in case] for case in all]
for case in all:
    flag = 0
    for num,i in enumerate(s):
        if flag == 1:
            continue

        sw = [0 for z in range(n)]
        for k in i[1:]:
            sw[k-1] = 1

        if (sum(i*j for i,j in zip(sw,case)) % 2) != p[num]:
            flag = 1
           
    if flag == 0:
        ret += 1

print(ret)

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

ans = 0
for i in range(2**n):
	flag = True
	for j in range(m):
		res = 0
		for k in ks[j][1:]:
			res += (i//(2**(k-1)))&1
		if res%2 != p[j]:
			flag = False
	if flag == True:
		ans += 1
print(ans)

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

key='{:0'+str(N)+"b}"
for k in range(2**N):
    
    switch=list(key.format(k))
    for i in range(M):
        odd=1
        even=0
        if P[i]==1:
            odd=0
            for j in range(X[i][0]):
                odd+=int(switch[ X[i][j+1]-1] )
            if odd%2==0:
                break
            
        else:
            even=0
            for j in range(X[i][0]):
                even+=int(switch[ X[i][j+1]-1] )
            if even%2==1:
                break
    
    if odd%2==1 and even%2==0:
        ans+=1
        
            
print(ans)

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

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

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


c = 0
for i in range(2 ** N):
    b = []
    for j in range(N):
        b.append(i >> j & 1 > 0)
    flag = True
    for j in range(M):
        cc = 0
        for ss in s[j]:
            if b[ss-1]:
                cc += 1
        if cc % 2 != p[j]:
            flag = False
            break
    if flag:
        c += 1
print(c)

Solution (Python):
import numpy as np
import itertools as ittr

def test_switch(e_balls, sw, p):
    for i, e_ball in enumerate(e_balls):
        n_on = np.sum(sw[e_ball - 1])
        
        if p[i] != (n_on % 2):
            return False
    
    return True

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

e_balls = []

for m in range(M):
    e_balls.append(np.asarray([int(si) for si in input().split()[1:]]))

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

cnt = 0

for sw in ittr.product([0, 1], repeat = N):
    if test_switch(e_balls, np.array(sw), p):
        cnt += 1

print(cnt)

Solution (Python):
import numpy as np
import itertools as ittr

def test_switch(e_balls, sw, p):
    for i, e_ball in enumerate(e_balls):
        n_on = np.sum(sw[e_ball - 1])
        
        if p[i] != (n_on % 2):
            return False
    
    return True

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

e_balls = []

for m in range(M):
    i = input().split()
    s = [int(si) for si in i[1:]]
    e_balls.append(np.asarray(s))

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

cnt = 0

for sw in ittr.product([0, 1], repeat = N):
    if test_switch(e_balls, np.array(sw), p):
        cnt += 1

print(cnt)

Solution (Python):
import numpy as np
import itertools as ittr

def test_switch(e_balls, sw, p):
    for i, e_ball in enumerate(e_balls):
        si = sw[e_ball - 1]
        
        if p[i] != (np.sum(si == 1) % 2):
            return False
    
    return True

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

e_balls = []

for m in range(M):
    i = input().split()
    s = [int(si) for si in i[1:]]
    e_balls.append(np.asarray(s))

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

cnt = 0

for sw in ittr.product([0, 1], repeat = N):
    if test_switch(e_balls, np.array(sw), p):
        cnt += 1

print(cnt)

Solution (Python):
import numpy as np
import itertools as ittr

def test_switch(e_balls, sw, p):
    for i, e_ball in enumerate(e_balls):
        eb = np.asarray(e_ball)
        si = sw[eb - 1]
        
        if p[i] != (np.sum(si == 1) % 2):
            return False
    
    return True

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

e_balls = []

for m in range(M):
    i = input().split()
    s = [int(si) for si in i[1:]]
    e_balls.append(s[:])

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

cnt = 0

for sw in ittr.product([0, 1], repeat = N):
    if test_switch(e_balls, np.array(sw), p):
        cnt += 1

print(cnt)

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

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

if m==1:
    p = [int(input())]
else:
    p = list(map(int, input().split()))



def check(g,en):
    stack = ["1", "0"]
    candi = []
    while stack:
        cur = stack.pop()
        if len(cur) == en:
            candi.append(cur)
            continue
        for i in g[len(cur)+1]:
            tmp = cur+i
            stack.append(tmp)
    return candi

g={}
for i in range(0,n+1):
    g[i]=["1", "0"]

ans = 0

for i in check(g,n):
    flag=0
    for j in range(m):
        tmp=0
        for k in range(0,len(li[j])):
            tmp += int(i[li[j][k]-1])
        if tmp % 2 != p[j]:
            flag=1
            break
    if flag==0:
        
        ans += 1

print(ans)

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


for i in range(1 << n):
    check = True
    for j in range(m):
        cnt = 0
        for l in range(1, len(k[j])):
            cnt += (i>>(k[j][l]-1))&1
        if cnt%2 != p[j]:
            check = False
    if check == True:
        ans += 1

print (ans)

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

ans = 0

for i in range(1 << N):
    cnt_on = [0]*M
    for j in range(N):
        if ((i >> j) & 1) == 1:
            for m in range(M):
                cnt_on[m] += ks[m][1:].count(j+1)

    c = 0
    for m in range(M):
        if cnt_on[m]%2 == p[m]:
            c += 1
    
    if c == M:
        ans += 1


print(ans)

Solution (Python):

n, m = map(int, input().split())
s = [None] * m
for i in range(m):
    k, *s[i] = map(lambda x: int(x) - 1, input().split())
p = list(map(int, input().split()))
ans = 0
for b in range(1 << n):
    f = True
    for i in range(m):
        cnt = sum(b >> x & 1 for x in s[i])
        f &= (cnt % 2 == p[i])
    ans += f
print(ans)

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    bulbs = []
    for _ in range(M):
        b = tuple(map(int, input().split()))
        bulbs.append(b[1:])

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

    ans = 0
    for switch in range(2**N):
        check = [0] * M
        for i, bulb in enumerate(bulbs):
            cnt = 0
            for b in bulb:
                if switch >> (b - 1) & 1:
                    cnt += 1

            if cnt % 2 == P[i]:
                check[i] = True
            else:
                check[i] = False

        if all(check):
            ans += 1

    return ans


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

Solution (Python):
import itertools


N, M = map(int, input().split())
connected_switches = [[int(x) - 1 for x in input().split()[1:]] for x in range(M)]
conditions = list(map(int, input().split()))

ok = 0
for patterns in itertools.product((0, 1), repeat=N):
    patterns = list(patterns)
    is_lighting = True
    for i, lights in enumerate(connected_switches):
        turned_sw = sum([patterns[x] for x in lights])
        if turned_sw % 2 != conditions[i]:
            is_lighting = False
            break
    if is_lighting:
        ok += 1

print(ok)

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(1<<n):
    isok=True
    for j in range(m):
        cnt = 0
        for k in range(1,len(ks[j])):
            cnt += (i>>(ks[j][k]-1))&1
        if cnt%2 != p[j]:
            isok = False
            break
    if isok:
        ans += 1
print(ans)

Solution (Python):
(n,m),*s,p=[list(map(int,t.split()))for t in open(0)]
a=0
for i in range(1<<n):
 c=[0]*m
 for j in range(n*m):c[j%m]^=i>>j//m&(j//m+1in s[j%m][1:])
 a+=c==p
print(a)

Solution (Python):
(n,m),*s,p=[list(map(int,t.split()))for t in open(0)]
a=0
for i in range(1<<n):
 c=[0]*m
 for j in range(n*m):c[j%m]^=i>>j//m&(j//m+1in s[j%m][1:])
 a+=all(j==i for i,j in zip(c,p))
print(a)

Solution (Python):
[input_n, input_m] = map(int, input().split())

input_ks = [list(map(int, input().split())) for i in range(input_m)]
input_p = list(map(int, input().split()))

switch_list = [[bool(i & 2 ** j) for j in range(input_n)]
               for i in range(2 ** input_n)]

count = len(switch_list)
for switch in switch_list:
    for m in range(input_m):
        if ((sum(switch[l - 1] for l in input_ks[m][1:])-input_p[m]) % 2):
            count -= 1
            break
print(count)

Solution (Python):
(n,m),*s,p=[list(map(int,t.split()))for t in open(0)]
a=0
for i in range(1<<n):
 c=[0]*m
 for j in range(n*m):c[j%m]+=i>>j//m&(j//m+1in s[j%m][1:])
 a+=all(j==i%2for i,j in zip(c,p))
print(a)

Solution (Python):
(n,m),*s,p=[list(map(int,t.split()))for t in open(0)]
a=0
r=range
for i in r(1<<n):
 c=[0]*m
 for j in r(n*m):j,k=j//m,j%m;c[k]+=i>>j&(j+1in s[k][1:])
 a+=all(j==i%2for i,j in zip(c,p))
print(a)

Solution (Python):
(n,m),*s,p=[list(map(int,t.split()))for t in open(0)]
a=0
r=range
for i in r(1<<n):
 c=[0]*m
 for j in r(n):
  for k in r(m):c[k]+=i>>j&(j+1in s[k][1:])
 a+=all(j==i%2for i,j in zip(c,p))
print(a)

Solution (Python):
I=lambda:list(map(int,input().split()))
n,m=I()
*s,p=eval('I(),'*-~m)
a=0
r=range
for i in r(1<<n):
 c=[0]*m
 for j in r(n):
  for k in r(m):c[k]+=i>>j&(j+1in s[k][1:])
 a+=all(j==i%2for i,j in zip(c,p))
print(a)

Solution (Python):
[input_n, input_m] = map(int, input().split())

input_ks = [list(map(int, input().split())) for i in range(input_m)]
input_p = list(map(int, input().split()))

switch_list = [[bool(i & 2 ** j) for j in range(input_n)]
               for i in range(2 ** input_n)]

count = 0
for switch in switch_list:
    switchPattern = []
    for m in range(input_m):
        switchPattern.append(sum(switch[l - 1] for l in input_ks[m][1:]) %2 == input_p[m])
    if (all(switchPattern)):
        count += 1
print(count)

Solution (Python):
I=lambda:list(map(int,input().split()))
n,m=I()
s=eval('I(),'*m)
p=I()
a=0
r=range
for i in r(1<<n):
 c=[0]*m
 for j in r(n):
  for k in r(m):c[k]+=i>>j&(j+1in s[k][1:])
 a+=all(j==i%2for i,j in zip(c,p))
print(a)

Solution (Python):
[N,M] = list(map(int,input().split()))
K = []
S = []
for i in range(M):
  x = list(map(int,input().split()))
  K.append(x[0])
  S.append(x[1:])
P = list(map(int,input().split()))
ans = 0
for ms in range(1 << N):
  cnt = 0
  for i in range(M):
    sum = 0
    for v in S[i]:
      if (ms >> (v-1)) & 1:
        sum += 1
    if sum % 2 == P[i]:
      cnt += 1
  if cnt == M:
    ans += 1
print(ans)

Solution (Python):
N, M = map(int, input().split())
k = []
lis = []
P = []
for _ in range(M):
    x = list(map(int, input().split()))
    k.append(x[0])
    lis.append(x[1:])
for p in map(int, input().split()):
    P.append(p)
count = 0
for i in range(2**N):
    flag = True
    string = str(bin(i)[2:])[::-1]
    for index in range(M):
        total = 0
        for s in lis[index]:
            if s <= len(string):
                if string[s - 1] == '1':
                    total += 1
        if total % 2 != P[index]:
            flag = False
            break
    if flag:
        count += 1
print(count)

Solution (Python):
import numpy as np
N, M = map(int, input().split())
mat = np.zeros((M,N))
for i in range(M):
    slist = list(map(int, input().split()))
    for j in slist[1:]:
        mat[i,j-1] = 1
plist = list(map(int, input().split()))
mat = np.append(mat, np.array([plist]).T, axis=1)

def power_set(N):
    p_sets = [[]]
    item = [i for i in range(N)]
    for i in item:
        temp = []
        for j in p_sets:
            temp += [ j+[i] ]
        p_sets += temp
    return p_sets

ret = 0
for swi in power_set(N):
    tm_mat = mat[:,swi+[N]]
    if sum([(np.sum(i) % 2) == 0 for i in tm_mat]) == M:
        ret += 1
print(ret)

Solution (Python):
n, m = [int(_) for _ in input().split()]
b = [[int(_) for _ in input().split()] for __ in range(m)]
p = [int(_) for _ in input().split()]
ans = 0
for i in range(2**n):
    s = format(i, '0'+str(n)+'b')
    for j in range(m):
        on = 0
        for k in range(b[j][0]):
          on += int(s[b[j][k+1]-1])
        on %= 2
        if p[j] != on:
          break
    else : 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 i in range(2 ** N):
	ptn = bin(i)[2:].rjust(N, "0")  
	light = True  
	for j in range(M):
		tmp = 0  
		for n in range(1, s[j][0] + 1):
			if ptn[s[j][n] - 1] == "1":
				tmp += 1
		if tmp % 2 != p[j] % 2:
			light = False
	if light:
		ans += 1

print(ans)

Solution (Python):
import math
from functools import reduce
from collections import deque

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,m = get_nums_l()

lamps = []
for i in range(m):
    lamps.append(get_nums_l()[1:])

p = get_nums_l()

ans = 0

for x in range(2**n):
    ok = True
    for ri,r in enumerate(lamps):
        count = 0
        for a in r:
            count += x&(2**(a-1)) > 0
        if count%2 != p[ri]:
            ok = False
            break
    if ok:
        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 i in range(2 ** N):
	x = bin(i)[2:].rjust(N, "0")
	light = True  
	for j in range(M):
		tmp = 0  
		for k in range(1, s[j][0] + 1):
			if x[s[j][k] - 1] == "1":
				tmp += 1
		if tmp % 2 != p[j] % 2:
			light = False
	if light:
		ans += 1
print(ans)

Solution (Python):

import sys
from itertools import product

input = sys.stdin.readline


n, m = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(m)]
con = list(map(int, input().rstrip().split()))
ans = 0
for i in product(range(2), repeat=n):
    cnt = 0
    for j in range(m):
        ons = 0
        for k in lst[j][1:]:
            if i[k - 1] == 1:
                ons += 1
        if ons % 2 == con[j]:
            cnt += 1
    if cnt == m:
        ans += 1
print(ans)

Solution (Python):



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

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

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

cnt = 0
for i in range(1024):
    x = format(i,"010b")[::-1]
    if n < 10 and x[n] == "1":
        break
    
    for j in range(m):
        tmpSum = 0
        for k in s[j]:
            tmpSum += int(x[k-1])
        if tmpSum%2 is not p[j]:
            break
    else:
        cnt += 1

print(cnt)

Solution (Python):
N, M = map(int, input().split(" "))
botlist = []
ans = 0
for n in range(M):
    bot = list(map(int, input().split(" ")))
    
    botlist.append(bot)

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

pushlist = [[]for i in range(2**N)]

for p in range(N):
    for q in range(2**N):
        if q % (2**(p+1)) <2**p:
            pushlist[q].append(0)
        else:
            pushlist[q].append(1) 

for A in pushlist:
    
    g = 0
    faa = 0
    for B in botlist:
        g += 1
        cou = 0
        for c in range(B[0]):
            cou += A[B[c+1]-1]

        if cou % 2 == plist[g-1]:
            faa += 1
    if faa == M:
        ans += 1
    

print(ans)

Solution (Python):
import numpy as np

N, M = map(int, input().split())
lamplist = [0]*M
for i in range(M):
    A = list(map(int, input().split()))
    lamplist[i] = A
oddeven_ans = list(map(int, input().split()))

switch = np.zeros(N)
ans = 0
numofswitch = np.zeros(M)

for s in range(M):
    numofswitch[s] = lamplist[s][0]
    del lamplist[s][0]

for j in range(2 ** N):
    ansflag = 0

    for k in range(N):
        switch[k] = j % 2
        j //= 2
    for p in range(M):
        numofshining = 0
        for r in lamplist[p]:
            if switch[r-1] == 1:
                numofshining += 1

        if numofshining % 2 != oddeven_ans[p]:
            ansflag = 1
    if ansflag == 0:
        ans += 1

print("{}".format(ans))

Solution (Python):
N, M = map(int, input().split())
k = []
lis = []
P = []
for _ in range(M):
    x = list(map(int, input().split()))
    k.append(x[0])
    lis.append(x[1:])
for p in map(int, input().split()):
    P.append(p)
count = 0
for i in range(2**N):
    flag = True
    Switch = [False] * (N+1)
    string = str(bin(i)[2:])
    for index, s in enumerate(string[::-1]):
        if s == '1':
            Switch[index + 1] = True
    for index in range(M):
        total = 0
        for s in lis[index]:
            if Switch[s]:
                total += 1
        if total % 2 != P[index]:
            flag = False
            break
    if flag:
        count += 1
print(count)

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

p_list = list(map(int, input().split()))
count = 0
for i in range(2**n):
  s_str = format(i, 'b').zfill(n)
  for j in range(len(k_list)):
    on = 0
    for s in k_list[j]:
      on += int(s_str[s-1])
    if on % 2 != p_list[j]:
      break
  else:
    count += 1

print(count)