Problem p02837 (python)

Fixed submission:
n = int(input())
ls = []
for i in range(n):
    a = int(input())
    p = []
    for i in range(a):
        x,y = map(int,input().split())
        p.append([x-1,y])
    ls.append(p)

ans = 0

for i in range(2**n):
    flag = 0
    for j in range(n):
        if (i >> j) & 1:
            for k in ls[j]:
                if (i>>k[0])&1 != k[1]:
                    flag = 1
                    break
    if flag == 0:
        ans = max(ans, bin(i)[2:].count('1'))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ls = []
for i in range(n):
    a = int(input())
    p = []
    for i in range(a):
        x,y = map(int,input().split())
        p.append([x-1,y])
    ls.append(p)

ans = 0

for i in range(2**n):
    flag = 0
    for j in range(n):
        if (i >> j) & 1:#もし正直者だったら
            for k in ls[j]:#証言の確認
                if (i >> k[0])&1 != k[1]:#もし証言がおかしかったら
                    flag = 1
                    break
    if flag == 0:
        ans = max(ans, bin(i)[2:].count(1))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ls = []
for i in range(n):
    a = int(input())
    for i in range(a):
        x,y = map(int,input().split())
        ls.append([x-1,y])

ans = 0

for i in range(2**n):
    flag = 0
    for j in range(n):
        if (i >> j) & 1:
            for k in ls[j]:
                if (i >> k) & 1 != y:
                    flag = 1
                    break
    if flag == 0:
        ans = max(ans, bin(i)[2:].count('1'))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ls = []
for i in range(n):
    a = int(input())
    for i in range(a):
        x,y = map(int,input().split())
        ls.append([x-1,y])

ans = 0

for i in range(2**n):
    flag = 0
    for j in range(n):
        if (i >> j) & 1:
            for k in ls[j]:
                if (i >> k[0]) & 1 != y:
                    flag = 1
                    break
    if flag == 0:
        ans = max(ans, bin(i)[2:].count('1'))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
lsx = []
lsy = []
ans = 0
def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]
if n==1:
    a = int(input())
    for i in range(a):
    	x,y=map(int,input().split())
      if y==0:
          print(0)
      else:
          print(1)
      break
else:
    for i in range(n):
        a = int(input())
        for j in range(a):
            x,y = map(int,input().split())
            lsx.append(x)
            lsy.append(y)
            if x in lsx:
                p = 0
                p2 = 0
                for k in my_index_multi(lsx,x):
                    if lsy[k] == 1:
                        p+=1
                    else:
                        p2+=1                
                ans+=min(p,p2)
    test=0        
    for i in lsy:
        if i == 0:
            test+=1
    if test==len(lsy):
        print(1)
    else:
        print(n-ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
lsx = []
lsy = []
ans = 0
if n==1:
    a = int(input())
    x,y=map(int,input().split())
    if y==0:
        print(0)
    else:
        print(1)
else:
    for i in range(n):
        a = int(input())
        for j in range(a):
            x,y = map(int,input().split())
            lsx.append(x)
            lsy.append(y)
            if x in lsx:
                if lsy[lsx.index(x)]!=lsy[-1]:
                    ans+=1
    test=0        
    for i in lsy:
        if i == 0:
            test+=1
    if test==len(lsy):
        print(1)
    else:
        print(n-ans)