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



Sample input:
2 2
2 1 2
1 2
0 1


Sample output:
1

Submission status: Runtime Error

Solution code:
#電球クラス
class Light:
    def __init__(self,name,switchs,whattype):
        self.name=name
        self.switchs=switchs
        self.whattype=whattype
    def reset(self):
        sumnum=0
        for switch in self.switchs:
            sumnum+=switch.onoff
        if sumnum%2==0:
            self.state="off"
        else:
            self.state="on"
            
#スイッチクラス            
class Switch:
    def __init__(self,name):
        self.name=name
        self.onoff=0
    def click(self,onoff):
        self.onoff=onoff
        
    
#整理用データ
n,m=[int(i) for i in input().split()]
allist=[]
for i in range(m+1):
    allist.append([int(j) for j in input().split()])
      

#全スイッチのリスト
switchlist=[]
for i in range(n):
    switchlist.append(Switch(i))


#全電球のリスト
lightlist=[]
for i in range(m):
    swlist=[]
    swnum=allist[i][1:]
    for j in swnum:
        swlist.append(switchlist[j-1])
    whattype=allist[-1][i]
    lightlist.append(Light(i,swlist,whattype))
    
#全部の付け方について
count=0
clicklist=[0 for i in range(n)]    
for i in range(2**n):
    onoffcheck=0
    j=0
    while i:
        clicklist[j]=i%2
        i=i//2
        j+=1
    for k in range(n):
        switchlist[k].click(clicklist[k])
    for light in lightlist:
        light.reset()
        if light.state=="off":
            onoffcheck+=1
    for i in lightlist:
#         print(i.state)
    if onoffcheck==0:
        count+=1
print(count)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
KS = []*M
for i in range(M):
  KS[i]= list(map(int, input().split()))
P = list(map(int, input().split()))

ans = 0
for i in range(N**2):
  sl = []
  for j in range(N):
    if (i>>j)&1:
      sl.append(j+1)
  for j in range(M):
    if len(set(KS[j][1:])&set(sl))%2 ==P[j]:
      continue
    else:
      break
  else:
    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python

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

    # all possible switch patterns
    for i in range(2 ** N):
        light_on = 0
        # all switch conditions
        for j in range(M):
            switch_on = 0
            # all connected switch
            for k in S[j][1:]:
                # convert integer to binary
                if (i >> k-1) & 1:
                    switch_on += 1
            if switch_on %2 == P[j]:
                light_on += 1
        if light_on == M:
            ans += 1

    return ans

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

Submission status: Runtime Error

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

sum = 0
isAffectedSwitch=[[False for _ in range(n)] for _ in range(m)]
for i in range(m):
    for j in range(1,s[i][0]+1):
        isAffectedSwitch[i][s[i][j]-1]=True

C = []
for i in range(N):
    B = 0
    for j in range(M):
        if isAffectedSwitch[j][i] = True:
            B += 2**(M-j-1)
    C.append(B)

for i in range(2**N):
    A = 0
    for j in range(N):
        if (i >> j):
            A = A^C[j]
    if A == p:
        sum += 1
        
print(sum)

Submission status: Runtime Error

Solution code:
from itertools import product
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 tup in product(range(2), repeat=M):
    for i in range(M):
        flg = True
        cnt = 0
        for d in s[i]:
            cnt += tup[d - 1]
        if cnt % 2 != p[i]:
            flg = False
            break

    if flg:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n, m = map(int, input().split())
switch = defaultdict(list)
for i in range(m):
    s = list(map(int, input().split()))[1:]
    switch[i] = s
p = list(map(int, input().split()))

output = 0
for h in range(2**n):
    flag = 1
    padding = f'0{n}b'
    bit = format(h, padding)
    for i, v in enumerate(p):
        cnt = 0
        for j in switch[i]:
            if bit[j-1] == '1':
                cnt += 1
        if cnt % 2 != v:
            flag = 0
    if flag == 1:
        output += 1
print(output)

Submission status: Runtime Error

Solution code:
from itertools import combinations
from collections import defaultdict
n, m = map(int, input().split())
switch = defaultdict(list)
for i in range(m):
    s = list(map(int, input().split()))[1:]
    switch[i] = s
p = list(map(int, input().split()))

output = 0
for h in range(2**n):
    flag = 1
    padding = f'0{n}b'
    bit = format(h, padding)
    for i, v in enumerate(p):
        cnt = 0
        for j in switch[i]:
            if bit[j-1] == '1':
                cnt += 1
        if cnt % 2 != v:
            flag = 0
    if flag == 1:
        output += 1
print(output)

Submission status: Runtime Error

Solution code:
import numpy as np

temp=input().split()
N=int(temp[0])
M=int(temp[1])

A=np.zeros((M, N))

for i in range(M):
  temp=list(map(int, input().split()))
  for j in range(1, temp[0]+1):
    A[i, temp[j]-1]=1
    
    
p=list(map(int, input().split()))

counter=0
for i in range(pow(2, N)):
  temp=format(i, '0'+str(N)+'b')
  s=[int(temp[j]) for j in range(N)]
  
  a=np.dot(A, s)%2
  
  if all(p==a):
    counter+=1
    
print(counter)

Submission status: Runtime Error

Solution code:
import numpy as np

temp=input().split()
N=int(temp[0])
M=int(temp[1])

A=np.zeros((M, N))

for i in range(M):
  temp=list(map(int, input().split()))
  for j in range(1, temp[0]+1):
    A[i, temp[j]]=1
    
    
p=list(map(int, input().split()))

counter=0
for i in range(pow(2, N)):
  temp=format(i, '0'+str(N)+'b')
  s=[temp[j] for j in range(N)]
  
  a=np.dot(A, s)%2
  
  if p==a:
    counter+=1
    
print(counter)

Submission status: Runtime Error

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

for i in range(2**N):
    x = ('00000000' + str(bin(i))[2:])[-10:]
    countM = 0
    for j in range(M):
        countl = 0
        for l in range(k[j]):
            tmp = s[j][l]
            if x[-tmp] == '1':
                countl += 1
        if countl%2 == p[j]:
            countM += 1
    if countM == M:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
a = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
c = 0
for n in range(1 << n):
    for i, s in enumerate(a):
        if p[i] ^ sum(n >> s-1 & 1 for s_ in s) & 1:
            break
        else:
            c += 1
print(c)

Submission status: Runtime Error

Solution code:
import numpy as np

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

S = np.zeros((M,N),dtype=np.int64)
for m in range(M):
    tokens = input().split()
    K = int(tokens[0])
    for k in range(K):
        s = int(tokens[1+k])
        S[m,s-1] = 1 # s is 1-origin

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

ans = 0
for bits in range(1<<N):
	x = np.array([(bits>>b)&1 for b in range(N)],dtype=np.int64)
	y = S@x
	#print(y)
	for m in range(M):
		if (y[m]&1) != p[m]:
			break  
	else:
		ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
S = input()
ans = 99999
for i in range(len(S) - 2):
    a = int(S[i:i+3])
    ans = min(ans, abs(a-753))
print(ans)

Submission status: Runtime Error

Solution code:
import sys

def input():
    return sys.stdin.readline()[:-1]

def main():
    n,m = map(int,input().split())
    k = []
    s = []
    ans = 0
    
    for _ in range(m):
        tmp = [int(i) for i in input().split()]
        k.append(tmp.pop(0))
        s.append(tmp)

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

    for i in range(2**n):
        tentou=[0]*m
        b = bin(i)[2:].zfill(5)
        for i2 in range(len(s)):
            for i3 in s[i2]:
                if b[i3-1] == "1":
                    tentou[i2]+=1
        tentou = [z % 2 for z in tentou]
        if tentou == p:
            ans+=1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())#n個のスイッチのオンオフの組み合わせ
ks = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))#0/1⇒偶数or奇数
num=2**m
ans=0
for i in range(num+1):
    bin_i = str(bin(i))
    bin_i = bin_i[2:len(bin_i)]
    res = m-len(bin_i)
    bin_i = "0"*res + bin_i
    on=0
    for j in range(m):
        s_num=0
        for k in range(1, ks[j][0]+1):
            if bin_i[ks[j][k]-1] == "1":
                s_num+=1
        if s_num%2==p[j] and s_num!=0:
            on+=1
        else:
            break
    if on==m:
        ans+=1
print(ans)

Submission status: Runtime Error

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

def check(ar):
    cnt = 0
    for j in range(M):
        count = 0
        for k in ks[j][1::]:
            if ar[k-1] == 1:
                count += 1
        if count%2 == p[j]:
            cnt += 1
    return (cnt == M)


def dfs(n, ar):
    if n == 0:
        if check(ar):
            return 1
        else:
            return 0
    else:
        return dfs(n-1, ar.append(0)) + dfs(n-1, ar.append(1))
arr = []
ans = dfs(N, arr)
print(ans)

Submission status: Runtime Error

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

def check(ar):
    cnt = 0
    for j in range(M):
        count = 0
        for k in ks[1::]:
            if ar[k-1] == 1:
                count += 1
        if count%2 == p[j]:
            cnt += 1
    return (cnt == M)


def dfs(n, ar):
    if n == 0:
        if check(ar):
            return 1
        else:
            return 0
    else:
        return dfs(n-1, ar.append(0)) + dfs(n-1, ar.append(1))
arr = []
ans = dfs(N, arr)
print(ans)

Submission status: Runtime Error

Solution code:
N, M = mtp(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(2**M):
    cnt = 0
    for j in range(M):
        count = 0
        for k in ks[j][1::]:
            if (i >> k-1)&1 == 1:
                count += 1
        if count%2 == p[j]:
            cnt += 1
    if cnt == M:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import itertools

n, m = map(int, input().split())
s = []
k = []
for i in range(m):
    array = list(map(int, input().split()))
    k.append(array.pop(0))
    s.append(array)
p = list(map(int, input().split()))

for i in range(m):
    s[i].sort()

cnt = 0
for i in range(2 ** n):
    STATE = []
    digit = len(format(i, 'b'))
    N = int(format(i, 'b'))
    for j in range(digit):
        if ((i >> j) & 1):
            STATE.append(j + 1)
    for l in range(m):
        tmp = []
        if p[l] == 1:
            for o in range(1, len(s), 2):  
                for r in itertools.permutations(s[l], o):
                    tmp.append(r)
                    if STATE == tmp:
                        cnt += 1
        else:   
            for o in range(2, len(s), 2):
                for r in itertools.permutations(s[l], o):
                    tmp.append(r)
                if STATE == tmp:
                    cnt += 1
    if cnt == m:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import itertools

n, m = map(int, input().split())
s = []
k = []
for i in range(n):
    array = list(map(int, input().split()))
    k.append(array.pop(0))
    s.append(array)
p = list(map(int, input().split()))


for i in range(n):
    s[i].sort()

cnt = 0
for i in range(2 ** n):
    STATE = []
    digit = len(format(i, 'b'))
    N = int(format(i, 'b'))
    for j in range(digit):
        if ((i >> j) & 1):
            STATE.append(j + 1)
    for k in range(m):
        tmp = []
        if p[k] == 1:
            for l in range(1, len(s), 2):  
                for o, _ in enumerate(s, l):
                    for p in itertools.permutations(s, o):
                        tmp.append(o)
        else:
            for l in range(2, len(s), 2):
                for o in enumerate(s,l):
                    for p in itertools.permurtations(s, o):
                        tmp.append(o)
        if STATE == tmp:
            cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
swithCount, lightCount = map(int, input().split())
swithList = [0] * lightCount

for i in range(swithCount):
    connectedLightList = list(map(int, input().split()))
    for lightIndex in connectedLightList[1:]:
        lightIndex -= 1
        swithList[i] = swithList[i] | 1 << lightIndex

expectedLightStatusList = list(map(int, input().split()))
expectedLightStatus = 0

for i, eachStatus in enumerate(expectedLightStatusList):
    expectedLightStatus = expectedLightStatus | eachStatus << i

resultCount = 0
for eachSwitchSet in range(1 << swithCount):
    actuallyLightStatus = 0
    for switchIndex in range(swithCount):
        if eachSwitchSet >> switchIndex & 1:
            actuallyLightStatus = actuallyLightStatus ^ swithList[switchIndex]

    if expectedLightStatus == actuallyLightStatus:
        resultCount += 1

print(resultCount)

Submission status: Runtime Error

Solution code:
swithCount, lightCount = map(int, input().split())
swithList = [0] * lightCount

for i in range(swithCount):
    connectedLightList = list(map(int, input().split()))
    for lightIndex in range(connectedLightList[1:]):
        lightIndex -= 1
        swithList[i] = swithList[i] | 1 << lightIndex

expectedLightStatusList = list(map(int, input().split()))
expectedLightStatus = 0

for i, eachStatus in enumerate(expectedLightStatusList):
    expectedLightStatus = expectedLightStatus | eachStatus << i

resultCount = 0
for eachSwitchSet in range(1 << swithCount):
    actuallyLightStatus = 0
    for switchIndex in range(swithCount):
        if eachSwitchSet >> switchIndex & 1:
            actuallyLightStatus = actuallyLightStatus ^ swithList[switchIndex]

    if expectedLightStatus == actuallyLightStatus:
        resultCount += 1

print(resultCount)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
info_list=[]
for i in range(m):
    info_list.append(list(map(int,input().split())))
p_list = list(map(int,input().split()))

count= 0

for i in range((n)**2):
    swith = str(bin(i))[2:]
    swith_num = swith.zfill(m) 
    for j in info_list:
        flag = 0
        swith_sum = 0
        for k in j[1:]:
            swith_sum += int(swith_num[int(k)-1])
        if swith_sum%2 == p_list[info_list.index(j)]:
            pass
        else:
            flag = 1
            break
    if flag == 0:        
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
# n=int(inputfile.readline())
# a,b=map(int, inputfile.readline().split())
# c=list(map(int, inputfile.readline().split()))
# s=[list(map(int,list(inputfile.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import math
import sys

inputfile = open("input.txt")
N, M=map(int, inputfile.readline().split())

# 各スイッチがどの電球につながっているかの情報をビットで保持する配列
# 1番目のスイッチが2番目と3番目の電球につながっていた場合以下のようになる
# (1 << 1) | (1 << 2) = (110)b   ※ zero index
bulb_list = [0 for _ in range(N)]

for bulb_idx in range(M):
    switches = list(map(int, inputfile.readline().split()))
    bulb_bit = 1 << bulb_idx # つながっている電球を二進数で表す

    # switchesの2番目以降の要素には、スイッチの番号が入っている
    for sw in switches[1::]:
        sw_idx = (sw - 1) # スイッチの番号をzero indexに変換する
        bulb_list[sw_idx] = bulb_list[sw_idx] | bulb_bit

bulb_conds = list(map(int, inputfile.readline().split()))

bulb_cond = 0
for i, bc in enumerate(bulb_conds):
    bulb_cond |= bc << i

light_num = 0
# N = 3 の時
# 000, 001, 010, 011, 100, 101, 110, 111 の8パターンで、
# スイッチを押す全てのパターンを表現することが出来る
for bit_ptn in range(1 << N):
    t = 0 # tはbit_ptnが表すスイッチの組み合わせを全て押したときの電球の状態を表す(最初は全部消えている)
    for i in range(N):
        if bit_ptn >> i & 1:
            t = t ^ bulb_list[i]
    if t == bulb_cond:
        light_num += 1

print(light_num)

Submission status: Runtime Error

Solution code:
import itertools
n, m = list(map(int, input().split()))

ks = [[int(i) for i in  list().split()] for in range(m)]
p = [int(i) for i in list().split()]

cmt = 0

for i in range(ks[1]):
  if i%2 = p[ks[0]]:
    for r in range(i):
      cmt += itertools.combination(i, r)
print(cmt)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
ks = [[0] for i in range(m)]
jud = []
for i in range(m):
    tmp = list([int(i)-1 for i in input().split()])
    ks[i] = tmp[1:]
jud = list(map(int, input().split()))

ans = 0
c = True
for i in range(2 ** n):
    tmp = list()
    c = True
    for j in range(m):
        t = ks[j]
        ch = 0
        for m in t:
            ib = format(i, 'b')
            if len(ib) >= m+1:
                ch += int(ib[m])
            else:
                break
        if ch % 2 != jud[j]:
            c = False
            break
    if c:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
ks = [[0] for i in range(m)]
jud = []
for i in range(m):
    tmp = list([int(i)-1 for i in input().split()])
    ks[i] = tmp[1:]
jud = list(map(int, input().split()))

ans = 0
c = True
for i in range(2 ** n):
    tmp = list()
    c = True
    for j in range(m):
        t = ks[j]
        ch = 0
        for m in t:
            ch += tmp[m]
        if ch % 2 != jud[j]:
            c = False
            break
    if c:
        ans += 1
print(ans)

Submission status: Runtime Error

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

k = []
p = []
tmp = []

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

Submission status: Runtime Error

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

for i in range(2**n):
    bulb = [0] * m
    for j in range(n):
        if i>>j & 1:
            for k in range(m):
                if j+1 in lst[k][1:]:
                    bulb[k] += 1

    all_lightup = true
    for l in range(m):
        if bulb[l] % 2 != p[l]:
          	all_lightup = false
          	break
    if all_lightup:
        ans += 1

print (ans)

Submission status: Runtime Error

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

for i in range(2**n):
    bulb = [0] * m
    for j in range(n):
        if i>>j & 1:
            for k in range(m):
                if j+1 in lst[k][1:]:
                    bulb[k] += 1

    all_lightup = true
    for l in range(m):
        if bulb[l] % 2 != p[l]:
          	all_lightup = false
          	break:
    if all_lightup:
        ans += 1

print (ans)

Submission status: Runtime Error

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

for i in range(2**n):
    bulb = [0] * m
    for j in range(n):
        if i>>j & 1:
            for k in range(m):
                if j+1 in lst[k][1:]:
                    bulb[k] += 1

	for l in range(m):
    	if bulb[l] % 2 == p[l]:
        	ans += 1

print (ans)

Submission status: Runtime Error

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

for i in range(2**n):
    bulb = [0] * m
    for j in range(n):
        if i>>j & 1:
            for k in range(m):
                if j+1 in lst[k][1:]:
                    bulb[k] += 1


    if bulb[l] % 2 == p[l]:
        ans += 1

print (ans)

Submission status: Runtime Error

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

for i in range(2**n):
    bulb = [0] * m
    for j in range(n):
        if i>>j & 1:
            for k in range(m):
                if j+1 in lst[k][1:]:
                    bulb[k] += 1

    flag = True
    for l in range(m):
        if bulb[l] % 2 != p[l]:
            flag = False
    if flag:
        ans += 1

print (ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))
ans = 0

for i in range(2**n):
    bulb = [0] * m
    for j in range(n):
        if i>>j & 1:
            for k in range(m):
                if j+1 in lst[k][1:]:
                    bulb[k] += 1

    flag = True
    for l in range(m):
        if bulb[l] % 2 != p[l]:
            flag = False
    if flag:
        ans += 1

print (ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
s = [[int(x) for x in input().split()][1:] for y in range(m)]
p = [int(z) for z in input().split()]
ans = 0

for i in range(2**n):
    b = array([(i>>j)&1 for j in range(n)])
    if [sum(b[array(k) - 1]) % 2 for k in s] == p:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
s = [[int(x) for x in input().split()][1:] for y in range(m)]
p = [int(z) for z in range(m)]
ans = 0

for i in range(2**n):
    b = array([(i>>j)&1 for j in range(n)])
    if [sum(array(k) - 1) % 2 for k in s] == p:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N, M = int(input().split())  # N個のスイッチ, M個の電球

# M個の電球がそれぞれどこのスイッチと繋がっているかを格納
SSS = [list(map(int, input().split()))[1:] for i in range(M)]
P = list(map(int, input().split()))

ans = 0

for i in range(1 << N):  # 2のN乗の値になる, bit全探索
    for mask in range(M):
        ans_2 = 0
        for s in SSS[mask]:
            if (1 << s-1) & i != 0:
                ans_2 += 1

        if ans_2 % 2 != P[mask]:
            break
    else:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
N, M = int(input().split())  # N個のスイッチ, M個の電球

# M個の電球がそれぞれどこのスイッチと繋がっているかを格納
SSS = [list(map(int, input().split()))[1:] for i in range(M)]
P = list(map(int, input().split()))

ans = 0

for i in range(1 << N):  # 2のN乗の値になる, bit全探索
    for mask in range(M):
        ans_2 = 0
        for s in SSS[mask]:
            if (1 << s-1) & i != 0:
                ans_2 += 1

        if ans_2 % 2 != P[m]:
            break
    else:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
from numpy import *
n,m = map(int, input().split())

s = [[int(j) for j in input().split()][1:] for i in range(m)]
p = [int(i) for i in input().split()]

ans = 0

for i in range(2**n):
    b = array([(i >> j)&1 for j in range(n)])
    if [sum(b[array(k) - 1] % 2 for k in s)] == p:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys

def all_lighted(input, mod, pattern):
    for i, bulb in enumerate(input):
        if bin(bulb and pattern).count('1') % 2 == pattern[i]:
            next
        else:
            return False
    
    return True


def main():
    num_switch, num_bulb = [int(x) for x in sys.stdin.readline().split()]
    input = [0] * num_bulb

    for bulb in input:
        for x in sys.stdin.readline().split()[1:]:
            bulb += 2**(int(x) - 1)

    mod = [int(x) for x in sys.stdin.readline().split()]

    count = 0

    for i in range(2 ** num_switch):
        if all_lighted(input, mod, i): count += 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
List=[list(map(int,input().split())) for i in range(m)]
P=list(map(int,input().split()))

k=0
ans=0
flug=True

for i in range(n):
    k=bin(i)
    for l in range(m):
        count=0
        for j in range(List[l][0]):
            if ((k>>List[l][j+1])&1)==1:
                count += 1
        if count%2 != P[l]:
            flug=False
    if flug==True:
        ans += 1
        
print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
List=[list(map(int,input().sprit())) for i in range(m)]
P=list(map(int,input().split()))

k=0
ans=0
flug=True

for i in range(n):
    k=bin(i)
    for l in range(m):
        count=0
        for j in range(List[l][0]):
            if ((k>>List[l][j+1])&1)==1:
                count += 1
        if count%2 != P[l]:
            flug=False
    if flug==True:
        ans += 1
        
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def brute_force():
    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()))
    ans = 0
    for i in range(1 << N):
        for r in range(M):
            on_sum = 0
            for j in range(M):
                if i >> j & 1 and lamps[r][0]<=j<=lamps[r][1]:
                    on_sum += 1
            if on_sum % 2 == p[r]:
                continue
            else:
                break
        else:
            ans += 1
    print(ans)


brute_force()

Submission status: Runtime Error

Solution code:
import itertools
N,M=map(int,input().split())
kslist=[(list(map(int,input().split()))) for i in range(M)]
plist=list(map(int,input().split()))
ls=list((itertools.product(range(2),repeat=N)))
n=0
for tup in ls:
    if [tup[kslist[j][k in range(1,kslist[j][0]+1)]-1]%2 for j in range(M)]==plist:
        n+=1
print(n)

Submission status: Runtime Error

Solution code:
import itertools
N,M=map(int,input().split())
kslist=[]
for i in range(M):
    kslist.append(list(map(int,input().split()))) 
plist=list(map(int,input().split()))
ls=list((itertools.product(range(2),repeat=N)))
n=0
for tup in ls:
    if [tup[kslist[j][k in range(1,kslist[j][0]+1)]-1]%2 for j in range(M)]==plist:
        n+=1
print(n)

Submission status: Runtime Error

Solution code:
import itertools
N,M=map(int,input().split())
kslist=[]
for i in range(M):
    kslist.append(list(map(int,input().split()))) 
plist=list(map(int,input().split()))
seq=[0]*N+[1]*N
ls=list(set(list(itertools.permutations(seq,N))))
n=0
for tup in ls:
    if [tup[kslist[j][k in range(1,kslist[j][0]+1)]-1]%2 for j in range(M)]==plist:
        n+=1
print(n)

Submission status: Runtime Error

Solution code:
import itertools
N,M=map(int,input().split())
kslist=[]
for i in range(M):
    kslist.append(list(map(int,input().split()))) 
plist=list(map(int,input().split()))
seq=[0]*N+[1]*N
ls=list(set(list(itertools.permutations(seq,N))))
n=0
for tup in ls:
    ln=[]
    for j in range(M):
        sum1=0
        sum1+=tup[kslist[j][k in range(1,kslist[j][0]+1)]-1]
        ln.append(sum1%2)
    if ln==plist:
        n+=1
        
print(n)

Submission status: Runtime Error

Solution code:
while True:
  must1 = 1
  for mi in range(m):
    onoff = 0
    for ni in range(n):
      onoff += li[mi][ni]*yyy[ni]
    should1 = bool(onoff%2 == p[mi])
    must1 *= should1
  if must1 == 1:
    score += 1
  yyy[0] += 1
  for ni in range(n-1):
    if yyy[ni] == 2:
      yyy[ni] = 0
      yyy[ni+1] += 1
  if yyy[n-1] == 2:
    break
print(score)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[[0 for h in range(n)] for i in range(2**n)]
b=[[0 for i in range(m)] for h in range(2**n)]
#0~2**n-1を2進数表記し、リストaに記録する(各位の10はスイッチのonoffに対応)
for i in range(2**n):
  b=i
  for j in range(n):
    c=b//(2**(n-j-1))
    a[i][j]+=c
    b-=c*(2**(n-j-1))
print(a)
#それぞれの数について、電球が点灯するかどうかを検証する（各位が電球の点灯する条件を満たしているか）
for i in range(m):
  for j in range(2**n):
    lights=list(map(int,input().split()))
    for h in range(len(lights)-1):
      b[j][i]+=a[j][lights[h+1]-1]
check=list(map(int,input().split()))
#検証パート
ans=0
for i in range(2**n):
  flag=0
  for j in range(m):
    if b[i][j]%2!=check[j]:
      flag=1
      break
  if flag==0:
    ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
def add(s,d):
     sum=0
     for i in d[1:]:
          sum+=s[i] 
     return sum

def check(m):
    for i in range(m):
        if add(s, d[i]) % 2 == p[i]:
            pass
        else :
            return -1
    return 1
        
        
d = []
s=[]
inc=0

n, m = (int(x) for x in input().split())
for i in range(m):
    i = [int(i) for i in input().split()] 
    d.append(i)
p = [int(i) for i in input().split()]


for i in range(32):
    x = '{:0>6}'.format(bin(i).split('b')[1])
    s=list(x)
    s= [int(s) for s in s]
    if check(m) == 1:
            inc +=1
    
print(inc)

Submission status: Runtime Error

Solution code:
def add(s,d):
     sum=0
     for i in d[1:]:
          sum+=s[i] 
     return sum

def check(m):
    for i in range(m):
        if add(s, d[i]) % 2 == p[i]:
            pass
        else :
            return -1
    return 1
        
        
d = []
s=[]
inc=0

n, m = (int(x) for x in input().split())
for i in range(m):
    i = [int(i) for i in input().split()] 
    d.append(i)
p = [int(i) for i in input().split()]


for i in range(32):
    x = '{:0>6}'.format(bin(i).split('b')[1])
    s=list(x)
    s= [int(s) for s in s]
    #print(i, l)
    if check(m) == 1:
            inc +=1
    
print(inc)