qyliang/CodeNanoFix huggingface dataset:
Buggy code:
#!/usr/bin/env python3
from itertools import product

# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    N = int(input())
    grid = [[None for _ in range(N)] for i in range(N)]
    for i in range(N):
        a = int(input())
        for _ in range(a):
            x, y = list(map(int, input().split()))
            grid[i][x-1] = y
    res = 0
    for p in product([0, 1], repeat=N):
        flag = True
        p = list(p)
        for i in range(N):
            for j in range(N):
                if p[i] == 1:
                    if grid[i][j] == p[j]:
                        continue
                    flag = False
                    break
            if flag:
                continue
            break
        if flag:
            res = max(res, sum(p))
    print(res)
    pass

if __name__ == '__main__':
    main()


Fixed code:
#!/usr/bin/env python3
from itertools import product

# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    N = int(input())
    grid = [[None for _ in range(N)] for i in range(N)]
    for i in range(N):
        a = int(input())
        for _ in range(a):
            x, y = list(map(int, input().split()))
            grid[i][x-1] = y
    res = 0
    for p in product([0, 1], repeat=N):
        flag = True
        p = list(p)
        for i in range(N):
            if p[i] == 0:
                continue
            for j in range(N):
                if grid[i][j] is None:
                    continue
                if grid[i][j] == p[j]:
                    continue
                flag = False
                break
            if flag:
                continue
            break
        if flag:
            res = max(res, sum(p))
    print(res)
    pass

if __name__ == '__main__':
    main()
Buggy code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
XY = []
for _ in range(N):
    A = int(input())
    xy = [list(mapint()) for _ in range(A)]
    XY.append(xy)

ans = 0
for i in range(1<<N):
    honest = [-1]*N
    cnt = 0
    for j in range(N):
        if (i>>j)&1:
            cnt += 1
            honest[j] = 1
            for x, y in XY[j]:
                if y==0:
                    if honest[x-1]==1:
                        break
                    else:
                        honest[x-1] = 0
                if y==1:
                    if honest[x-1]==0:
                        break
                    else:
                        honest[x-1] = 1
            else:
                ans = max(ans, cnt)

print(ans)

Fixed code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
XY = []
for _ in range(N):
    A = int(input())
    xy = [list(mapint()) for _ in range(A)]
    XY.append(xy)

ans = 0
for i in range(1<<N):
    honest = [-1]*N
    cnt = 0
    ok = True
    for j in range(N):
        if (i>>j)&1:
            honest[j]=1
        else:
            honest[j]=0
    for j in range(N):
        if (i>>j)&1:
            cnt += 1
            for x, y in XY[j]:
                if honest[x-1]!=y:
                    ok = False
                    break
    if ok:
        ans = max(ans, cnt)

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

xy = [[] * n for _ 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
def judge(f):
    for i in range(n):
        print(xy[i], flag)
        for j in range(len(xy[i])):
            if f[xy[i][j][0] - 1] != xy[i][j][1] ^ (f[i] ^ 1):
                return False
    return True

for i in range(2 ** n):
    flag = [0] * n
    for j in range(n):
        if i >> j & 1:
            flag[j] = 1
    print()
    if judge(flag):
        ans = max(ans, sum(flag))
print(ans)

Fixed code:
n = int(input())

xy = [[] * n for _ 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
def judge(f):
    for i in range(n):
        if flag[i] == 1:
            for j in xy[i]:
                if f[j[0] - 1] != j[1]:
                    return False
        
    return True

for i in range(2 ** n):
    flag = [0] * n
    for j in range(n):
        if i >> j & 1:
            flag[j] = 1
    if judge(flag):
        ans = max(ans, sum(flag))
print(ans)
Buggy code:
n = int(input())

def func(x):
  res = []
  for i in range(n):
    res.append(x%2)
    x //= 2
  return res

test = {}
for i in range(n):
  A = int(input())
  test[i+1] = []
  for a in range(A):
    x,y = map(int,input().split())
    test[i].append((x,y))

ans = 0
for i in range(2**n):
  people = func(i)
  for i in range(n):
    if people[i]:
      for x,y in test[i+1]:
        if people[x-1] == y:
          continue
        else:
          break
      else:
        continue
      break
  else:
    ans = max(sum(people),ans)
print(ans)

Fixed code:
n = int(input())

def func(x):
  res = []
  for i in range(n):
    res.append(x%2)
    x //= 2
  return res

test = {}
for i in range(n):
  A = int(input())
  test[i+1] = []
  for a in range(A):
    x,y = map(int,input().split())
    test[i+1].append((x,y))

ans = 0
for i in range(2**n):
  people = func(i)
  for i in range(n):
    if people[i]:
      for x,y in test[i+1]:
        if people[x-1] == y:
          continue
        else:
          break
      else:
        continue
      break
  else:
    ans = max(sum(people),ans)
print(ans)
Buggy code:
n = int(input())

xy_arr = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = int(map(int, input().split()))
        xy_arr[i].append(x, y)
        
max_res = 0
for i in range(2 ** n):           
    ok_flg = True
    bin_i = format(i, "015b")[::-1]
                                    
        for j in range(n):
            for x, y in xy_arr[j]:　
                if bin_i[j] == 1 and y != int(bin_i[x - 1]):
                    ok_flg = False
                    break
            else:
                continue
            break
        
    if ok_flg:
        res = sum(int(x) for x in bin_i)
        mas_res = (max_res, res)
        
print(max_res)

Fixed code:
n = int(input())

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

max_res = 0
for i in range(2 ** n):           
    ok_flg = True
    bin_i = format(i, "015b")[::-1] 
                                    
    for j in range(n):
        for x, y in xy_arr[j]: 
            if bin_i[j] == "1" and y != int(bin_i[x - 1]):
                ok_flg = False
                break
        else:
            continue
        break
        
    if ok_flg:
        res = sum(int(x) for x in bin_i)
        max_res = max(max_res, res)
        
print(max_res)
Buggy code:
#!/usr/bin/env python3
import numpy as np

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N=int(input())
    A = []
    for i in range(N):
        a = int(input())
        xy = None
        for j in range(a):
            xy = list(map(int,input().split()))
        A.append(xy)
    print(A)

    c = 0
    for bit in range(2**N):
        bs = np.array(list(map(int,list("0"*N+bin(bit)[2:])[-N:])))
        ok = True
        #print(bs)
        for i in range(N):
            if A[i]:
                x, y = A[i]
                if bs[i]==0:
                    y = 1-y
                if bs[x-1]!=y:
                    ok=False
                    #print("NG")
                    break
        if ok:
            #print("OK")
            c = max(c, bs.sum())

    print(c)        


if __name__ == '__main__':
    main()


Fixed code:
#!/usr/bin/env python3
import numpy as np

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N=int(input())
    A = []
    for i in range(N):
        a = int(input())
        A.append([])
        xy = None
        for j in range(a):
            xy = list(map(int,input().split()))
            A[i].append(xy)
    #print(A)

    c=0
    for bit in range(1,2**N):
        bs = np.array(list(map(int,list("0"*N+bin(bit)[2:])[-N:])))
        #print(bs)
        ok=True
        for i in range(N):
            if bs[i]:
                for j in range(len(A[i])):
                    x, y = A[i][j]
                    if y==1 and bs[x-1]==0:
                        ok=False
                        break
                    if y==0 and bs[x-1]!=0:
                        ok=False
                        break
                else:
                    continue
                break

        if ok:
            #print("OK")
            #print(bs)
            c = max(c, bs.sum())

    print(c)        


if __name__ == '__main__':
    main()
Buggy code:
from collections import deque
n = int(input())
work = []
for i in range(n):
    a = int(input())
    work.append([list(map(int, input().split())) for i in range(a)])
result = 0
for i in range(2**n):
    state = bin(i)[2:].zfill(n)
    honest = []
    unkind = []
    for j in range(n):
        if state[j] == "0":
            unkind.append(j)
        else:
            honest.append(j)
    flag = True
    for human in honest:
        for x, y in work[human-1]:
            if y == 1 and x in unkind:
                flag = False
                break
            elif y == 0 and x in honest:
                flag = False
                break
        if not flag:
            break
    if flag:
        result = result if result>len(honest) else len(honest)
print(result)

Fixed code:
from collections import deque
n = int(input())
work = []
for i in range(n):
    a = int(input())
    work.append([list(map(int, input().split())) for i in range(a)])
result = 0
for i in range(2**n):
    state = bin(i)[2:].zfill(n)
    honest = []
    unkind = []
    for j in range(n):
        if state[j] == "0":
            unkind.append(j+1)
        else:
            honest.append(j+1)
    flag = True
    for human in honest:
        for x, y in work[human-1]:
            if y == 1 and x in unkind:
                flag = False
                break
            elif y == 0 and x in honest:
                flag = False
                break
        if not flag:
            break
    if flag:
        result = result if result>len(honest) else len(honest)
print(result)
Buggy code:
import sys, itertools
input = sys.stdin.readline

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

ans = 0

for p in itertools.product([1,0], repeat=n):
  ok = 1
  for l in ll:
    if p[l[0]] == 1 and p[l[1]] != l[2]:
      ok = 0
      break
  if ok:
    ans = max(ans, sum(p))

print(ans)

Fixed code:
import sys, itertools
input = sys.stdin.readline

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

ans = 0

for p in itertools.product([1,0], repeat=n):
  ok = 1
  for l in ll:
    if p[l[0]] == 1 and p[l[1]] != l[2]:
      ok = 0
      break
  if ok:
    ans = max(ans, sum(p))

print(ans)
Buggy code:
g = [[-1] * 15 for _ in range(15)]
n = int(input())
for i in range(n):
    m = int(input())
    for j in range(m):
        a, x = map(int, input().split())
        a -= 1
        g[i][a] = x
def count_ones_by_minus(num):
    count = 0
    while num:
        num &= num -1
        count += 1
    return count
for i in range(1 << 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, count_ones_by_minus(i))
    print(ans)  

Fixed code:
g = [[-1] * 15 for _ in range(15)]
n = int(input())
for i in range(n):
    m = int(input())
    for j in range(m):
        a, x = map(int, input().split())
        a -= 1
        g[i][a] = x
def count_ones_by_minus(num):
    count = 0
    while num:
        num &= num -1
        count += 1
    return count
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, count_ones_by_minus(i))
print(ans)
Buggy code:
N = int(input())
a = [[] for _ in range(N)]
for i in range(N):
  A_i = int(input())
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))
    
for i in range(2**N):
  contradiction = False
  max_honest = 0
  honest_p = []
  unkind_p = []
  doubt_honest_p = []
  doubt_unkind_p = []
  length = len(format(2**N-1, "b"))
  bin_num = format(i, "b").zfill(length)
  for j in range(length):
    if (i >> j) & 1:
      doubt_honest_p.append(j+1)
      for k in a[j]:
        p = k[0]
        t = k[1]
        if t:
          honest_p.append(p)
        else:
          unkind_p.append(p)
    else:
      doubt_unkind_p.append(j+1)
  for l in doubt_honest_p:
    if not l in honest_p or l in unkind_p:
      contradiction = True
  for m in doubt_unkind_p:
    if not m in unkind_p or m in honest_p:
      contradiction = True
  if not contradiction and max_honest <= len(doubt_honest_p):
    max_honest = len(doubt_honest_p)
    
print(max_honest)

Fixed code:
N = int(input())
a = [[] for _ in range(N)]
for i in range(N):
  A_i = int(input())
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))
 
max_honest = 0
for i in range(2**N):
  contradiction = False
  honest_p = []
  unkind_p = []
  doubt_honest_p = []
  doubt_unkind_p = []
  length = len(format(2**N-1, "b"))
  bin_num = format(i, "b").zfill(length)
  for j in range(length):
    if (i >> j) & 1:
      if not j+1 in honest_p:
      	honest_p.append(j+1)
      if not j+1 in doubt_honest_p:
      	doubt_honest_p.append(j+1)
      for k in a[j]:
        p = k[0]
        t = k[1]
        if t:
          if not p in honest_p:
          	honest_p.append(p)
        else:
          if not p in unkind_p: 
          	unkind_p.append(p)
    else:
      if not j+1 in unkind_p:
        unkind_p.append(j+1)
      if not j+1 in doubt_unkind_p:
      	doubt_unkind_p.append(j+1)
  if len(list(set(honest_p) & set(unkind_p))) != 0:
    contradiction = True
  if not contradiction and max_honest <= len(doubt_honest_p):
    max_honest = len(doubt_honest_p)
    
print(max_honest)
Buggy code:
n = int(input())
XY = []
ans = 0
for i in range(n):
  a = int(input())
  XY.append([])
  for j in range(a):
    XY[i].append(list(map(int,input().split())))
for i in range(2**n):
  i = format(i, 'b')
  i = i.zfill(n)
  temp = i.count("1")
  temp2 = 0
  print(i)
  for j in range(n):
    if i[j] == "1":
      for k in range(len(XY[j])):
        if str(XY[j][k][1]) != i[XY[j][k][0]-1]:
          temp2 = 1
          break
  if temp2 == 0:
    if ans < temp:
      ans = temp
print(ans)

Fixed code:
n = int(input())
XY = []
ans = 0
for i in range(n):
  a = int(input())
  XY.append([])
  for j in range(a):
    XY[i].append(list(map(int,input().split())))
for i in range(2**n):
  i = format(i, 'b')
  i = i.zfill(n)
  temp = i.count("1")
  temp2 = 0
  for j in range(n):
    if i[j] == "1":
      for k in range(len(XY[j])):
        if str(XY[j][k][1]) != i[XY[j][k][0]-1]:
          temp2 = 1
          break
  if temp2 == 0:
    if ans < temp:
      ans = temp
print(ans)
Buggy code:
N = int(input())
evidence = [[] for _ in range(N)]
for i in range(N):
  A = int(input())
  for _ in range(A):
    x,y = map(int,input().split())
    evidence[i].append((x-1,y))
result = 0
for j in range(1,2**N):
  consistent = True
  for k in range(N):
    if (j >> k) & 1 == 0:
      continue
    for x,y in evidence[k]:
      if (j >> x) & 1 != y:
        consistent = False
        break
    if not consistent:
      break
  else:
    result = max(result, bin(i)[2:].count("1"))
print(result)

Fixed code:
N = int(input())
evidence = [[] for _ in range(N)]
for i in range(N):
  A = int(input())
  for _ in range(A):
    x,y = map(int,input().split())
    evidence[i].append((x-1,y))
result = 0
for j in range(1,2**N):
  consistent = True
  for k in range(N):
    if (j >> k) & 1 == 0:
      continue
    for x,y in evidence[k]:
      if (j >> x) & 1 != y:
        consistent = False
        break
    if not consistent:
      break
  if consistent:
    result = max(result, bin(j)[2:].count("1"))
print(result)
Buggy code:
N = int(input())
x = []
y = []
words = []
for i in range(N):
  A = int(input())
  W = []
  for _ in range(A):
    x, y = map(int, input().split())
    W.append([x-1, y])
  words.append(W)
  
ans = 0
for bit in range(1<<n):
  ok = True
  is_honest = [(bit>>i) & 1 for i in range(N)]
  for i in range(N):
    if not is_honest[i]:
      continue
    for x, y in words[i]:
      if is_honest[x] != y:
        ok = False
  if ok:
    ans = max(ans, sum(is_honest))
print(ans)

Fixed code:
N = int(input())
x = []
y = []
words = []
for i in range(N):
  A = int(input())
  W = []
  for _ in range(A):
    x, y = map(int, input().split())
    W.append([x-1, y])
  words.append(W)
  
ans = 0
for bit in range(1<<N):
  ok = True
  is_honest = [(bit>>i) & 1 for i in range(N)]
  for i in range(N):
    if not is_honest[i]:
      continue
    for x, y in words[i]:
      if is_honest[x] != y:
        ok = False
  if ok:
    ans = max(ans, sum(is_honest))
print(ans)
Buggy code:
n = int(input())
word = []
for i in range(n):
  a = int(input())
  l = [list(map(int,input().split())) for _ in range(a)]
  word.append(l)
print(word)

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


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

ans = 0
for i in range(2**n):
  flag = 0
  count = 0
  for j in range(n):
    if ((i>>j)&1)==1 and flag==0:
      for k,l in word[j]:
        if ((i>>(k-1))&1) != l:
          flag = 1 ## tell a lie
          break
  if flag==0:
    count = bin(i).count('1')
    ans = max(ans,count)
print(ans)
Buggy code:
numbers = list(map(int, input().split()))
n = numbers[0]

v = []

for i in range(n):
    numbers = list(map(int, input().split()))
    a = numbers[0]
    
    w = []
    
    for j in range(a):
        z = list(map(int, input().split()))
        w.append(z)
        
    v.append(w)
    
rezultat = 0

max_steps = 2 ** n

for i in range(max_steps):
    w = [-1] * n
    
    for j in range(n):
        if i >> j & 1:
            w[j] = 1
        else:
            w[j] = 0
    
    ok = 1
    
    for j in range(n):
        if ok == 0:
            break
        for a, b in v[j]:
            if w[j] == 1:
                a = a - 1
            if w[a] != b:
                ok = 0
                break
                
    if ok:
        rezultat = rezultat if rezultat > sum(w) else sum(w)
        
print(rezultat)


Fixed code:
numbers = list(map(int, input().split()))
n = numbers[0]

v = []

for i in range(n):
    numbers = list(map(int, input().split()))
    a = numbers[0]
    
    w = []
    
    for j in range(a):
        z = list(map(int, input().split()))
        w.append(z)
        
    v.append(w)
    
rezultat = 0

max_steps = 2 ** n

for i in range(max_steps):
    w = [-1] * n
    
    for j in range(n):
        if i >> j & 1:
            w[j] = 1
        else:
            w[j] = 0
    
    ok = 1
    
    for j in range(n):
        if ok == 0:
            break
        for a, b in v[j]:
            if w[j] == 1:
                a = a - 1
                if w[a] != b:
                    ok = 0
                    break
                
    if ok:
        rezultat = rezultat if rezultat > sum(w) else sum(w)
        
print(rezultat)
Buggy code:
import sys
from collections import deque
readline = sys.stdin.readline


N = int(readline())
A = []
X, Y = [], []
for i in range(N):
    a = int(readline())
    A.append(a)
    x, y = zip(*[list(map(int, readline().split())) for j in range(a)])
    x = [_x - 1 for _x in x]
    X.append(x)
    Y.append(y)

while True:
    pass
M = 2 ** N
count = 0
for code in range(M - 1, -1, -1):
    contra = False
    for i in range(N):
        if ((code >> i) & 1) == 1:
            x, y = X[i], Y[i]
            for j in range(len(x)):
                if y[j] != ((code >> x[j]) & 1):
                    contra = True
                    break
            if contra:
                break
    if not contra:
        _count = 0
        for i in range(N):
            _count += ((code >> i) & 1)
        count = max(count, _count)

print(count)









Fixed code:
import sys
from collections import deque
readline = sys.stdin.readline


N = int(readline())
A = []
X, Y = [], []
for i in range(N):
    a = int(readline())
    A.append(a)
    x, y = [], []
    for j in range(a):
        _x, _y = map(int, readline().split())
        x.append(_x - 1), y.append(_y)
    X.append(x)
    Y.append(y)

M = 2 ** N
count = 0
for code in range(M - 1, -1, -1):
    contra = False
    for i in range(N):
        if ((code >> i) & 1) == 1:
            x, y = X[i], Y[i]
            for j in range(len(x)):
                if y[j] != ((code >> x[j]) & 1):
                    contra = True
                    break
            if contra:
                break
    if not contra:
        _count = 0
        for i in range(N):
            _count += ((code >> i) & 1)
        count = max(count, _count)

print(count)
Buggy code:
import itertools
n = int(input())
xy = [0 for _ in range(n)]
for i in range(n):
    ai = int(input())
    xy[i] = [list(map(int , input().split())) for _ in range(ai)]

#print(xy)
#print(xy[0])
#print(xy[0][0])
ans = 0
for i in itertools.product([0, 1], repeat=n):
    ok = True
    cnt = sum(i)
    for j in range(n):
        xyj = xy[j]
        for xyk in xyj:
            if xyk[1] == 0:
                if i[j] == 1:
                    ok = False
            elif xyk[1] == 1:
                if i[j] == 0:
                    ok = False
    if ok:
        ans = max(ans, cnt)

print(ans)


Fixed code:
import itertools
n = int(input())
xy = [0 for _ in range(n)]
for i in range(n):
    ai = int(input())
    xy[i] = [list(map(int , input().split())) for _ in range(ai)]

#print(xy)
#print(xy[0])
#print(xy[0][0])
ans = 0
for i in itertools.product([0, 1], repeat=n):
    ok = True
    cnt = sum(i)
    for j in range(n):
        xyj = xy[j]
        if i[j] == 1:
            for xyk in xyj:
                if xyk[1] == 1:
                    if i[xyk[0]-1] == 0:
                        ok = False
                elif xyk[1] == 0:
                    if i[xyk[0]-1] == 1:
                        ok = False
    #print(ok, i)
    if ok:
        ans = max(ans, cnt)

print(ans)