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):
from collections import defaultdict

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

s = defaultdict(list)
for i in range(M):
    tmp = [int(x) for x in input().split()]
    s[i] = set(tmp[1:])
p = [int(x) for x in input().split()]

ans = 0
for i in range(1 << N):
    ptn = set()
    for j in range(N):
        if i & (1 << j):
            ptn.add(j + 1)

    flag = True
    for k in range(M):
        c = len(s[k] & ptn) % 2
        if c != p[k]:
            flag = False
            break

    if flag:
        ans += 1
print(ans)

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

num = 2**N
ans = 0
for i in range(num):
    bit = bin(i)[2:].zfill(N)
    on, off = [], []
    ret = 0
    for j, b in enumerate(bit):
        j += 1
        if b == '1':
            on.append(j)
        else:
            off.append(j)
    for k in range(M):
        on = set(on)
        onon = set(K[k][1:])
        if len(on & onon) % 2 == P[k]:
            ret += 1
    if ret == M:
        ans += 1

print(ans)

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

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

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

cnt = 0

for i in range(2 ** n):
    bin_i = '{:010b}'.format(i)[::-1]

    for i in range(m):
        ks = kss[i]
        k = ks[0]
        s = ks[1:]

        sum_s = 0

        for j in range(k):
            sum_s += int(bin_i[s[j]-1])

        if sum_s % 2 != p[i]:
            break
    else:
        cnt += 1

print(cnt)

Solution (Python):
from itertools import product


def li():
    return list(map(int, input().split()))


def is_on(state, p, s_list):
    return sum(list(map(lambda x: state[x - 1], s_list))) % 2 == p


if __name__ == '__main__':
    [n, m] = li()
    ks_list = [li() for _ in range(m)]
    p_list = li()

    pattern = 0

    for state in product([0, 1], repeat=n):
        is_all = True
        for index, ks in enumerate(ks_list):
            if not is_on(state, p_list[index], ks[1:]):
                is_all = False
        if is_all:
            pattern = pattern + 1
    print(pattern)

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

    ans = 0
    for i in range(2 ** N):
        st = [(i >> j) & 1 for j in range(N)]
        for j in range(M):
            
            if sum([st[k-1] for k in S[j]]) % 2 != P[j]:
                break
        else:
            ans += 1

    print(ans)

solve()

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

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

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


ans=0
for i in range(2**N):
	ons=[]
	for j in range(N):
		if (i//(2**j))%2:
			ons.append(j+1)
	
	for j in range(M):
		c=0
		for k in range(len(s[j])):
			if s[j][k] in ons:
				c+=1
		
		flag=0
		if c%2!=p[j]:
			flag=1
			break
	if flag:
		continue
	else: ans+=1


print(ans)

Solution (Python):


def read_input():
    n, m = map(int, input().split())

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

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

    return n, m, slist, p


def switch_gen(n):
    curr = 0

    while True:
        bincurr = bin(curr)[2:]

        if len(bincurr) > n:
            return None
        bincurr = [int(c) for c in bincurr]
        t = [0] * (n - len(bincurr))
        t.extend(bincurr)
        yield t

        curr += 1


def check_condition(switch, slist, plist):
    for s, p in zip(slist, plist):
        count = 0
        for i in s[1]:
            if switch[i - 1] == 1:
                count += 1

        if count % 2 != p:
            return False

    return True


def submit():
    n, m, slist, p = read_input()

    count = 0
    for switch in switch_gen(n):
        if check_condition(switch, slist, p):
            count += 1

    print(count)




if __name__ == '__main__':
    submit()

Solution (Python):
import numpy as np
import itertools

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

ss = []
for i in range(m):
	tmp = list(map(int, input().split()))
	s = [0 for _ in range(n)]
	for t in tmp[1:]:
		s[t - 1] = 1
	ss.append(s)
ss = np.array(ss)


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

ans = 0
for x in itertools.product(range(2), repeat = n):
	lights = np.dot(ss, np.array(x))
	if sum([1 for i in range(m) if lights[i] % 2 == ps[i]]) == m:
		ans += 1

print(ans)

Solution (Python):
from itertools import product

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

Ss = []
for i in range(M):
    Ss.append([int(x) for x in input().split()][1:])

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

c = 0
for onoff in product([0,1], repeat=N):
    d = 0
    for i, S in enumerate(Ss):
        t = sum(onoff[s-1] for s in S)
        if t % 2 == Ps[i]:
            d += 1
    if d == M:
        
        c+=1
print(c)

Solution (Python):



def readInt():
    return int(input())

def readList():
    return list(input().split())

def readListI():
    return list(map(int, input().split()))

def pattern(n):
    ret = []
    for i in range(pow(2, n)):
        p = [0 for _ in range(n)]
        for j in range(n):
            if (i >> j) & 1:
                p[j] = 1
        ret.append(p)
    return ret

def main():
    n, m = readListI()
    lk = []
    lls = []
    for _ in range(m):
        d = readListI()
        k = d[0]
        ls = [s-1 for s in d[1:]]
        lk.append(k)
        lls.append(ls)
    lp = readListI()
    ret = 0
    for p in pattern(n):
        ok = True
        for i, ls in enumerate(lls):
            if sum(p[s] for s in ls) % 2 != lp[i]:
                ok = False
                break
        if ok:
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()

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

p=list(map(int,input().split()))
ans=0
for i in range(2**n):
  a=[]
  for _ in range(n):
    a+=[i%2]
    i//=2
  
  pp=1
  for j in range(m):
    num=0
    for si in s[j][1:]:
      if a[si-1]==1:
        num+=1
    
    if num%2!=p[j]:
      pp=0
  if pp==1:
    ans+=1
print(ans)

Solution (Python):
import sys

readline = sys.stdin.readline

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

k, s = [], []

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

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

total = 0
for bits in range(0, 2 ** N):
    flag = True
    for i in range(M):
        bsum = 0
        for b in s[i]:
            bsum += ((bits >> (b - 1)) & 1)
        flag = flag and (bsum % 2 == p[i])
    if flag:
        total += 1

print(total)

Solution (Python):
n,m = map(int,input().split())
sw = []
for i in range(m):
    L = list(map(int,input().split()))
    L.pop(0)
    sw.append(L)
p = list(map(int,input().split()))
def s(x,N):
    LI = []
    for i in range(N):
        A = x % (2**(N-i))
        B = A // (2**(N-1-i))
        if B == 1:
            LI.append(i+1)
    return LI
ans = 0
for i in range(2**n):
    ansl = []
    for j in range(m):
        C = list(set(sw[j]) & set(s(i,n)))
        if len(C) % 2 == p[j]:
            ansl.append(1)
    if len(ansl) == m:
        ans += 1
print(ans)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

N,M = map(int,input().split())
k = [0 for i in range(M)]
s = [[] for i in range(M)]
for i in range(M):
    input_list = [int(i) for i in input().split()]
    k[i] = input_list[0]
    s[i] = input_list[1:]

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

def tobinary(i):
    l = [0 for j in range(N)]
    for k in range(N):
        l[k] = i % 2
        i //= 2
    return l

ans = 0
for i in range(2**N):
    swich = tobinary(i)
    for m in range(M):
        cnt = 0
        for k_i in range(k[m]):
            if swich[s[m][k_i]-1]:
                cnt += 1
        if cnt % 2 == p[m]:
            blight = True
        else:
            blight = False
            break
    if blight == True:
        ans += 1

print(ans)

Solution (Python):
import numpy as np
from collections import defaultdict
from functools import reduce
from itertools import product




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

light = defaultdict(list)

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

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


for state in product([0,1], repeat=n):
    for i in range(m):
        if len(list(filter(lambda s: state[s] == 1, light[i])))%2 != p[i]:
            break
    else:
        res += 1

print(res)

Solution (Python):
from collections import defaultdict

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

S = defaultdict(list)

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

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

ans = 0
for i in range(int(pow(2,N))):
    u = i
    s_list = [0 for i in range(M)]
    for j in range(1,N+1):
        if u%2==1:
            for s in S[j]:
                s_list[s] += 1
        u//=2
    is_tento = True
    for s in range(M):
        if s_list[s]%2!=P[s]:
            is_tento = False
            break
    if is_tento:ans += 1

print(ans)

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

flgs = [0]*M
for i in range(M):
	k,*vals = map(int,input().split())
	for v in vals:
		flgs[i] |= 1 << (v-1)

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

cnt = 0
for bit in range(2**N):
	cnt_tmp = 1
	for i,f in enumerate(flgs):
		if len([j for j in range(N) if ((f&bit) & (1<< j)) != 0]) % 2 != p[i]:
			cnt_tmp = 0
	cnt += cnt_tmp
print(cnt)

Solution (Python):
import itertools
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
ks = []
for i in range(M):
    ks.append(inpl())
p = inpl()

ans = 0
for s in itertools.product(range(2),repeat=N):
    for i in range(M):
        if (sum([ s[n-1] for n in ks[i][1:]]) - p[i]) % 2:
            break
    else:
        ans += 1

print(ans)

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
import math


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    ret = math.factorial(x)
    ret = ret // (math.factorial(x - y) * math.factorial(y))

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)





def calc_bitcount(switch_pattern, bit):
    x = switch_pattern & bit
    ret = 0
    while x:
        if x & 1:
            ret += 1
        x >>= 1
    return ret


def main():
    n, m = intin()
    kslistlist = []
    for i in range(m):
        kslistlist.append(intina())
    plist = intina()

    light_to_bit = defaultdict(int)
    for light, kslist in enumerate(kslistlist):
        for switch in kslist[1:]:
            light_to_bit[light] |= (1<<(switch - 1))

    ans = 0

    for switch_pattern in range(2**n):
        for light, bit in light_to_bit.items():
            bitcount = calc_bitcount(switch_pattern, bit)
            if bitcount & 1 != plist[light]:
                break
        else:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

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

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

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


def D2NC(D: int, N: int, link=False) -> list:
    """
    10進数表記の数字をN進数表記に変換する。
    (関数名は"Decimal to N_ary Converter"の略。)

    Parameters
    ----------
    D : 10進数表記で与えられた数字。
    N : 変換したい底。
    link : Trueにすると結果を文字列結合して返す。

    Returns
    -------
    res : 変換結果。デフォルトではリスト化して返す。
    """
    alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    res = []
    while D > 0:
        if D % N > 9:
            tmp = alp[D % N - 10]
            res.insert(0, str(tmp))
        else:
            res.insert(0, str(D % N))
        D //= N
    if not res:
        res.append('0')
    if link:
        res = ''.join(res)
    return res


digit = N

ans = 0
for i in range(2**N):
    switch = D2NC(i, 2, True).zfill(digit)
    idx = 0
    flg = 1
    for i in ks:
        ct = 0
        for j in i[1:]:
            if switch[j-1] == '1':
                ct += 1
        if ct % 2 != p[idx]:
            flg = 0
            break
        idx += 1
    if flg:
        ans += 1
print(ans)

Solution (Python):
read = input 
rn = lambda :list(map(int, read().split()))
n,m = rn()
S = []
for i in range(m):
    ks = rn()
    s = ks[1:]
    s = list(map(lambda x:x-1, s))
    S.append(s)
P = rn()
ans = 0
for i in range(1<<n):
    flag = True
    for p, s in zip(P,S):
        cnt = 0
        for swc in s:
            if (1<<swc) & i >0:
                cnt +=1
        if cnt % 2 != p:
            flag = False
            break;

    if flag: 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(' ')))

ans = 0
for i in range(2 ** N) :
    add = True
    for j in range(M) :
        k = K[j]
        cnt = 0
        for s in k[1:] :
            if (1 << (s - 1)) & i > 0 :
                cnt += 1
        if cnt % 2 == P[j] :
            pass
        else :
            add = False
            break
    if add :
        ans += 1

print(ans)

Solution (Python):
def inpl():
    return list(map(int, input().split()))


def isAllOn(pattern):
    for i, s in enumerate(S):
        on = 0
        for k in s[1:]:
            if (pattern >> (k - 1)) % 2 == 1:
                on += 1
        
        if on % 2 != P[i]:
            return False
    return True


N, M = inpl()

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

ans = 0
for pattern in range(2**N):
    if isAllOn(pattern) is True:
        ans += 1

print(ans)

Solution (Python):
n, m = map(int, input().split())
memo = []
ans = 0
for i in range(m):
    a = list(map(int, input().split()))
    b = [0]*n
    for j in range(a[0]):
        b[a[j+1]-1] = 1
    memo.append(b)
clear = list(map(int, input().split()))
for i in range(2 ** n):
    now = []
    for j in range(n):
        now.append((i // (2 ** j)) % 2)
    for j in range(m):
        t = 0
        for k in range(n):
            t += memo[j][k] * now[k]
        if t % 2 != clear[j]:
            break
    else:
        ans += 1
print(ans)

Solution (Python):
import itertools

wl, gl = tuple(map(int,input().split()))

class G:
    def __init__(self):
        self.kantis = [False for _ in range(wl)]
        self.mo = 0
    def match(self,wstates):
        re = 0
        for kanti,wstate in zip(self.kantis,wstates):
            if kanti and wstate:
                re += 1
        return re % 2 == self.mo

gs = []
for gi in range(gl):
    g = G()
    kantiwis = list(map(int,input().split()))
    kantiwis = kantiwis[1:]
    for kantiwi in kantiwis:
        kantiwi -= 1
        g.kantis[kantiwi] = True
    gs.append(g)

mos = list(map(int,input().split()))
for gi in range(gl):
    gs[gi].mo=mos[gi]


re = 0
for wstates in itertools.product([True,False], repeat=wl):
    ok = True
    for g in gs:
        if not g.match(wstates):
            ok = False
            break
    if ok:
        re += 1

print(re)

Solution (Python):



def solve():
    n, m = map(int, input().split())
    ks = []
    for i in range(m):
        tks = [int(j) for j in input().split()]
        ks.append(tks[1:])
    ps = [int(i) for i in input().split()]
    ans = 0
    for i in range(2 ** n):
        t = []
        idx = 1
        while i > 0:
            if i & 1 == 1:
                t.append(idx)
            idx += 1
            i >>= 1
        for j in range(m):
            cnt = 0
            for k in ks[j]:
                if k in t:
                    cnt += 1
            if cnt % 2 != ps[j]:
                break
        else:
            ans += 1
    print(ans)

if __name__=="__main__":
    solve()

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()))
flag = [False for i in range(n)]
ans = 0
for bit in range(1 << n):
    a = True

    for i in range(n):
        if bit & (1 << i):
            flag[i] = True
        else:
            flag[i] = False
    for i in range(m):
        count = 0
        for j in range(len(ks[i])):
            if j == 0:
                continue
            if flag[ks[i][j] - 1]:
                count += 1
        if count % 2 != p[i]:
            a = False
    if a:
        ans += 1
print(ans)

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

ans = 0
for i in range(2 ** n):
    x = format(i, '0' + str(n) +'b')
    for j in range(m):
        q = 0
        for idx in s[j][1:]:
            if x[idx - 1] == '1':
                q += 1
        if q % 2 != p[j]:
            ans -= 1
            break
    ans += 1
print(ans)

Solution (Python):
from itertools import product,chain
from functools import reduce
from operator import xor
N,M = map(int,input().split())

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

cnt = 0
for c in product((False,True), repeat=N):
    if all(not reduce(xor, (c[i-1] for i in l))^p for l,p in zip(lights, P)):
        cnt += 1

print(cnt)

Solution (Python):
N, M = [int(c) for c in input().split()]

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

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

sw = [0]*N
n = [0]

def f(i):
    if i==N:
        n[0]+=check()        
    else:
        sw[i]=0
        f(i+1)
        sw[i]=1
        f(i+1)

def check():
    all_light = True
    for s_m, p_m in zip(s,p):
        d=0
        for ss in s_m:
            d += sw[ss-1]
        if d%2 != p_m:
            all_light = False
            break
    return 1 if all_light else 0
            
f(0)

print(n[0])

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()))
d=0
for i in range(2**n):
    t=bin(i)[2:]
    t="0"*(n-len(t))+t
    for j in range(m):
        c=0
        for h in range(1,k[j][0]+1):
            if t[k[j][h]-1]=="1":
                c+=1
        else:
            if c%2!=p[j]:
                break
    else:
        d+=1
print(d)

Solution (Python):
import itertools


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

for pattern in itertools.product(range(2), repeat=n):
    power = [0]*m
    for i in range(len(pattern)):
        if pattern[i] == 1:
            for j in range(len(info)):
                if i + 1 in info[j][1:]:
                    power[j] += 1
    for i in range(m):
        if power[i] % 2 != p[i]:
            break
    else:
        ans += 1
print(ans)

Solution (Python):



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

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

count = 0
for i in range(2 ** N):
    temp = i
    X = []
    for j in range(N):
        X.append(temp // (2 ** (N-j-1)))
        temp -= X[-1] * 2 ** (N-j-1)
    
    temp_count = 0
    for j, s in enumerate(S):
        if sum([X[temp_s-1] for temp_s in s]) % 2 == P[j]:
            temp_count += 1
            
    if temp_count == M:
        count += 1

print(count)

Solution (Python):
from collections import Counter, deque, defaultdict
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

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

ans = 0
for pp in itertools.product([True, False], repeat=N):
    a = np.array((False,) + pp)
    ok = True
    for s, p in zip(S, P):
        if sum(a[s]) % 2 != p:
            ok = False
            break
    if ok:
        ans += 1
print(ans)

Solution (Python):


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

def is_on(L, i):
  if L & (1 << (i-1)):
    return True
  else:
    return False

def is_ok(L, s, p):
  c = 0
  for i in s:
    if is_on(L, i):
      c += 1
  return (c % 2) == p

def main():
  N, M = readInts()
  S = []
  for _ in range(M):
    data = readInts()
    S.append(data[1:])
  P = readInts()

  ans = 0
  for L in range(2**N):
    ok = True
    for i, s in enumerate(S):
      if not is_ok(L, s, P[i]):
        ok = False
        break
    if ok:
      ans += 1

  print(ans)

if __name__ == "__main__":
  main()

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, m = li()

switch = []
for _ in range(m):
    s = list(li_())
    switch.append(s[1:])

p = list(li())

ans = 0
ok = True

for bit in range(1<<n):
    ok = True
    for i, swi in enumerate(switch):
        flag = 0
        for swij in swi:
            if bit & (1<<swij):
                flag += 1

        if flag % 2 != p[i]:
            ok = False

    if ok:
        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 p in range(2**n):
    num = format(p,'0'+str(n)+'b')
    light = 0
    for temp,i in zip(ks,range(1,m+1)):
        on = 0
        for s in temp[1:]:
            if num[s-1] == "1":
                on += 1
        if on%2 == P[i-1]:
            light += 1
    if light == m:
        ans += 1
print(ans)

Solution (Python):
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]






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

ans = 0
for i in range(1<<N):
    dp = [0]*(N+1)
    ind = i
    for k in range(N):
        if ind % 2 == 1:
            dp[k+1] = 1
        ind //= 2

    flag = True
    for k in range(1, M+1):
        a = 0
        for e in s[k]:
            a = (a + dp[e]) % 2
        if a != p[k]:
            flag = False
            break

    if flag:
        ans += 1
print(ans)

Solution (Python):
N, M = map(int, input().split())
light = []
for i in range(M):
    light.append(list(map(int, input().split())))
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    switch = "{:010b}".format(i)
    switch = switch[(10-N):]
    flag = 1
    for j in range(M):
        count = 0
        for k in range(light[j][0]):
            if switch[light[j][k+1]-1] == "1":
                count += 1
        if count % 2 == p[j]:
            continue
        else:
            flag = 0
            break
    if flag == 1:
        ans += 1

print(ans)

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

for i in range(M):
    k, *S = map(int, input().split())
    for s in S:
        X[i][s-1] = 1

P = list(map(int, input().split()))
ans = 0
for i in range(1<<N):
    for j in range(M):
        s = P[j]
        for k in range(N):
            if (i & (1<<k)) and X[j][k]:
                s ^= 1
        if s:
            break
    else:
        ans += 1
print(ans)

Solution (Python):
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 range(pow(2, N)):
  for j in range(len(ks)):
    c = i
    t = 0
    for k in range(N):
      n = c % 2
      if n == 1 and (k + 1) in ks[j][1:]:
        t += 1
      c //= 2
    if t % 2 != p[j]:
      break
  else:
    Ans += 1

print(Ans)

Solution (Python):

import sys


def solve(n, m, s, p):
    ret = 0
    
    
    count = 0
    for bits in range(2 ** n):
        ok = True
        for j in range(m):
            count = 0
            for i in s[j]:
                if (bits & (1 << (i - 1))) > 0:
                    count += 1
            
            
            
            
            
            if count % 2 != p[j]:
                ok = False
                break
        
        
        
        if ok:
            ret += 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    s = [[] for _ in range(M)]
    for i in range(M):
        n = int(next(tokens))
        for j in range(n):
            s[i].append(int(next(tokens)))
    p = []
    for i in range(M):
        p.append(int(next(tokens)))
    solve(N, M, s, p)

if __name__ == '__main__':
    main()

Solution (Python):
def rec(s_status, cp, con, p, N, M):
    if cp == N:
        for i in range(M):
            sum_s = 0
            for s in con[i]:
                sum_s += int(s_status[s - 1])
            if sum_s % 2 != p[i]:
                return 0
        else:
            return 1
    else:
        res = 0
        res += rec(s_status, cp + 1, con, p, N, M)
        s_status[cp] = True
        res += rec(s_status, cp + 1, con, p, N, M)
        s_status[cp] = False
        return res


def main():
    N, M = map(int, input().split())
    s_status = [False] * N

    con = [[] for _ in range(M)]
    for i in range(M):
        data = list(map(int, input().split()))
        con[i] = data[1:]

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

    print(rec(s_status, 0, con, p, N, M))


if __name__ == '__main__':
    main()

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

ans = 0
for i in range(1<<n):
    on_all = True
    for j in range(m):
        n_on = 0
        for s in ks[j]:
            if i&(1<<(s-1)):
                n_on += 1
        if not n_on%2 == p[j]:
            on_all = False
    if on_all:
        ans += 1
print(ans)

Solution (Python):
N,M =map(int,input().split())
lis =[]
for i in range(M):
    S =[int(i) for i in input().split()]
    k =S.pop(0)
    foo = 0
    for i in S:
        foo += 2**(i-1)
    lis.append(foo)

ans = 0
p = [int(i)for i in input().split()]
for i in range(2**N):
    sta =True
    for n,j in enumerate(lis):
        if bin(i&j)[2:].count("1")%2 !=p[n]:
            sta = False
    if sta:
        ans += 1
print(ans)