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

testimonies = []
for idx1 in range(n):
    testimony = []
    count = int(input())
    for idx2 in range(count):
        x,y = map(int, input().split())
        testimony.append((x-1, y)) 
    testimonies.append(testimony)

output = 0
for combination in range(2 ** n):
    consistent = True
    for index in range(n):
        if (combination >> index) & 1 == 0:
            continue
        for x,y in testimonies[index]:
            if (index >> x) & 1 != y:
                consistent = False
                break
        if not consistent:
            break
    if consistent:
        output = max(output, bin(combination)[2:].count("1"))
print(output)

Fixed code:
n = int(input())
testimonies = [[] for i in range(n)]
for idx1 in range(n):
    count = int(input())
    for idx2 in range(count):
        x,y = map(int, input().split())
        testimonies[idx1].append((x-1, y))

output = 0
for combination in range(2 ** n):
    consistent = True
    for index in range(n):
        if (combination >> index) & 1 == 0:
            continue
        for x,y in testimonies[index]:
            if (combination >> x) & 1 != y:
                consistent = False
                break
        if not consistent:
            break
    if consistent:
        output = max(output, bin(combination)[2:].count("1"))
print(output)
Buggy code:
N=int(input())
ALL=[]
for i in range(N):
  A=int(input())
  XY=[]
  for k in range(A):
    x,y=map(int,input().split())
    XY+=[[x,y]]
  ALL+=[XY]
ans=0  
for i in range(2**N):
  people=[-1]*N
  anssub=0
  for k in range(N):
    if ((i >> k) & 1):
      if people[k]==1:
        people[k]=-2        
      people[k]=0
      anssub+=1
      for t in ALL[k]:
        if people[t[0]-1]!=t[1] and people[t[0]-1]!=-1:
          people[t[0]-1]=-2
        else:
          people[t[0]-1]=t[1]
    else:
      if people[k]==0:
        people[k]=-2
      people[k]=1  
      for t in ALL[k]:
        if t[1]==0:
          if people[t[0]-1]!=1 and people[t[0]-1]!=-1:
            people[t[0]-1]=-2
          else:
            people[t[0]-1]=1
        else:
          if people[t[0]-1]!=0 and people[t[0]-1]!=-1:
            people[t[0]-1]=-2
          else:
            people[t[0]-1]=0
  if not -2 in people:
    ans=max(ans,anssub)
print(ans)            

Fixed code:
N=int(input())
ALL=[]
for i in range(N):
  A=int(input())
  XY=[]
  for k in range(A):
    x,y=map(int,input().split())
    XY+=[[x,y]]
  ALL+=[XY]
ans=0  
for i in range(2**N):
  people=[-1]*N
  anssub=0
  for k in range(N):
    if ((i >> k) & 1):
      if people[k]==0 or people[k]==-2:
        people[k]=-2        
      else:
        people[k]=1
      anssub+=1
      for t in ALL[k]:
        if people[t[0]-1]!=t[1] and people[t[0]-1]!=-1:
          people[t[0]-1]=-2
        else:
          people[t[0]-1]=t[1]
    else:
      if people[k]==1 or people[k]==-2:
        people[k]=-2
      else:
        people[k]=0  
  if not -2 in people:
    ans=max(ans,anssub)
print(ans)
Buggy code:
def main():
    N = int(input())
    d = defaultdict(list)
    for i in range(N):
        n = int(input())
        for _ in range(n):
            d[i].append(list(map(int, input().split())))
    max_trust_num = 0

    # check all possible combinations of Honest or Unkind.
    for i in range(2**N):
        trust = True

        # assign Honest or Unnkind to each person.
        # if person i is Honest, trust_combs[i] = 1
        # else, trust_combs[i] = 0
        trust_combs = []
        for j in range(N):
            if (i >> j) & 1:
                trust_combs.append(1)
            else:
                trust_combs.append(0)
  
        # check if the combination of Honest or
        # Unkind contradicts the given statements.
        for k in range(len(trust_combs)):
            if trust_combs[k] == 1:
                for l in d[k]:
                    if not l[1] == trust_combs[l[0]-1]:
                        trust = False
        if trust:
            max_trust_num = max(max_trust_num, sum(trust_combs))

    print(max_trust_num)


if __name__ == "__main__":
    main()


Fixed code:
from collections import defaultdict


def main():
    N = int(input())
    d = defaultdict(list)
    for i in range(N):
        n = int(input())
        for _ in range(n):
            d[i].append(list(map(int, input().split())))
    max_trust_num = 0

    # check all possible combinations of Honest or Unkind.
    for i in range(2**N):
        trust = True

        # assign Honest or Unnkind to each person.
        # if person i is Honest, trust_combs[i] = 1
        # else, trust_combs[i] = 0
        trust_combs = []
        for j in range(N):
            if (i >> j) & 1:
                trust_combs.append(1)
            else:
                trust_combs.append(0)
  
        # check if the combination of Honest or
        # Unkind contradicts the given statements.
        for k in range(len(trust_combs)):
            if trust_combs[k] == 1:
                for l in d[k]:
                    if not l[1] == trust_combs[l[0]-1]:
                        trust = False
        if trust:
            max_trust_num = max(max_trust_num, sum(trust_combs))

    print(max_trust_num)


if __name__ == "__main__":
    main()
Buggy code:
n=int(input())
xy=[[] for i in range(n)]
for i in range(n):
  a=int(input())
  for j in range(a):
    x,y=map(int,input().split())
    x-=1
    xy.append((x,y))
ans=0
for i in range(1<<n):
  cnt=bin(i).count("1")
  if cnt<=ans:continue
  for j in range(n):
    if i&(1<<j):
      for x,y in xy[j]:
        if y==1 and i&(1<<x):continue
        if y==0 and i&(1<<x)==0:continue
        break
      else:
        continue
      break
  else:
    ans=cnt
print(ans)






Fixed code:
n=int(input())
xy=[[] for i in range(n)]
for i in range(n):
  a=int(input())
  for j in range(a):
    x,y=map(int,input().split())
    xy[i].append([x,y])
ans=0
for b in range(1<<n):
  cnt=bin(b).count("1")
  if cnt<=ans:continue
  for j in range(n):
    if b&(1<<j):
      for x,y in xy[j]:
        if y==1 and b&(1<<x-1): continue
        if y==0 and b&(1<<x-1)==0: continue
        break
      else:
        continue
      break
  else:
    ans=cnt
print(ans)
Buggy code:
import itertools 
n=int(input())
g=[[-1 for _ in range(15)] for _ in range(15)]
for i in range(n):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        g[i][x-1]=y
ans=0

for i in range(2**n):
    honests = [0 for _ in range(n)]
    for j in range(n):
        if(i>>j)&1:
            honests[j]=1
    print(honests)
    ok=True
    for j in range(n):
        if honests[j]:
            for k in range(n):
                if g[j][k]==-1: continue
                if g[j][k]!=honests[k]: ok=False
    if ok:
        ans=max(ans,honests.count(1))
print(ans)

Fixed code:
import itertools 
n=int(input())
g=[[-1 for _ in range(15)] for _ in range(15)]
for i in range(n):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        g[i][x-1]=y
ans=0

for i in range(2**n):
    honests = [0 for _ in range(n)]
    for j in range(n):
        if(i>>j)&1:
            honests[j]=1
    ok=True
    for j in range(n):
        if honests[j]:
            for k in range(n):
                if g[j][k]==-1: continue
                if g[j][k]!=honests[k]: ok=False
    if ok:
        ans=max(ans,honests.count(1))
print(ans)
Buggy code:
N=int(input())
X=[]
Y=[]
for n in range(N):
    A=int(input())
    lx=[]
    ly=[]
    for m in range(A):
        x,y=map(int,input().strip().split())
        lx.append(x)
        ly.append(y)
    X.append(lx)
    Y.append(ly)    

def judge(l,X,Y):
    honest=True
    for n in range(N):
        if l[n]==1:
            for i in range(len(X[n])):
                if l[X[n][i]-1]!=Y[n][i]:
                    honest=False
    return honest

ans=0
def dfs(l,N): #honest=1,unkind=0
    if len(l)==N:
        global ans
        if judge(l,X,Y):
            ans=max(ans,sum(l))
            return
    else:
        for n in range(2):
            l.append(n)
            print(l)
            dfs(l,N)
            l.pop()

dfs([],N)
print(ans)  

Fixed code:
N=int(input())
X=[]
Y=[]
for n in range(N):
    A=int(input())
    lx=[]
    ly=[]
    for m in range(A):
        x,y=map(int,input().strip().split())
        lx.append(x)
        ly.append(y)
    X.append(lx)
    Y.append(ly)    

def judge(l,X,Y):
    honest=True
    for n in range(N):
        if l[n]==1:
            for i in range(len(X[n])):
                if l[X[n][i]-1]!=Y[n][i]:
                    honest=False
    return honest

ans=0
def dfs(l,N): #honest=1,unkind=0
    if len(l)==N:
        global ans
        if judge(l,X,Y):
            ans=max(ans,sum(l))
            return
    else:
        for n in range(2):
            l.append(n)
            dfs(l,N)
            l.pop()

dfs([],N)
print(ans)
Buggy code:
n = int(input())
A = []
X = []
for i in range(n):
    a = int(input())
    A.append(a)
    lis = []
    for j in range(a):
        lis.append(list(map(int, input().split())))
    X.append(lis)

ans = 0
for i in range(2 ** n):
    H_lis = [0 for i in range(n)]
    for j in range(n):
        if ((i >> j) & 1):
            H_lis[j] = 1
    flag = True
    j = 0
    while j < n and flag:
        if H_lis[j] == 1:
            for k in range(A[k]):
                if X[j][k][1] != H_lis[X[j][k][0] - 1]:
                    flag = False
                    break
        j += 1
    if flag:
        ans = max(ans, H_lis.count(1))
print(ans)

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

ans = 0
for i in range(2 ** n):
    H_lis = [0 for i in range(n)]
    for j in range(n):
        if ((i >> j) & 1):
            H_lis[j] = 1
    flag = True
    j = 0
    while j < n and flag:
        if H_lis[j] == 1:
            for k in range(A[j]):
                if X[j][k][1] != H_lis[X[j][k][0] - 1]:
                    flag = False
                    break
        j += 1
    if flag:
        ans = max(ans, H_lis.count(1))
print(ans)
Buggy code:
def bin_(n):
    return str(bin(n))[2: ]

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

start = 2**N-1
max_ = 0
for i in range(2**N):
    num = i
    uso = 0
    
    keta=bin(num)[2:]
    
    while(len(keta)<N):
        keta = "0"+keta
    print(keta)
    for j in range(N):
        if(keta[j]=="1"):
            for p in range(len(syougen[j])):
                
                x,y = syougen[j][p]
                if(keta[x] != str(y)):
                    uso = 1
                    break
    
    suuji = str(bin(num))[2:]
    count  = 0
    for i in range(len(suuji)):
        if(suuji[i]=="1"):
            count += 1
            
    if(uso==0):
        max_ = max(max_,count)
        
print(max_)

Fixed code:
def bin_(n):
    return str(bin(n))[2: ]

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

start = 2**N-1
max_ = 0
for i in range(2**N):
    num = i
    uso = 0
    
    keta=bin(num)[2:]
    
    while(len(keta)<N):
        keta = "0"+keta
    for j in range(N):
        if(keta[j]=="1"):
            for p in range(len(syougen[j])):
                
                x,y = syougen[j][p]
                if(keta[x] != str(y)):
                    uso = 1
                    break
    
    suuji = str(bin(num))[2:]
    count  = 0
    for i in range(len(suuji)):
        if(suuji[i]=="1"):
            count += 1
            
    if(uso==0):
        max_ = max(max_,count)
        
print(max_)
Buggy code:
# ABC147C - HonestOrUnkind2
from itertools import combinations


def main():
    N = int(input())
    testimonies = [[] for _ in range(N + 1)]
    for i in range(1, N + 1):
        A = int(input())
        for _ in range(A):
            testimonies[i].append(map(int, input().split()))

    for cnt_honest in range(N, 0, -1):
        for honest_people in combinations(range(1, N + 1), cnt_honest):
            is_consistent = True
            for i in honest_people:
                for x, y in testimonies[i]:
                    if (x in honest_people and not y) or (x not in honest_people and y):
                        is_consistent = False
                        break
                if not is_consistent:
                    break
            if is_consistent:
                print(cnt_honest)
                return
    print(0)


if __name__ == "__main__":
    main()


Fixed code:
# ABC147C - HonestOrUnkind2
from itertools import combinations


def main():
    N = int(input())
    testimonies = {i: {} for i in range(1, N + 1)}
    for i in range(1, N + 1):
        A = int(input())
        for _ in range(A):
            x, y = map(int, input().split())
            testimonies[i][x] = y

    for cnt_honest in range(N, 0, -1):
        for honest_people in combinations(range(1, N + 1), cnt_honest):
            honest_people = set(honest_people)
            is_consistent = True
            for i in honest_people:
                for x, y in testimonies[i].items():
                    if (x in honest_people and not y) or (x not in honest_people and y):
                        is_consistent = False
                        break
                if not is_consistent:
                    break
            if is_consistent:
                print(cnt_honest)
                return
    print(0)


if __name__ == "__main__":
    main()
Buggy code:
import itertools
N = int(input())
item = []
for i in range(N):
    A = int(input())
    s = []
    for ii in range(A):
        x, y = map(int, input().split())
        s.append((x, y))
        item.append(s)

Ps = itertools.product([0, 1], repeat=N)
ans = 0
for P in Ps:
    right = True
    for i, p in enumerate(P):
        if p == 1:
            for x, y in item[i]:
                if (y == 1 and P[x - 1] == 0) or (y == 0 and P[x - 1] == 1):
                    right = False
    if right:
        ans = max(ans, sum(P))

print(ans)

Fixed code:
import itertools
N = int(input())
item = []
for i in range(N):
    A = int(input())
    s = []
    for ii in range(A):
        x, y = map(int, input().split())
        s.append((x, y))
    item.append(s)

Ps = itertools.product([0, 1], repeat=N)
ans = 0
for P in Ps:
    right = True
    for i, p in enumerate(P):
        if p == 1:
            for x, y in item[i]:
                if (y == 1 and P[x - 1] == 0) or (y == 0 and P[x - 1] == 1):
                    right = False
    if right:
        ans = max(ans, sum(P))

print(ans)
Buggy code:
N = int(input())

g = [[-1]*N for i in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = [int(n) for n in input().split(' ')]
        g[i][x-1] = y

ans = 0
for i in range(1<<N):
    d = [0]*N
    for j in range(N):
        if i>>j&1:
            d[j]=1
    ok = True
    for j in range(N):
        if d[j]:
            for k in range(N):
                if g[j][k] == -1:
                    continue
                if g[j][k] == d[k]:
                    ok=False
    if ok:
        ans = max(ans, bin(i).count("1"))

print(ans)
        


Fixed code:
N = int(input())

g = [[-1]*N for i in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = [int(n) for n in input().split(' ')]
        g[i][x-1] = y

ans = 0
for i in range(1<<N):
    d = [0]*N
    for j in range(N):
        if i>>j&1:
            d[j]=1
    ok = True
    for j in range(N):
        if d[j]:
            for k in range(N):
                if g[j][k] == -1:
                    continue
                if g[j][k] != d[k]:
                    ok=False
    if ok:
        ans = max(ans, bin(i).count("1"))

print(ans)
Buggy code:
from itertools import product

def solve():
    N = int(input())
    graph = {i: [] for i in range(1, N+1)}
    for i in range(N): 
        A = int(input())
        for _ in range(A):
            x,y = map(int, input().split())
            graph[i+1].append((x,y))
            
    def dfs(nodes):
        searched = [-1] * N
        stack = [i+1 for i,node in enumerate(nodes) if node == 1]
        ret_len = len(stack)
        
        while stack:
            node = stack.pop(0)
            for x,y in graph[node]:
                if nodes[x-1] != y: return -1
                if searched[x-1] == -1:
                    searched[x-1] = y
                    if y == 1: stack.append(x)
                        
        # print(nodes, searched)
        return ret_len
                    
        
    ret = 0
    for nodes in product([0,1], repeat=N):
        ret = max(ret, dfs(nodes))
        
    print(ret)

Fixed code:
from itertools import product

def solve():
    N = int(input())
    graph = {i: [] for i in range(1, N+1)}
    for i in range(N): 
        A = int(input())
        for _ in range(A):
            x,y = map(int, input().split())
            graph[i+1].append((x,y))
            
    def dfs(nodes):
        searched = [-1] * N
        stack = [i+1 for i,node in enumerate(nodes) if node == 1]
        ret_len = len(stack)
        
        while stack:
            node = stack.pop(0)
            for x,y in graph[node]:
                if nodes[x-1] != y: return -1
                if searched[x-1] == -1:
                    searched[x-1] = y
                    if y == 1: stack.append(x)
                        
        # print(nodes, searched)
        return ret_len
                    
        
    ret = 0
    for nodes in product([0,1], repeat=N):
        ret = max(ret, dfs(nodes))
        
    print(ret)
    
solve()
Buggy code:
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
tes = [[-1]*N for i in range(N)]
for i in range(N):
    A = int(readline())
    for j in range(A):
        x,y = map(int,readline().rstrip().split())
        tes[i][x-1] = y

cnt = 0
for i in range(2**N):
    hon = [0]*N
    for j in range(N):
        if (i>>j)&1:
            hon[j] = 1
    flag = True
    for j in range(N):
        if hon[j]:
            for k in range(N):
                if tes[j][k] != hon[k]:
                    flag = False
                    break
        if not flag:
            break
    if flag:
        cnt = max(cnt,hon.count(1))
print(cnt)

Fixed code:
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
tes = [[-1]*N for i in range(N)]
for i in range(N):
    A = int(readline())
    for j in range(A):
        x,y = map(int,readline().rstrip().split())
        tes[i][x-1] = y

cnt = 0
for i in range(2**N):
    hon = [0]*N
    for j in range(N):
        if (i>>j)&1:
            hon[j] = 1
    flag = True
    for j in range(N):
        if hon[j]:
            for k in range(N):
                if tes[j][k] == -1:
                    continue
                if tes[j][k] != hon[k]:
                    flag = False
                    break
        if not flag:
            break
    if flag:
        cnt = max(cnt,hon.count(1))
print(cnt)
Buggy code:
N=int(input())
xy=[[] for in range(N)]
for _ in range(N):
    A = int(input())
    for __ in range(A):
        x, y = map(int, input().split())
        xy[_].append((x-1,y))

ans = 0
for p in range(1<<N):
    h = []
    judge = True
    for i in range(N):
        h.append(p&1)
        p>>=1
    for i in range(N):
        for x, y in xy[i]:
            if h[i] and y != h[x]:
                judge = False
                break
        if not judge: break
    if not judge: continue
    ans = max(ans,sum(h))

print(ans)


Fixed code:
N=int(input())
xy=[[] for _ in range(N)]
for _ in range(N):
    A = int(input())
    for __ in range(A):
        x, y = map(int, input().split())
        xy[_].append((x-1,y))

ans = 0
for p in range(1<<N):
    h = []
    judge = True
    for i in range(N):
        h.append(p&1)
        p>>=1
    for i in range(N):
        for x, y in xy[i]:
            if h[i] and y != h[x]:
                judge = False
                break
        if not judge: break
    if not judge: continue
    ans = max(ans,sum(h))

print(ans)
Buggy code:
import sys
input = sys.stdin.readline
def main():
    N  = int(input())
    R = [[] for i in range(N)]
    for i in range(N):
        A = int(input())
        R[i] = [list(map(int, input().split())) for i in range(A)]
    ans = 0
    for i in range(1<<N):
        CNT = 0
        for j in range(N):
            if not (i>>j & 1):
                continue
            CNT += 1
            for x, y in R[j]:
                if y == 1 and (i>>(x-1) & 1):
                    continue
                else:
                    CNT = 0
                    break

        ans = max(ans, CNT)
    print(ans)

if __name__ == '__main__':
    main()

Fixed code:
import sys
input = sys.stdin.readline
def main():
    N  = int(input())
    R = [[] for i in range(N)]
    for i in range(N):
        A = int(input())
        R[i] = [list(map(int, input().split())) for i in range(A)]
    ans = 0
    for i in range(1<<N):
        CNT = 0
        for j in range(N):
            if not (i>>j & 1):
                continue
            CNT += 1
            for x, y in R[j]:
                if y == 1 and (i>>(x-1) & 1):
                    continue
                elif y == 0 and (not (i>>(x-1) & 1)):
                    continue
                else:
                    CNT = 0
                    break
            else:
                continue
            break

        ans = max(ans, CNT)
    print(ans)

if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
xy = []
for _ in range(n):
    a = int(input())
    xy.append([list(map(int, input().split())) for _ in range(a)])

ans = 0
for i in range(2**n):
    pat = []
    for j in range(n):
        pat.append((i>>j)%2)
    check = True
    for j in range(n):
        if pat[j]:
            for z in xy[j]:
                if pat[z[0]-1] != z[1]:
                    check = False
    if check:
        print(pat)
        ans = max(ans, sum(pat))
print(ans)


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

ans = 0
for i in range(2**n):
    pat = []
    for j in range(n):
        pat.append((i>>j)%2)
    check = True
    for j in range(n):
        if pat[j]:
            for z in xy[j]:
                if pat[z[0]-1] != z[1]:
                    check = False
    if check:
        ans = max(ans, sum(pat))
print(ans)
Buggy code:
n = int(input())
XY = []
for i in range(n):
    a = int(input())
    xy = []
    for j in range(a):
        x, y = map(int, input().split())
        xy.append([x, y])
    XY.append(xy)
ans = 0
for i in range(2 ** n):
    s = [0] * n
    cnt = 0
    case = True
    for j in range(n):
        if (i >> j) & 1:
            s[j] = 1
            cnt += 1
    for k in range(n):
        if s[k] == 1:
            for l in range(len(XY[l])):
                if s[XY[k][l][0] - 1] != XY[k][l][1]:
                    case = False
                    break
    if case is True:
        ans = max(ans, cnt)
print(ans)

Fixed code:
n = int(input())
XY = []
for i in range(n):
    a = int(input())
    xy = []
    for j in range(a):
        x, y = map(int, input().split())
        xy.append([x, y])
    XY.append(xy)
ans = 0
for i in range(2 ** n):
    s = [0] * n
    cnt = 0
    case = 0
    for j in range(n):
        if (i >> j) & 1:
            s[n - 1 - j] = 1
            cnt += 1
    for k in range(n):
        if s[k] == 1:
            for l in range(len(XY[k])):
                if s[XY[k][l][0] - 1] != XY[k][l][1]:
                    case = 1
    if case == 0:
        ans = max(ans, cnt)
print(ans)