TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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?

Submission attempts (in order):
from itertools import product

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

cnt = 0
for pat in product([0, 1], repeat=n):
    for ksi, pi in zip(ks, pi):
        tmp = sum(pat[ksij - 1] for ksij in ksi[1:])
        if  tmp % 2 != pi:
            break
    else:
        cnt += 1
print(cnt)


from itertools import product

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

cnt = 0
for pat in product([0, 1], repeat=n):
    for ksi, pi in zip(ks, p):
        tmp = sum(pat[sij - 1] for sij in ksi[1:])
        if  tmp % 2 != pi:
            break
    else:
        cnt += 1
print(cnt)


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n,m=map(int,input().split())
s=[]
for i in range(m):
    s.append(list(map(int,input().split())))
p=list(map(int,input().split()))

onoff=[["0"],["1"]]

for i in range(n):
    tmp=[]
    for j in onoff:
        tmp.append(j+["0"])
        tmp.append(j+["1"])
    onoff=tmp

ans=0
for i in onoff:
    f=0
    for j in range(m):
        c=0
        for k in range(s[j][0]):
            if i[s[j][1+k]-1]=="1":
                c+=1
        if c%2!=p[j]:
            f+=1
    if f==0:
        ans+=1
print(ans)

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

onoff=[["0"],["1"]]

for i in range(n-1):
    tmp=[]
    for j in onoff:
        tmp.append(j+["0"])
        tmp.append(j+["1"])
    onoff=tmp

ans=0
for i in onoff:
    f=0
    for j in range(m):
        c=0
        for k in range(s[j][0]):
            if i[s[j][1+k]-1]=='1':
                c+=1
        if c%2!=p[j]:
            f+=1
    if f==0:
        ans+=1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n, k = [int(a) for a in input().split()]
v = [int(a) for a in input().split()]


cap = min(n, k)
max_val = 0
for left in range(k):
    for right in range(cap - left):
        rest = k - (left + right)
        l_popped = v[:left]
        r_popped = v[-right:] if right > 0 else []
        popped = l_popped + r_popped

        popped.sort()

        first_positive = len(popped)
        for i, value in enumerate(popped):
            if value > 0:
                first_positive = i
                break

        sum_val = sum(popped[min(rest, first_positive):])
        if sum_val > max_val:
            max_val = sum_val

print(max_val)



n, m = [int(a) for a in input().split()]

S = [[int(i) for i in input().split()[1:]] for _ in range(m)]

mask = [sum([2 ** (x-1) for x in s]) for s in S]

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




count = 0
for j in range(2**n):
    for i in range(m):
        on_switch = [int(k) for k in list(format(j & mask[i], 'b'))]
        if not sum(on_switch) % 2 == p[i]:
            count -= 1
            break
    count += 1

print(count)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
ans = 0
n,m = map(int, input().split())
s_list = []
s_count_list = []
for _ in range(m):
    s = list(map(int,input().split()))
    s_count_list.append(s[0])
    s_list.append(s[1:])
oe = list(map(int,input().split()))   
seq = list(range(1, n+1))
for i in range(1, n+1):
    cmb = list(itertools.combinations(seq,i))
    for j in range(len(cmb)):
        ansv = []
        for k in range(m):
            ss = []
            for l in range(len(s_list[k])):
                if s_list[k][l] in list(cmb[j]):
                    ss.append(s_list[k][l])
            if len(ss)%2 == oe[k]:
                ansv.append(True)
            else:
                ansv.append(False)
        if all(ansv):
            ans += 1
print(ans)

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

import itertools

cnt=0
for i in itertools.product([0,1],repeat=n):
    tn_arr=[]
    for j in range(m):
        on_cnt=0
        for k in range(len(s[j])):
            on_cnt+=i[s[j][k]-1]
        if on_cnt%2==p[j]:
            tn_arr.append(True)
        else:
            tn_arr.append(False)
    if all(tn_arr):
        cnt+=1

print(cnt)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n,m = map(int,input().split())
q = [list(map(int, input().split())) for i in range(m)]
ans = 0

for s in range(2**n): 
    judge = True
    for i in range(m): 
        cnt=0
        for j in range(1,len(q[i])): 
            w=q[i][j]
            if s >> (w-1) &1 ==1: 
                cnt+=1 
        if cnt % 2 != p[i]: 
            judge = False
    if judge:
        ans += 1

print(ans)

n,m = map(int,input().split())
q = [list(map(int, input().split())) for i in range(m)]
p= list(map(int, input().split()))
ans = 0
 
for s in range(2**n): 
    judge = True
    for i in range(m): 
        cnt=0
        for j in range(1,len(q[i])): 
            w=q[i][j]
            if s >> (w-1) &1 ==1: 
                cnt+=1 
        if cnt % 2 != p[i]: 
            judge = False
    if judge:
        ans += 1
 
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
#ABC128 C
N, M = (int(_) for _ in input().split())
A = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(N):
    for j, S in enumerate(A):
        if P[j] ^ sum(i >> k-1 & 1 for k in S) & 1:
            break
    else:
        ans += 1
print(ans)   

#ABC128 C
N, M = (int(_) for _ in input().split())
A = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(N):
    for j, S in enumerate(A):
        if P[j] ^ (sum(i >> k-1 & 1 for k in S) & 1):
            break
    else:
        ans += 1
print(ans)   

#ABC128 C
N, M = (int(_) for _ in input().split())
A = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
    for j, S in enumerate(A):
        if P[j] ^ sum(i >> k-1 & 1 for k in S) & 1:
            break
    else:
        ans += 1
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N, M = list(map(int, input().split(" ")))
S = []
for i in range(M):
    ks = list(map(int, input().split(" ")))
    S.append(ks[1:])
P = list(map(int, input().split(" ")))

switchMap = []
for i in range(N):
    switchMap.append([])
for i, s in enumerate(S):
    for ss in s:
        switchMap[ss-1].append(i)

count = 0
for i in range(pow(2, N)):
    switches = bin(i).replace("0b", "").zfill(N)
    light = [0] * M
    for j, switch in enumerate(switches):
        if switch == '1':
            for s in switchMap[j]:
                light[s] += 1

    flag = True
    for j, l in enumerate(light):
        if l % 2 != P[j]:
            flag = False
            break

    if flag:
        print(switches)
        count += 1

print(count)


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

switchMap = []
for i in range(N):
    switchMap.append([])
for i, s in enumerate(S):
    for ss in s:
        switchMap[ss-1].append(i)

count = 0
for i in range(pow(2, N)):
    switches = bin(i).replace("0b", "").zfill(N)
    light = [0] * M
    for j, switch in enumerate(switches):
        if switch == '1':
            for s in switchMap[j]:
                light[s] += 1

    flag = True
    for j, l in enumerate(light):
        if l % 2 != P[j]:
            flag = False
            break

    if flag:
        # print(switches)
        count += 1

print(count)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n, m = map(int, input().split())
list_num = list([] for i in range(n))
test = [input().split() for i in range(m)]
check = [0] * n
for i in test:
  list_num[int(i[0]) - 1].append(i[1])
count = 0
count_ac = 0
count_wa = 0
check = 0
for i in list_num:
  for j in range(len(i)):
    if(i[j] =='WA'):
      count += 1
    else:
      count_ac += 1
      check = 1
      break
  if(check == 1):
    count_wa += count
    count = 0
    check = 0 

print(count_ac , count_wa)


n, m = map(int, input().split())
k = list(list(map(int, input().split())) for _ in range(m))
p = list(map(int, input().split()))
check = 0

def rec(A, c):
  if len(A) == n:
    count_m = 0
    for l in range(m):
      list_k = k[l]
      count = 0
      for j in range(1, list_k[0] + 1):
        if A[list_k[j] - 1] == 1:
          count += 1
      if p[l] == (count%2):
        count_m += 1
    if(count_m == m):
      c += 1
    return c
  
  for i in range(2):
    A.append(i)
    c = rec(A, c)
    A.pop()

  return c

print(rec([], check))


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
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 bit in range(1 << N):
    flag = True
    for i in range(N):
        count = 0
        for v in ks[i]:
            if bit & (1<<(v-1)):
                cnt += 1
        if cnt %2 != p[i]:
            flag = False
    if flag:
        ans += 1

print(ans)

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

print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N, M = map(int,input().split())
state = []
for _ in range(M):
  lst = list(map(int, input().split()))
  state.append(lst[1:])
p = list(map(int, input().split()))#numbers switches on %2 == pi 
ans = 0
for i in rage(2**n):
  total = 0
  for j in range(m):
    cnt = 0
    for s in state[j]:
      s -= 1
      if (i >> s) & 1:
        cnt += 1
    cnt %= 2
    if cnt == p[j]:
      total += 1
  if total == m:
    ans += 1
print(ans)

N, M = map(int,input().split())
state = []
for _ in range(M):
  lst = list(map(int, input().split()))
  state.append(lst[1:])
p = list(map(int, input().split()))#numbers switches on %2 == pi 
ans = 0
for i in range(2**N):
  total = 0
  for j in range(M):
    cnt = 0
    for s in state[j]:
      s -= 1
      if (i >> s) & 1:
        cnt += 1
    cnt %= 2
    if cnt == p[j]:
      total += 1
    else:
      break
  if total == M:
    ans += 1
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#m = int(input())
n, m = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

l = []
for i in range(m):
    l.append(list(map(int, sys.stdin.readline().split())))

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

ans = 0
for i in range(2 ** n):
    g = format(i, "010b")
    for j in range(m):
        cnt = 0
        for k in range(1,l[j][0]+1):
            if g[9-l[j][k]] == "1":
                cnt += 1

        if cnt % 2 != p[j]:
            break

        if j == m - 1:
            ans += 1

print(ans)
    

    
    

        


n, m = map(int, input().split())
h = []
for i in range(m):
    h.append(list(map(int, input().split())))
    
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
    g = format(i, "010b")
    count = 0
    
    for j in range(m):
        x = 0
        for k in range(len(h[j]) - 1):
            x += int(g[10 - h[j][k+1]])
        if x % 2 != p[j]:
            break
        count+= 1
    
    if count == m:
        ans += 1


print(ans)
        







                                        




    




        


    







        



Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import sys
input = sys.stdin.readline

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

denkyu = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
memo = []
memos = []


def erabu(i, n, c, d):
    if (i > len(k[d][1:])):
        if(c % 2 == p[d]):
            memo.append(n)
        return
    if(i+1 in k[d][1:]):
        erabu(i+1, n.append(i+1), c+1, d)
    erabu(i + 1, n, c, d)


print(memo)

for i in range(m):
    erabu(0, 0, 0, i)
    memos.append(memo)



# def isOK(i, n):
 #   if (n ^ memos[i][j] not 0)


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

ans = 0
switchState = [0]*n


def dfs(i, tukeru):
    
    if(i == n):
        sumOfTento = 0
        for denkyu in range(m):
            sumOfswitch = 0
            for switch in switches[denkyu]:
                sumOfswitch += switchState[switch-1]
            if(sumOfswitch % 2 == p[denkyu]):
                sumOfTento += 1
        # print(switchState)
        if(sumOfTento == m):
            return 1
        else:
            return 0
    switchState[i] = tukeru
    return dfs(i+1, 0) + (dfs(i+1, 1) if i != n-1 else 0)


print(dfs(0, 0)+dfs(0, 1))


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N, M = map(int, input().split(" "))
botlist = []
ans = 0
for n in range(M):
    bot = list(map(int, input().split(" ")))
    
    botlist.append(bot)
#botlist
plist = list(map(int, input().split(" ")))

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

for p in range(N):
    M = (2**N)/(p+1)
    for q in range(M):
        for r in range(p+1):
            if q%2 == 0:
                pushlist[r*q] = 0
            else:
                pushlist[r*q] = 1

for A in pushlist:
    g = 0
    for B in botlist:
        cou = 0
        for c in range(B[0]):
            cou += A[B[c]]
        if cou % 2 == plist[g]:
            ans += 1
    g +=1

print(ans)


    





N, M = map(int, input().split(" "))
botlist = []
ans = 0
for n in range(M):
    bot = list(map(int, input().split(" ")))
    
    botlist.append(bot)
#botlist
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:
    #print(A)
    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)


    





Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N,K = map(int, input().split())
cnt = 0
while 2**cnt < K:
    cnt += 1
result = ((1/2)**cnt)/N
for i in range(2,N+1):
    while (2**cnt)+(2**cnt)*(i-1) >= K and cnt >= 0:
        cnt -= 1
    if cnt == -1:
        result += (N-i+1)/N
        break
    cnt += 1
    result += ((1/2)**cnt)/N
print(result)


N,M = map(int, input().split())
connect = [[0,0,0]]
on_off = [0]*(N+1)
result = 0
for _ in range(M):
    k = list(map(int, input().split()))
    connect.append(k[1:])
p = list(map(int, input().split()))

for cnt in range(0,2**N):
    bin_str = list(format(cnt, 'b'))
    i = len(on_off)-len(bin_str)
    for num in bin_str:
        on_off[i] = int(num)
        i += 1
    for i in range(1,M+1):
        total = 0
        for j in connect[i]:
            total += on_off[j]
        if total % 2 != p[i-1]:
            break
        elif i == M:
            result += 1
print(result)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
def abc128_c():
    
    N, M = map(int, input().split())

    connected_switches = []
    for i in range(M):
        # [k, s1, s2, ...sn][1:]
        tmp = list(map(int, input().split()))[1:]
        connected_switches.append(tmp)

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

    ans = 0

    
    for i in range(2 ** N):
        
        for j in range(M):
            on_lamp_count = 0
            on_switch_count = 0
            
            for k in range(N):
                
                if k + 1 in connected_switches[j] and ((i >> k) & 1):
                    on_switch_count += 1

            
            if on_switch_count % 2 != p[j]:
                break
            else:
                on_lamp_count += 1

        if on_lamp_count == p[j]:
            ans += 1

    print(ans)

if __name__ == '__main__':
    abc128_c()

def abc128_c():
    
    N, M = map(int, input().split())

    connected_switches = []
    for i in range(M):
        # [k, s1, s2, ...sn][1:]
        tmp = list(map(int, input().split()))[1:]
        connected_switches.append(tmp)

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

    ans = 0

    
    for i in range(2 ** N):
        
        for j in range(M):
            on_switch_count = 0
            
            for k in range(N):
                
                if k + 1 in connected_switches[j] and ((i >> k) & 1):
                    on_switch_count += 1

            
            if on_switch_count % 2 != p[j]:
                break
            
            if j == (M - 1):
                ans += 1

    print(ans)

if __name__ == '__main__':
    abc128_c()


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N,M = (int(i) for i in input().split())
s = [[int(i) for i in input().split()] for i in range(M)]
p = [int(i) for i in input().split()]
result2 = 0

for i in range(2 ** N):
    hoge = bin(i + 1)
    hoge = str(hoge)
    hoge = hoge[2:]
    hoge = hoge.zfill(len(str(bin((2 ** N)))) - 2)
    result = True
    for j in range(M):
        onon = 0
        for k in s[j][1:]:
            if hoge[k] == "1":
                onon += 1
        if onon % 2 != p[j]:
            result = False
    if result:
        print("OK")
        print(hoge)
        result2 += 1
print(result2)

N,M = (int(i) for i in input().split())
s = [[int(i) for i in input().split()] for i in range(M)]
p = [int(i) for i in input().split()]
result2 = 0

for i in range(2 ** N):
    hoge = bin(i + 1)
    hoge = str(hoge)
    hoge = hoge[2:]
    hoge = hoge.zfill(len(str(bin((2 ** N)))) - 2)
    result = True
    for j in range(M):
        onon = 0
        for k in s[j][1:]:
            if hoge[k] == "1":
                onon += 1
        if onon % 2 != p[j]:
            result = False
    if result:
        result2 += 1
print(result2)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
lights = [map(int, input().split()[1:]) for i in range(M)]
p = map(int, input().split())

combi = 0
for i in range(1<<N):
    flag = True
    for j, switch in enumerate(lights):
        if sum([1 for s in switch if (i>>(s-1)) & 1 == 1])%2 != p[j]:
            flag = False
            break
    if flag:
        combi += 1

print(combi)

# -*- coding: utf-8 -*-

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

combi = 0
for i in range(1<<N):
    flag = True
    for j, switch in enumerate(lights):
        if sum([1 for s in switch if (i>>(s-1)) & 1 == 1])%2 != p[j]:
            flag = False
            break
    if flag:
        combi += 1

print(combi)

# -*- coding: utf-8 -*-

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

combi = 0
for i in range(1<<N):
    flag = True
    for j, switch in enumerate(lights):
        if sum([1 for s in switch if (i>>(s-1)) & 1 == 1])%2 != p[j]:
            flag = False
            break
    if flag:
        combi += 1

print(combi)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N, M = map(int, input().split())
S = [0] * M
for i in range(M):
    _, *s, = map(int, input().split())
    for v in s:
        S[i] = S[i] | (2 << v)

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

ans = 0
for p in range(2**N):
    ok = True
    for i in range(M):
        b = format(p & S[i], 'b')
        if b.count('1') % 2 != P[i]:
            ok = False
            break
    if ok:
        ans += 1

print(ans)

N, M = map(int, input().split())
S = [0] * M
for i in range(M):
    _, *s, = map(int, input().split())
    for v in s:
        S[i] = S[i] | (2 << v)

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

ans = 0
for p in range(2**(N + 1)):
    ok = True
    for i in range(M):
        b = format(p & S[i], 'b')
        if b.count('1') % 2 != P[i]:
            ok = False
            break
    if ok:
        ans += 1

print(ans)

N, M = map(int, input().split())
S = [0] * M
for i in range(M):
    _, *s, = map(int, input().split())
    for v in s:
        S[i] = S[i] | (2 << v)

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

ans = 0
for p in range(2**N + 1):
    ok = True
    for i in range(M):
        b = format(p & S[i], 'b')
        if b.count('1') % 2 != P[i]:
            ok = False
            break
    if ok:
        ans += 1

print(ans)

N, M = map(int, input().split())
S = [0] * M
for i in range(M):
    _, *s, = map(int, input().split())
    for v in s:
        S[i] = S[i] | (1 << (v - 1))

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

ans = 0
for p in range(2**N):
    ok = True
    for i in range(M):
        b = format(p & S[i], 'b')
        if b.count('1') % 2 != P[i]:
            ok = False
            break
    if ok:
        ans += 1

print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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?

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


res = 0
for i in range(2**n):
    on = [0 for _ in range(n)]
    for j in range(n):
        if((i>>j)&1):
            on[j]=1
    all_on = True 
    for j in range(m):
        on_num = 0 
        for s in ks[j][1: ]:
            if(on[s-1]): on_num += 1 

        if(on_num%2 != p[j]):
            break 

    if(all_on): res += 1
print(res)

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


res = 0
for i in range(2**n):
    on = [0 for _ in range(n)]
    for j in range(n):
        if((i>>j)&1):
            on[j]=1
    all_on = True 
    for j in range(m):
        on_num = 0 
        for s in ks[j][1: ]:
            if(on[s-1]==1):
                on_num += 1 

        if(on_num%2 != p[j]):
            all_on = False
            break 

    if(all_on):
        res += 1
print(res)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
k = []

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

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

cnt = 0
ans = 0
for i in range(2 ** n):
    lis = [False] * n

    for j in range(n):
        if (i >> j) & 1:
            lis[j] = True
    print(lis)
    cnt = 0
    for j in range(m):
        val = 0
        for l in range(len(k[j])):
            if lis[k[j][l]-1] == True:
                val += 1
            #print(lis[k[j][l]-1])
        if val % 2 == p[j]:
            cnt += 1
        #print(val)
        #print(cnt)
    if cnt == m:
        ans += 1
    #print(ans)



print(ans)

n, m = map(int, input().split())
lis = []
for i in range(m):
    s = list(map(int, input().split()))
    lis.append(s)
p = list(map(int, input().split()))
#print(lis)
ans = 0
for i in range(2**n):
    flg = [False] * n
    for j in range(n):
        if ((i >> j) & 1):
            flg[j] = True
    #print(flg)
    cnt = 0
    for j in range(m):
        val = 0
        for k in range(lis[j][0]):
            if flg[lis[j][k+1]-1] == True:
                val += 1
        if val % 2 == p[j]:
            cnt += 1
    if cnt == m:
        ans += 1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N,M=input().strip().split()
l1=[]
while True:
    try:
        l1.append(list(map(int,input().split())))
    except:
        break;
l2=l1[-1]
del l1[-1]
n=0
tate=0
yoko=1
count1=0
count2=0
count3=0
while True:
    while True:        
        sw=str(bin(n))
        del sw[0]
        a=l1[tate][yoko]
        if int(sw[a])==1:
            count1=count1+1
        yoko=yoko+1
        if yoko==l1[tate][0]:
            yoko=1
            if count1%2==l2[tate]:
                count2=count2+1
            break
    tate=tate+1
    if tate==M:
        if count2==N:
            count3=1
        n=n=1
        break
        

n,m=map(int,input().split())
a,c=[],0
for i in range(m):
    a.append(list(map(int,input().split())))
p=list(map(int,input().split()))
for i in range(2**n):
    i,b='0'*(n-len(bin(i))+2)+bin(i)[2:],0
    for j in range(m):
        f=0
        for k in range(a[j][0]):
            f+=int(i[a[j][k+1]-1])
        if f%2==p[j]:
            b+=1
    if b==m:
        c+=1
print(c)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
# 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 = sum([i >> j and j in lamps[r] for j in range(N)])
            
            # for j in range(N):
            #    if i >> j & 1 and j in lamps[r]:
            
            if on_sum % 2 != p[r]:
                break
        else:
            ans += 1
    print(ans)


brute_force()


# 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 = sum([int(i >> j and j in lamps[r]) for j in range(N)])
            print(on_sum)
            
            # for j in range(N):
            #    if i >> j & 1 and j in lamps[r]:
            
            if on_sum % 2 != p[r]:
                break
        else:
            ans += 1
    print(ans)


brute_force()


# 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 = sum([int(i >> j & 1 and j in lamps[r]) for j in range(N)])
            print(on_sum)
            
            # for j in range(N):
            #    if i >> j & 1 and j in lamps[r]:
            
            if on_sum % 2 != p[r]:
                break
        else:
            ans += 1
    print(ans)


brute_force()


# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
from itertools import product

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

ans = 0
for c in a:  
    cnt = 0
    for i in range(M):  
        tmp = 0
        for t in s[i]:  
            tmp += c[t - 1]  
            # print("tmp : {}".format(tmp))
        if tmp % 2 == p[i]:
            cnt += 1
    if cnt == M:  
        ans += 1
print(ans)

from itertools import product

N, M = map(int, input().split())
k = [0] * M
s = [[0] for _ in range(M)]
for i in range(M):
    k[i], *s[i] = map(int, input().split())
p = list(map(int, input().split()))
a = list(product([0, 1], repeat=N))  
# print(a)

ans = 0
for c in a:  
    cnt = 0
    for i in range(M):  
        tmp = 0
        for t in s[i]:  
            tmp += c[t - 1]  
            # print("tmp : {}".format(tmp))
        if tmp % 2 == p[i]:
            cnt += 1
    if cnt == M:  
        ans += 1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N, M = list(map(int, input().split()))

k_list = []
s_list = []
for i in range(M):
    k_s = list(map(int, input().split()))
    k_list.append(k_s[0])
    s_list.append(k_s[1:])

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

ans = 0

for i in range(1 << N):
    all_list = True
    for j in range(M):
        n = 0
        for k in s_list[j]:
            n += bool(i & (1 << k))
        if n % 2 != p_list[j]:
            all_list = False
            break
    ans += all_list

print(ans)

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

s_list = []
a = []
for i in range(M):
    s = list(map(int, input().split()))
    k = s[0]
    for j in range(1, k):
        a[s[j] - 1] |= 1 << i

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

p = 0
for i, x in enumerate(p):
    p |= x << 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)

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

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

print(ans)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N = int(N)
M = int(M)
line_list = []
for i in range(M):
    line = input().split()
    new_list=[]
    for l in line:
        new_list.append(int(l))
    new_list.pop(0)
    line_list.append(new_list)
old_p_list = input().split()
p_list = []
for p in old_p_list:
    p_list.append(int(p))

import itertools
A = []
for n in range(N):
    A.append([True,False])
pattern_list = list(itertools.product(*A))
pattern_num = 0
for pattern in pattern_list:
    ok_flug = 1
    for i, line in enumerate(line_list):
            on_num = 0
            for l in line:
                if pattern[l-1]:
                    on_num += 1
            if on_num%2 != p_list[i]:
                ok_flug = 0
    if ok_flug == 1:
        pattern_num += 1
print(pattern_num)

import itertools
N = int(N)
M = int(M)
line_list = []
for i in range(M):
    line = input().split()
    new_list=[]
    for l in line:
        new_list.append(int(l))
    new_list.pop(0)
    line_list.append(new_list)
old_p_list = input().split()
p_list = []
for p in old_p_list:
    p_list.append(int(p))

A = []
for n in range(N):
    A.append([True,False])
pattern_list = list(itertools.product(*A))
pattern_num = 0
for pattern in pattern_list:
    ok_flug = 1
    for i, line in enumerate(line_list):
            on_num = 0
            for l in line:
                if pattern[l-1]:
                    on_num += 1
            if on_num%2 != p_list[i]:
                ok_flug = 0
    if ok_flug == 1:
        pattern_num += 1
print(pattern_num)

import itertools
N,M = input().split()
N = int(N)
M = int(M)
line_list = []
for i in range(M):
    line = input().split()
    new_list=[]
    for l in line:
        new_list.append(int(l))
    new_list.pop(0)
    line_list.append(new_list)
old_p_list = input().split()
p_list = []
for p in old_p_list:
    p_list.append(int(p))

A = []
for n in range(N):
    A.append([True,False])
pattern_list = list(itertools.product(*A))
pattern_num = 0
for pattern in pattern_list:
    ok_flug = 1
    for i, line in enumerate(line_list):
            on_num = 0
            for l in line:
                if pattern[l-1]:
                    on_num += 1
            if on_num%2 != p_list[i]:
                ok_flug = 0
    if ok_flug == 1:
        pattern_num += 1
print(pattern_num)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
from itertools import product
n,m = map(int,(input().split()))
sw =[list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for bit in product([0, 1], repeat=n):
    onoff = [1] * n 
    ele = True
    for i, j in enumerate(bit):
        if j == 1:
            onoff[i] = 0
    for k in range(m):
        cnt = 0
        for l in range(1,sw[k][0]): 
            if onoff[sw[k][l]-1]  == 1:
                cnt += 1
        if cnt % 2 != p[k]:
            ele = False
            break
    if ele :
        ans += 1
print(ans)


from itertools import product
n,m = map(int,(input().split()))
sw =[list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for bit in product([0, 1], repeat=n):
    onoff = [1] * n 
    ele = True
    for i, j in enumerate(bit):
        if j == 1:
            onoff[i] = 0
    for k in range(m):
        cnt = 0
        for l in range(1,sw[k][0]): 
            if onoff[sw[k][l]-1]  == 1:
                cnt += 1
        if cnt % 2 != p[m-1]:
            ele = False
            break
    if ele :
        ans += 1
print(ans)


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

ans = 0
for bit in product([0, 1], repeat=n):
    ele = True 
    for i in range(m): 
        cnt = 0
        for j in sw[i][1:]: 
            #print(j)
            cnt += bit[j-1]
        if cnt % 2 != p[i]:
            ele = False
            break
    if ele:
        ans += 1        
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

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

for i in range(2**n):
  i_2 = str(bin(i))[2:]
  i_bit = i_2.zfill(n)
  print(i_bit)
  

N, M = map(int,input().split())
K = [list(map(int,input().split())) for i in range(M)]
P = list(map(int,input().split()))

switch_sum = 0
switch_ptn = 0
switch_ptn2 = 0


for i in range(2**N):
  i_2 = str(bin(i))[2:]
  i_bit = i_2.zfill(N)
  
  
#  print(i_bit)
  for j in range(M):
    for k in range(1,K[j][0]+1):
      switch_sum += int(i_bit[K[j][k]-1])
    switch_sum = switch_sum%2
#    print(switch_sum,P[j])
    if switch_sum == P[j]:
      switch_ptn += 1
    switch_sum = 0
  if switch_ptn == M:
    switch_ptn2 += 1
  switch_ptn = 0
    
print(switch_ptn2)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n, m = map(int, input().split())
k_s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))

ans = 0

for bit in range(1<<n):
  on = 0
  for i in range(m):
    numon = 0
    k = k_s[i][0]
    s = k_s[i][1:]
    for j in range(k):
      mask = 1<<s[j]
      if mask&bit:
        numon += 1
    if numon%2 == p[i]:
      on += 1
  if on == m:
    ans += 1

print(ans)
  

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

ans = 0

for bit in range(1<<n):
  on = 0
  for i in range(m):
    numon = 0
    k = k_s[i][0]
    s = k_s[i][1:]
    for j in range(k):
      mask = 1<<(s[j]-1)
      if mask&bit:
        numon += 1
    if numon%2 == p[i]:
      on += 1
  if on == m:
    ans += 1

print(ans)
  

Verdicts: Wrong Answer

Accepted