qyliang/CodeNanoFix huggingface dataset:
Buggy code:
def main():
    # input
    n = int(input())

    li = []
    for i in range(n):
        a = int(input())
        dic = {}
        for j in range(a):
            x, y = map(int, input().split())
            dic[x] = y
        li.append(dic)
    print(li)

    # calc
    ans = 0
    flag = False
    for num in range(1, 2**n):
        num = bin(num)[2:].rjust(n, '0')
        for i in range(len(li)):
            if num[i] == '1':
                for j, key in enumerate(li[i]):
                    if num[key-1] != str(li[i][key]):
                        flag = True
                        break
                if flag:
                    flag = False
                    break
        else:
            # print(num, ans)
            ans = max(num.count('1'), ans)
    print(ans)




if __name__ == '__main__':
    main()


Fixed code:
def main():
    # input
    n = int(input())

    li = []
    for i in range(n):
        a = int(input())
        dic = {}
        for j in range(a):
            x, y = map(int, input().split())
            dic[x] = y
        li.append(dic)
    # print(li)

    # calc
    ans = 0
    flag = False
    for num in range(1, 2**n):
        num = bin(num)[2:].rjust(n, '0')
        for i in range(len(li)):
            if num[i] == '1':
                for j, key in enumerate(li[i]):
                    if num[key-1] != str(li[i][key]):
                        flag = True
                        break
                if flag:
                    flag = False
                    break
        else:
            # print(num, ans)
            ans = max(num.count('1'), ans)
    print(ans)




if __name__ == '__main__':
    main()
Buggy code:
from itertools import product

N = int(input())
xy = [[] for in range(N)]

for i in range(N):
    for j i range(int(input())):
        xy[i].append(list(map(int, input().split())))
        
ans = 0
for bit in product([0,1], repeat=N):
    f = 0
    for i, j in enumerate(bit):
        if j == 1:
            for x, y in xy[i]:
                if bit[x-1] != y:
                    f = 1
                    break
    if f == 0:
        ans = max(ans, sum(bit))
print(ans)

Fixed code:
from itertools import product

N = int(input())
xy = [[] for i in range(N)]

for i in range(N):
    for j in range(int(input())):
        xy[i].append(list(map(int, input().split())))
        
ans = 0
for bit in product([0,1], repeat=N):
    f = 0
    for i, j in enumerate(bit):
        if j == 1:
            for x, y in xy[i]:
                if bit[x-1] != y:
                    f = 1
                    break
    if f == 0:
        ans = max(ans, sum(bit))
print(ans)
Buggy code:
n = int(input())

A = []

for _ in range(n):
    t = int(input())
    A.append([list(map(int, input().split())) for _ in range(t)])

ans = 0
max = 0
flag = 0

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

Fixed code:
n = int(input())

A = []

for _ in range(n):
    t = int(input())
    A.append([list(map(int, input().split())) for _ in range(t)])

ans = 0
max = 0
flag = 0

for i in range(2**n):
    ans = 0
    flag = 0
    for j in range(n):
        if ((i>>j) & 1) == 1 and flag ==  0:
            for k,l in A[j]:
                if ((i>>(k-1)) & 1) != l:
                    flag = 1
                    break
    if flag == 0:
        ans = bin(i).count('1')
        if ans > max:
            max = ans
print(max)
Buggy code:
def int_to_list(bit, n):
    l = []
    for i in range(n):
     if bit & (1 << i):
         l.append(i)
    return l

def solve():
    N = int(input())
    
    l = [[] for _ in range(N)]
    for i in range(N):
        for _ in range(int(input())):
            p, q = map(int, input().split())
            l[i].append((p, q))

    ans = 0
    for i in range(1 << N):
        partial = int_to_list(i, N)

        for j in range(N):
            f = True
            for p, q in l[j]:
                r = p-1
                if q == 0 and r in partial:
                    f = False
                if q == 1 and not r in partial:
                    f = False
        if f:
            ans = max(ans, len(partial))
            
    return ans

print(solve())

Fixed code:
def int_to_list(bit, n):
    l = []
    for i in range(n):
     if bit & (1 << i):
         l.append(i)
    return l

def solve():
    N = int(input())
    
    l = [[] for _ in range(N)]
    for i in range(N):
        for _ in range(int(input())):
            p, q = map(int, input().split())
            l[i].append((p-1, q))

    ans = 0
    for i in range(1 << N):
        partial = int_to_list(i, N)

        f = True
        for j in range(N):
            if j not in partial: continue
            for p, q in l[j]:
                if q == 0 and p in partial:
                    f = False
                if q == 1 and not p in partial:
                    f = False
        if f:
            ans = max(ans, len(partial))
            
    return ans

print(solve())
Buggy code:
def main():
    N = int(input())
    S = [[] * N for i in range(N)]
    ans = 0

    for i in range(N):
        A = int(input())
        for j in range(A):
            x, y = map(int, input().split())
            S[i].append([x-1, y])

    P = [0]*N

    for i in range(2**N):
        for j in range(N):
            if P[j] == 0:
                P[j] = 1
                break
            else:
                P[j] = 0

        if sum(P) <= ans:
            continue
        flag = 0
        for p in range(len(P)):
            if P[p] == 1:
                for s in S[p]:
                    if s[1]!= P[s[0]]:
                        flag = 1
        if flag == 1:
            continue
        else:
            ans = sum(P)

    print(ans)


 
if name == 'main':
    main()


Fixed code:
def main():
    N = int(input())
    S = [[] * N for i in range(N)]
    ans = 0

    for i in range(N):
        A = int(input())
        for j in range(A):
            x, y = map(int, input().split())
            S[i].append([x-1, y])

    P = [0]*N
    
    for i in range(2**N):
        for j in range(N):
            if P[j] == 0:
                P[j] = 1
                break
            else:
                P[j] = 0
        
        if sum(P) <= ans:
            continue
        flag = 0
        for p in range(len(P)):
            if P[p] == 1:
                for s in S[p]:
                    if s[1]!= P[s[0]]:
                        flag = 1
        if flag == 1:
            continue
        else:
            ans = sum(P)
        
    print(ans)


 
if __name__ == '__main__':
    main()
Buggy code:
n = int(input())

stm = [[] for i in range(n)]

def possible(honest):
    for i in range(n):
        if honest[i] == '0':
            continue
        for j in range(len(stm[i])):
            if stm[i][j][1] == 1 and honest[stm[i][j][0]-1] == '0':
                return False
            elif stm[i][j][1] == 0 and honest[stm[i][j][0]-1] == '1':
                return False
    return True

            

for i in range(n):
    a = int(input())
    x,y = map(int, input().split())
    stm[i].append([x,y])
   
count = 0
for k in range(2**n):
    hon = list(bin(k)[2:])
    hon = ['0']*(n-len(hon)) + hon
    if possible(hon):
        print(hon)
        count = max(count, sum([int(x) for x in hon]))
print(count)            

Fixed code:
n = int(input())

stm = [[] for i in range(n)]

def possible(honest):
    #print(honest)
    for i in range(n):
        if honest[i] == '0':
            continue
        for j in range(len(stm[i])):
            #print(stm[i][j])
            #print(honest[stm[i][j][0]-1])
            if stm[i][j][1] == 1 and honest[stm[i][j][0]-1] == '0':
                return False
            elif stm[i][j][1] == 0 and honest[stm[i][j][0]-1] == '1':
                return False
    return True

            

for i in range(n):
    a = int(input())
    for _ in range(a):
        x,y = map(int, input().split())
        stm[i].append([x,y])
   
count = 0
for k in range(2**n):
    hon = list(bin(k)[2:])
    hon = ['0']*(n-len(hon)) + hon
    if possible(hon):
        count = max(count, sum([int(x) for x in hon]))
print(count)
Buggy code:
N = int(input())
A = [[-1 for i in range(N)] for i in range(N)]
for i in range(N):
    m = int(input())
    for i in range(m):
        x,y = map(int,input().split())
        A[i][x-1] = y
ans = 0
for i in range(1<<N):
    honets = [0 for i in range(N)]
    for j in range(N):
        if (i>>j) & 1:
            honets[j] = 1
    ok = True
    for j in range(N):
        if honets[j] == 1:
            for k in range(N):
                if A[j][k] == -1: continue
                if A[j][k] != honets[k]: ok = False
    if ok:
        ans = max(ans, honets.count(1))
print(ans)


Fixed code:
N = int(input())
A = [[-1 for i in range(N)] for i in range(N)]
for i in range(N):
    m = int(input())
    for j in range(m):
        x,y = map(int,input().split())
        A[i][x-1] = y
#print(A)
ans = 0
for i in range(1<<N):
    honets = [0 for i in range(N)]
    for j in range(N):
        if (i>>j) & 1:
            honets[j] = 1
    ok = True
    for j in range(N):
        if honets[j] == 1:
            for k in range(N):
                if A[j][k] == -1: continue
                if A[j][k] != honets[k]: ok = False
    if ok:
        ans = max(ans, honets.count(1))
print(ans)
Buggy code:
n = int(input())
s = []
a = []
for i in range(n):
    aa = int(input())
    a.append(aa)
    c = []
    for j in range(aa):
        xy = list(map(int,input().split()))
        c.append(xy)
    s.append(c)
#print(s[0])
sy = []
ans = 0

def syojiki(sy,count):
    if count == n:
   #     print(sy)
        check = [[] for i in range(n)]
        for i in range(n):
            if sy[i] == 1:
                check[i].append(1)
                for j in range(a[i]):
                    if s[i][j][1] not in check[s[i][j][0]-1]:
                        check[s[i][j][0]-1].append(s[i][j][1])
  #      print(check)
        check2 = 0
        for i in range(n):
            if len(check[i]) <= 1:
                check2 += 1
   #     print(check2)
        if check2 == n:
            global ans
            ans = max(ans,check.count([1]))
  #      print(ans)
    else:
        syojiki(sy+[0],count+1)
        syojiki(sy+[1],count+1)

syojiki(sy,0)
print(ans)

Fixed code:
n = int(input())
s = []
a = []
for i in range(n):
    aa = int(input())
    a.append(aa)
    c = []
    for j in range(aa):
        xy = list(map(int,input().split()))
        c.append(xy)
    s.append(c)
#print(s[0])
sy = []
ans = 0
 
def syojiki(sy,count):
    if count == n:
     #   print(sy)
        check = [[] for i in range(n)]
        for i in range(n):
            if sy[i] == 1:
                check[i].append(1)
        for i in range(n):
            if sy[i] == 1:
                for j in range(a[i]):
                    if s[i][j][1] not in check[s[i][j][0]-1]:
                        check[s[i][j][0]-1].append(s[i][j][1])
    #    print(check)
        check2 = 0
        for i in range(n):
            if len(check[i]) == 0:
                check2 += 1
            elif len(check[i]) == 1 and check[i][0] == sy[i]:
                check2 += 1
   #     print(check2)
        if check2 == n:
            global ans
            ans = max(ans,check.count([1]))
   #         print(ans)
    else:
        syojiki(sy+[0],count+1)
        syojiki(sy+[1],count+1)
 
syojiki(sy,0)
print(ans)
Buggy code:
N = int(input())
l = []
ans = 0
for i in range(N):
    A = int(input())
    for j in range(A):
        l.append(list(map(int,input().split())))
for bit in range(1<<N):
    flag = True
    listH = [(bit>>i)&1 for i in range(N)]
    for i in range(N):
        if not listH[i]:
            continue
        for k in range(2):
            x = l[i][0]-1
            y = l[i][1]
            if listH[x] != y:
                flag = False
    if flag:
        ans = max(ans,sum(listH))
print(ans)

Fixed code:
N = int(input())
L = []
l = []
A = []
ans = 0
for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        l.append(list(map(int,input().split())))
    L.append(l)
    l = []
for bit in range(1<<N):
    flag = True
    listH = [(bit>>i)&1 for i in range(N)]
    for j in range(N):
        if not listH[j]:
            continue
        for k in range(A[j]):
            x = L[j][k][0]-1
            y = L[j][k][1]
            if listH[x] != y:
                flag = False
    if flag:
        ans = max(ans,sum(listH))
print(ans)
Buggy code:
N = int(input())
xy = [[] for _ in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        xy_ = tuple(map(int,input().split()))
        xy[i].append(xy_)

bN = 2**N
ans = 0
for b in range(bN):
    for n in range(N):
        if (b >> n) & 1:
            for x,y in xy[n]:
                if y != b >> (x-1):
                    break
            else:
                continue
            break
    else:
        ans = max(ans,bin(b).count("1"))
print(ans)


Fixed code:
N = int(input())
xy = [[] for _ in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        xy_ = tuple(map(int,input().split()))
        xy[i].append(xy_)

bN = 2**N
ans = 0
for b in range(bN):
    for n in range(N):
        if (b >> n) & 1:
            for x,y in xy[n]:
                if y != (b >> (x-1) & 1):
                    break
            else:
                continue
            break
    else:
        ans = max(ans,bin(b).count("1"))
print(ans)
Buggy code:
N = int(input())
XYList = []
for i in range(N):
    A = int(input())
    for j in range(A):
        XY = []
        XY.append(list(map(int, input().split())))
    XYList.append(XY)
maxSum = 0
for i in range(2**N):
    sum = 0
    for j in range(N):
        if i >> j & 1:
            honest = True
            for XY in XYList[j]:
                if ((i >> (XY[0]-1)) & 1) != XY[1]:
                    honest = False
                    break
            if honest:
                sum += 1
            else:
                sum = 0
                break
    if maxSum < sum:
        maxSum = sum
print(maxSum)

Fixed code:
N = int(input())
XYList = []
for i in range(N):
    A = int(input())
    XY = []
    for j in range(A):
        XY.append(list(map(int, input().split())))
    XYList.append(XY)
maxSum = 0
for i in range(2**N):
    sum = 0
    for j in range(N):
        if i >> j & 1:
            honest = True
            for XY in XYList[j]:
                if ((i >> (XY[0]-1)) & 1) != XY[1]:
                    honest = False
                    break
            if honest:
                sum += 1
            else:
                sum = 0
                break
    if maxSum < sum:
        maxSum = sum
print(maxSum)
Buggy code:
import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import functools
import itertools
import math
INF = float('inf')
MOD = 10**9+7

N = int(input())
As = [None] * N
ts = [[] for i in range(N)]
for i in range(N):
    As[i] = int(input())
    for j in range(As[i]):
        x, y = map(int, input().split())
        ts[i].append((x-1, y))
ans = 0
for ps in itertools.product([0, 1], repeat = N):
    qs = [None] * N
    flg = 1
    for i in range(N):
        if qs[i] != None and qs[i] != ps[i]:
            flg = 0
            break
        if ps[i]:
            for j in range(As[i]):
                x, y = ts[i][j]
                if qs[x] == None:
                    qs[x] = y
                elif qs[x] != y:
                    flg = 0
                    break
        if flg == 0:
            break
    if flg:
        ans = max(ans, sum(ps))
print(ans)


Fixed code:
import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import functools
import itertools
import math
INF = float('inf')
MOD = 10**9+7

N = int(input())
As = [None] * N
ts = [[] for i in range(N)]
for i in range(N):
    As[i] = int(input())
    for j in range(As[i]):
        x, y = map(int, input().split())
        ts[i].append((x-1, y))
ans = 0
for ps in itertools.product([0, 1], repeat = N):
    # print(ps)
    qs = [None] * N
    flg = 1
    for i in range(N):
        if qs[i] != None and qs[i] != ps[i]:
            flg = 0
            break
        qs[i] = ps[i]
        if ps[i]:
            for j in range(As[i]):
                x, y = ts[i][j]
                if qs[x] == None:
                    qs[x] = y
                elif qs[x] != y:
                    flg = 0
                    break
        if flg == 0:
            break
    if flg:
        ans = max(ans, sum(ps))
print(ans)
Buggy code:
n = int(input())

s =[[] for _ in range(n)]

for i in range(n):
    a_tmp = int(input())
    for _ in range(a_tmp):
        x,y = map(int,input().split())
        s[i].append([x,y])

#print(s)

mx = 2**n -1


def hantei(num):
    flag=0
    bi =[0 for _ in range(n)]
    for j in range(n):
        if((num>>j)%2 == 1):
            for x,y in s[j]:
                if(y != bi[x-1]):
                    flag = 1
                    return flag
    
    return flag

ans = 0 
for i in range(mx):
    if(hantei(i) == 0):
        #print(i)
        ans = max(ans,bin(i)[2::].count("1"))
        
print(ans)

#print(bin(3)[2::].count("1"))
#print(hantei(3))

Fixed code:
n = int(input())

s =[[] for _ in range(n)]

for i in range(n):
    a_tmp = int(input())
    for _ in range(a_tmp):
        x,y = map(int,input().split())
        s[i].append([x,y])

#print(s)

mx = 2**n


def hantei(num):
    flag=0
    bi =[0 for _ in range(n)]
    for j in range(n):
        bi[j] = (num>>j)%2
    
    for j in range(n):
        if((num>>j)%2 == 1):
            for x,y in s[j]:
                if(y != bi[x-1]):
                    flag = 1
                    return flag
    
    return flag

ans = 0 
for i in range(mx):
    if(hantei(i) == 0):
        #print(i)
        ans = max(ans,bin(i)[2::].count("1"))
        
print(ans)

#print(bin(3)[2::].count("1"))
#print(hantei(3))
Buggy code:
N = int(input())
C = []

flg = False
for _ in range(N):
    a = int(input())
    comment = [[int(_) for _ in input().split()] for i in range(a)]
    if a:
        flg=True
    C.append(comment)
if not flg :
    print(N)
    exit()


def bit_tbl2(length):
    _format = "{:0" + str(length) + "b}"
    for i in range(int('1' * length, 2) + 1):
        yield _format.format(i)


ans = 0
for b in bit_tbl2(N):
    # print(b)
    syo = [-1] * (N + 1)
    flg = False
    for i in range(N):
        if b[i] == '1':
            syo[i+1] = 1

    for i in range(N):
        if b[i] != '1': continue

        for x, y in C[i]:
            if syo[x] != -1 and y != syo[x]:
                flg = True
                break
            syo[x] = y

        if flg: break

    if not flg:

        v = 0
        for x in syo:
            if x == 1: v += 1
        # print(v)

        ans = max(ans, v)
print(ans)


Fixed code:
N = int(input())
C = []

flg = False
for _ in range(N):
    a = int(input())
    comment = [[int(_) for _ in input().split()] for i in range(a)]
    if a:
        flg=True
    C.append(comment)
if not flg :
    print(N)
    exit()


def bit_tbl2(length):
    _format = "{:0" + str(length) + "b}"
    for i in range(int('1' * length, 2) + 1):
        yield _format.format(i)


ans = 0
for b in bit_tbl2(N):
    # print(b)
    syo = [-1] * (N + 1)
    flg = False

    for i in range(N):
        if b[i] == '1':
            syo[i+1] = 1

    for i in range(N):
        if b[i] != '1': continue

        for x, y in C[i]:
            if y == 1 and syo[x] != 1:
                flg = True
                break
            if syo[x] != -1 and y != syo[x]:
                flg = True
                break
            syo[x] = y

        if flg: break

    if not flg:

        v = 0
        for x in syo:
            if x == 1: v += 1
        # print(v)

        ans = max(ans, v)
print(ans)
Buggy code:
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-


def main():
    N = int(input())
    XY = [[] for _ in range(N)]
    for i in range(N):
        A = int(input())
        XY[i] = [list(map(int, input().split())) for _ in range(A)]

    max_H = 0
    for i in range(2**N):
        bin = format(i, '015b')[::-1]
        ok = True

        for j in range(N):
            for x, y in XY[j]:
                if bin[j] == '1' and y != int(bin[x - 1]):
                    ok = False
                    break
                else:
                    continue
                break
        if ok:
            H = sum(int(x) for x in bin)
            max_H = max(max_H, H)
        print(max_H)


if __name__ == "__main__":
    main()


Fixed code:
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-


def main():
    N = int(input())
    XY = [[] for _ in range(N)]
    for i in range(N):
        A = int(input())
        XY[i] = [list(map(int, input().split())) for _ in range(A)]

    max_H = 0
    for i in range(2**N):
        bin = format(i, '015b')[::-1]
        ok = True

        for j in range(N):
            for x, y in XY[j]:
                if bin[j] == '1' and y != int(bin[x - 1]):
                    ok = False
                    break
                else:
                    continue
                break
        if ok:
            H = sum(int(x) for x in bin)
            max_H = max(max_H, H)
    print(max_H)


if __name__ == "__main__":
    main()
Buggy code:
n=int(input())
xy=[[] for i in range(n)]
ans=0
a=[0]*n
for i in range(n):
  a[i]=int(input())
  for j in range(a[i]):
    x,y=map(int,input().split())
    xy[i].append([x,y])
for i in range(2**n):
  temp=[0]*n
  for j in range(n):
    if ((i >> j) & 1):
      temp[j]=1
  count=True
  for j in range(n):
    for k in range(a[j]):
      if temp[j]==1:
        p=xy[j][k][0]
        if temp[p]!=xy[j][k][0]:
          count=False
      else:
        p=xy[j][k][0]
        if temp[p]==xy[j][k][0]:
          count=False     
  if count==True:
    ans=max(ans,sum(temp))
print(ans)

Fixed code:
n=int(input())
xy=[[] for i in range(n)]
ans=0
a=[0]*n
for i in range(n):
  a[i]=int(input())
  for j in range(a[i]):
    x,y=map(int,input().split())
    xy[i].append([x,y])
for i in range(2**n):
  temp=[0]*n
  for j in range(n):
    if ((i >> j) & 1):
      temp[j]=1
  count=True
  for j in range(n):
    for k in range(a[j]):
      if temp[j]==1:
        p=xy[j][k][0]-1
        if temp[p]!=xy[j][k][1]:
          count=False
          break
  if count==True:
    ans=max(ans,sum(temp))
print(ans)
Buggy code:
n = int(input())
a = []
xy = [[] for i in range(n)]
for i in range(n):
  a.append(int(input()))
  for j in range(a[i]):
    xy[i].append(list(map(int, input().split())))

tf = [0]*n
ans = 0
b = 1
for i in range(n**2):
  for j in range(n):
    if (i >> j) & 1:
      tf[j] = 1
  for k in range(n):
    if tf[k] == 1:
      for l in range(a[k]):
        if tf[xy[k][l][0]-1] != xy[k][l][1]:
          b = 0
          break
    if b == 1 and sum(tf) > ans:
      ans = sum(tf)

print(ans)

Fixed code:
n = int(input())
a = []
xy = [[] for i in range(n)]
for i in range(n):
  a.append(int(input()))
  for j in range(a[i]):
    xy[i].append(list(map(int, input().split())))

tf = [0]*n
ans = 0
for i in range(2**n):
  for j in range(n):
    if (i >> j) & 1:
      tf[j] = 1
    else:
      tf[j] = 0
  b = 1
  for k in range(n):
    if tf[k] == 1:
      for l in range(a[k]):
        if tf[xy[k][l][0]-1] != xy[k][l][1]:
          b = 0
          break
  if b == 1 and sum(tf) > ans:
    ans = sum(tf)

print(ans)