qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import math
import copy
from queue import Queue
import heapq
import numpy as np

MOD = 5000000007

#n = int(input())
#s = int(input())
#a, b, c, x, y = [int(i) for i in input().split()]
#table = [[int(i)  for i in input().split()] for j in range(m)]
#table = [list(input()) for n in range(r)] #table[h][w]
#p = [int(i) for i in input().split()]
#s = [int(i) for i in range(n)]
#p = [int(input()) for i in range(m)]
#s = input()

#list = list(s)
#a = [0 for _ in range(n+1)]
#dp = [[0 for _ in range(n+1)] for _ in range(n+1)]

n = int(input())
word_list = [[] for i in range(n)]

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

ans = 0

for i in range(2**n):
    peoples = []
    flag = 1
    for j in range(n):
        if(i >> j & 1):
            peoples.append(1)
        else:
            peoples.append(0)
    
    for k in range(n):
        if peoples[k] == 1
            words = words_list[k]
            for word in words:
                if peoples[word[0]] != word[1]:
                    flag = 0
                    break
    
    if flag:
        ans = max(ans,sum(peoples))

print(ans)

Fixed code:
import math
import copy
from queue import Queue
import heapq
import numpy as np

MOD = 5000000007

#n = int(input())
#s = int(input())
#a, b, c, x, y = [int(i) for i in input().split()]
#table = [[int(i)  for i in input().split()] for j in range(m)]
#table = [list(input()) for n in range(r)] #table[h][w]
#p = [int(i) for i in input().split()]
#s = [int(i) for i in range(n)]
#p = [int(input()) for i in range(m)]
#s = input()

#list = list(s)
#a = [0 for _ in range(n+1)]
#dp = [[0 for _ in range(n+1)] for _ in range(n+1)]

n = int(input())
word_list = [[] for i in range(n)]

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

ans = 0

for i in range(2**n):
    peoples = []
    flag = 1
    for j in range(n):
        if(i >> j & 1):
            peoples.append(1)
        else:
            peoples.append(0)

    for k in range(n):
        if peoples[k] == 1:
            words = word_list[k]
            for word in words:
                if peoples[word[0]] != word[1]:
                    flag = 0
                    break

    if flag:
        ans = max(ans,sum(peoples))

print(ans)
Buggy code:
N = int(input())
A = [0]*N
testi = []
assume = 2**N-1
ans = 0

for i in range(N):
    A[i] = int(input())
    if A[i] == 0:
        testi.append(-1)
    else:
        testi.append([list(map(int, input().split())) for _ in range(A[i])])

while(assume):
    flag = True
    for i in range(N):
        if assume & (2**i) != 0 and testi[i] != -1:
            for j in testi[i]:
                if j[1] != ((assume & (2**(j[0]-1))) >> (j[0]-1)):
                    flag = False
                    break
        
        if not flag:
            break
    
    assume -= 1
    tmp = bin(assume).count('1')
    if tmp > ans:
        ans = tmp

print(ans)         

Fixed code:
N = int(input())
A = [0]*N
testi = []
assume = 2**N-1
ans = 0

for i in range(N):
    A[i] = int(input())
    if A[i] == 0:
        testi.append(-1)
    else:
        testi.append([list(map(int, input().split())) for _ in range(A[i])])

while(assume):
    flag = True
    for i in range(N):
        if assume & (2**i) != 0 and testi[i] != -1:
            for j in testi[i]:
                if j[1] != ((assume & (2**(j[0]-1))) >> (j[0]-1)):
                    flag = False
                    break
        
        if not flag:
            break
    
    if flag:
        tmp = bin(assume).count('1')
        if tmp > ans:
            ans = tmp
    assume -= 1
    

print(ans)
Buggy code:
import itertools as it

N = int(input())
xy = []
for i in range(N):
    A_i = int(input())
    xy_i = []
    for j in range(A_i):
        tmp = [int(i) for i in input().split()]
        xy_i.append(tmp)
    xy.append(xy_i)
ans = 0
for conf in it.product(range(2), repeat=N):
    is_consist = True
    # honest 1, evil 0
    for i in range(N):
        if conf[i] == 0:
            continue
        # i is honest
        for jth_state in range(len(xy[i])):
            if xy[i][jth_state][1] != conf[xy[i][jth_state][0] - 1]:
                is_consist = False
                break
    if is_consist:
        ans = max(ans, sum(conf))
        if ans == sum(conf):
            print(conf)
print(ans)


Fixed code:
import itertools as it

N = int(input())
xy = []
for i in range(N):
    A_i = int(input())
    xy_i = []
    for j in range(A_i):
        tmp = [int(i) for i in input().split()]
        xy_i.append(tmp)
    xy.append(xy_i)
ans = 0
for conf in it.product(range(2), repeat=N):
    is_consist = True
    # honest 1, evil 0
    for i in range(N):
        if conf[i] == 0:
            continue
        # i is honest
        for jth_state in range(len(xy[i])):
            if xy[i][jth_state][1] != conf[xy[i][jth_state][0] - 1]:
                is_consist = False
                break
    if is_consist:
        ans = max(ans, sum(conf))
print(ans)
Buggy code:
N = int(input())
testimo_ls = [ [] for i in range(N) ]
rst = 0
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split(' '))
        testimo_ls[i].append([x - 1, y])
for i in range(1 << N):
    honest_ls = []
    for j in range(N):
        if i >> j & 1:
            honest_ls.append(j)
    is_ok = True
    for s in honest_ls:
        for t in testimo_ls[s]:
            if t[0] not in honest_ls and t[1] == 1:
                is_ok = False
                break
            if t[0] in honest_ls and t[1] == 1:
                is_ok = False
                break
    if is_ok:
        rst = max(rst, len(honest_ls))
print(rst)

Fixed code:
N = int(input())
testimo_ls = [ [] for i in range(N) ]
rst = 0
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split(' '))
        testimo_ls[i].append([x - 1, y])
for i in range(1 << N):
    honest_ls = []
    for j in range(N):
        if i >> j & 1:
            honest_ls.append(j)
    is_ok_cnt = 0
    is_ok = True
    for s in honest_ls:
        for t in testimo_ls[s]:
            if t[1] == 0 and t[0] in honest_ls:
                is_ok = False
                break
            if t[1] == 1 and t[0] not in honest_ls:
                is_ok = False
                break
    if is_ok:
        rst = max(rst, len(honest_ls))
print(rst)
Buggy code:
import itertools

N = int(input())
a = []
dic = {}
ans = [1 for _ in range(N)]
trueans = 0
for i in range(N):
  a.append(int(input()))
  dic[i] = []
  for j in range(a[-1]):
    x, y = input().split()
    dic[i].append((int(x),int(y)))

def check(dic, ans):
  for k, v in dic.items():
    for x, y in v:
      if ans[k]==1:
        if ans[x-1] != y:
          return False
      else:
        if ans[x-1] == y:
          return False
  return True

slist = []
for i in range(1, N+1):
  slist.append(i)
if check(dic, ans):
  print(N)
else:
  while(True):
    for i in range(1, N+1):
      tmp = list(itertools.combinations(slist,i))
      print(tmp)
      for t in tmp:
        anstmp = ans
        for t in t:
          anstmp[t-1] = 0
          flag = check(dic, anstmp)
          if flag:
            break
        if flag:
          break
      if flag:
        trueans = N - i
        break
    if flag:
      break
    break
  print(trueans)

Fixed code:
import itertools
import copy
N = int(input())
dic = {}
ans = [1 for _ in range(N)]
trueans = 0
for i in range(N):
  a = int(input())
  dic[i] = []
  for _ in range(a):
    x, y = input().split()
    dic[i].append((int(x),int(y)))
 
def check(dic, ans):
  for k, v in dic.items():
    for x, y in v:
      if ans[k] == 1:
        if ans[x-1] != y:
          return False
  return True
 
slist = []
for i in range(1, N+1):
  slist.append(i)
if check(dic, ans):
  print(N)
else:
  while(True):
    for i in range(1, N+1):
      tmp = list(itertools.combinations(slist,i))
      for t in tmp:
        anstmp = copy.deepcopy(ans)
        for t in t:
          anstmp[t-1] = 0
          flag = check(dic, anstmp)
          if flag:
            break
        if flag:
          break
      if flag:
        trueans = N - i
        break
    if flag:
      break
    break
  print(trueans)
Buggy code:
N = int(input())
xys = [[] for _ in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        x,y = map(int,input().split())
        xys[i].append((x-1,y))

ans = 0
for b in range(1<<N):
    cnt = bin(b).count('1')
    if cnt <= ans: continue
    for i in range(N):
        if b&(1<<i):
        for x,y in xys[i]:
                if y==1 and b&(1<<x): continue
                if y==0 and b&(1<<x)==0: continue
                break
            else:
                continue
            break
    else:
        ans = cnt
print(ans)

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

ans = 0
for b in range(1<<N):
    cnt = bin(b).count('1')
    if cnt <= ans: continue
    for i in range(N):
        if b&(1<<i):
            for x,y in xys[i]:
                if y==1 and b&(1<<x): continue
                if y==0 and b&(1<<x)==0: continue
                break
            else:
                continue
            break
    else:
        ans = cnt
print(ans)
Buggy code:
import itertools
n=int(input())
A=[[] for i in range(n)]
for i in range(n):
  r=int(input())
  for j in range(r):
    A[i].append(list(map(int,input().split())))
ans=0
L=list(itertools.product([0,1],repeat=n))
for i in L:
  T=[]
  for num,j in enumerate(i):
    if j==1:
      for k in A[num]:
        T.append(k)
if all(i[j[0]-1]==j[1] for j in T):
  ans=max(ans,sum(i))
print(ans)

Fixed code:
import itertools
n=int(input())
A=[[] for i in range(n)]
for i in range(n):
  r=int(input())
  for j in range(r):
    A[i].append(list(map(int,input().split())))
ans=0
L=list(itertools.product([0,1],repeat=n))
for i in L:
  T=[]
  for num,j in enumerate(i):
    if j==1:
      for k in A[num]:
        T.append(k)
  if all(i[j[0]-1]==j[1] for j in T):
    ans=max(ans,sum(i))
print(ans)
Buggy code:
N = int(input())

E = []
for n in range(N):
  A = int(input())
  for _ in range(A):
    x, y = list(map(int, input().split()))
    E.append((n, x - 1, y))

    for k in range((1 << N)):
      status = [(k >> i) & 1 for i in range(N)]
      no_paradox = True
      for Xa, Xb, yb in E:
        if (status[Xa] == 1 and status[Xb] == yb):
          no_paradox = False
          break
          if no_paradox:
            ans = max(ans, sum(l))
print(ans)

Fixed code:
N = int(input())
E = []
for n in range(N):
    A = int(input())
    for _ in range(A):
        x, y = list(map(int, input().split()))
        E.append((n, x - 1, y))
ans = 0
for k in range((1 << N) - 1, -1, -1):
    status = [(k >> i) & 1 for i in range(N)]
    no_paradox = True
    for Xa, Xb, yb in E:
        if (status[Xa] == 1 and status[Xb] != yb):
            no_paradox = False
            break
    if no_paradox:
        ans = max(ans, sum(status))
print(ans)
Buggy code:
N=int(input())

syogen=[]
for i in range(N):
	a=int(input())
	temp=[list(map(int, input().split())) for _ in range(a)]
	syogen.append([a,temp])

ans=0

for h in range(2**N):
	flag=0
	cnt=0
	l=[0]*N
	for g in range(N):
		if h>>g &1:
			l[g]=1
	#print(l)
	for gg in range(N):
		if l[gg]==1:
			temp_=syogen[g]
			for n in range(temp_[0]):
				if l[temp_[1][n][0]]==temp_[1][n][1]:
					continue
				else:
					flag=1
					break
		if flag==1:
			break
		elif flag==0 and gg==N-1:
			#print(bin(h))
			ans=max(ans,sum(l))

print(ans)

Fixed code:
N=int(input())

syogen=[]
for i in range(N):
	a=int(input())
	temp=[list(map(int, input().split())) for _ in range(a)]
	syogen.append([a,temp])

ans=0

for h in range(2**N):
	flag=0
	cnt=0
	l=[0]*N
	for g in range(N):
		if h>>g &1:
			l[g]=1
	#print(l)
	for gg in range(N):
		if l[gg]==1:
			temp_=syogen[gg]
			#print(temp_)
			for n in range(temp_[0]):
				if l[temp_[1][n][0]-1]==temp_[1][n][1]:
					continue
				else:
					flag=1
					break
		if flag==1:
			break
		elif flag==0 and gg==N-1:
			#print(bin(h))
			ans=max(ans,sum(l))

print(ans)
Buggy code:
N = int(input())
g = [[-1 for _ in range(N)] for _ in range(N)]
for i in range(N):
    m = int(input())
    for j in range(m):
        x,y = map(int,input().split())
        g[i][x-1] = y

ans = 0
for i in range(1 << N):
    hornest = [0] * N
    for j in range(N):
        if (i << j)&1:
            hornest[j] = 1
    is_ok = 1
    for j in range(N):
        if hornest[j]:
            for k in range(N):
                if g[j][k] == -1:
                    continue
                if g[j][k] != hornest[k]:
                    is_ok = 0
    if is_ok:
        ans = max(ans,hornest.count(1))
        
print(ans)

Fixed code:
N = int(input())
g = [[-1 for _ in range(N)] for _ in range(N)]
for i in range(N):
    m = int(input())
    for j in range(m):
        x,y = map(int,input().split())
        g[i][x-1] = y

ans = 0
for i in range(1 << N):
    hornest = [0] * N
    for j in range(N):
        if (i >> j)&1:
            hornest[j] = 1
    is_ok = 1
    for j in range(N):
        if hornest[j] and is_ok:
            for k in range(N):
                if g[j][k] == -1:
                    continue
                if g[j][k] != hornest[k]:
                    is_ok = 0
    if is_ok:
        ans = max(ans,hornest.count(1))
        
print(ans)
Buggy code:
import sys
input = sys.stdin.readline

_n = int(input())

said = []
for i in range(_n):
    ai = int(input())
    said.append([list(map(int, input().split())) for _ in range(ai)])

ans = 0
for i in range(2 ** _n):
    ynflg = 1
    flg = format(i, 'b').zfill(_n)
    for sy, tag in zip(said, flg):
        if tag == 0:
            continue

        for s in sy:
            if flg[s[0] - 1] != str(s[1]):
                ynflg = 0
                break

        if ynflg == 0:
            break

    if ynflg == 1:
        ans = max(ans, flg.count('1'))

print(ans)


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

_n = int(input())

said = []
for i in range(_n):
    ai = int(input())
    said.append([list(map(int, input().split())) for _ in range(ai)])

ans = 0
for i in range(2 ** _n):
    ynflg = 1
    flg = format(i, 'b').zfill(_n)
    for sy, tag in zip(said, flg):
        if tag == '0':
            continue

        for s in sy:
            if flg[s[0] - 1] != str(s[1]):
                ynflg = 0
                break

        if ynflg == 0:
            break

    if ynflg == 1:
        ans = max(ans, flg.count('1'))

print(ans)
Buggy code:
n = int(input())
xys = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        xys[i].append((x-1, y))

ans = 0
for i in range(1<<n):
    ok = True
    for j in range(n):
        # if jth person may be honest, verify testimony of him.
        if (i>>j) & 1 == 1:
            for xy in xys[j]:
                x, y = xy
                if (i>>x) & 1 != y:
                    ok = False
                    break
        if not ok:
            break
    if ok:
        ans = max(ans, bin(x).count('1'))
print(ans)



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

def digitsum(x):
    return bin(x).count('1')

ans = 0
for i in range(1<<n):
    ok = True
    for j in range(n):
        # if jth person may be honest, verify testimony of him.
        if (i>>j) & 1 == 1:
            for xy in xys[j]:
                x, y = xy
                if (i>>x) & 1 != y:
                    ok = False
                    break
        if not ok:
            break
    if ok:
        ans = max(ans, digitsum(i))
print(ans)
Buggy code:
n = int(input())
xys = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        xys[i].append((x-1, y))

def digitsum(x):
    ret = 0
    while x>0:
        ret += x & 1
        x <<= 1
    return ret

ans = 0
for i in range(1<<n):
    ok = True
    for j in range(n):
        # if jth person may be honest, verify testimony of him.
        if (i>>j) & 1 == 1:
            for xy in xys[j]:
                x, y = xy
                if (i>>x) & 1 != y:
                    ok = False
                    break
        if not ok:
            break
    if ok:
        ans = max(ans, digitsum(i))
print(ans)

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

def digitsum(x, base=2):
    ret = 0
    while x>0:
        ret += x % base
        x = x // base
    return ret

ans = 0
for i in range(1<<n):
    ok = True
    for j in range(n):
        # if jth person may be honest, verify testimony of him.
        if (i>>j) & 1 == 1:
            for xy in xys[j]:
                x, y = xy
                if (i>>x) & 1 != y:
                    ok = False
                    break
        if not ok:
            break
    if ok:
        ans = max(ans, digitsum(i))
print(ans)
Buggy code:
N = int(input())
path = []
ans = 0
ap = path.append
Ap = path[-1].append
for i in range(N):
    A = int(input())
    ap([])
    for j in range(A):
        x, y = map(int,input().split())
        x -= 1
        Ap((x, y))
for i in range(1<<N):
    i |= (1<<N)
    judge = True
    for j in range(N):
        if (1<<j) & i:
            for k in range(len(path[j])):
                if path[j][k][1] != int(bin(i)[-path[j][k][0] - 1]):
                    judge = False
    if judge:
        if ans < bin(i).count("1") - 1:
            ans = bin(i).count("1") - 1
print(ans)

Fixed code:
N = int(input())
path = []
ans = 0
for i in range(N):
    A = int(input())
    path.append([])
    for j in range(A):
        x, y = map(int,input().split())
        x -= 1
        path[-1].append((x, y))
for i in range(1<<N):
    i |= (1<<N)
    judge = True
    for j in range(N):
        if not judge:
            break
        if (1<<j) & i:
            for k in range(len(path[j])):
                if path[j][k][1] != int(bin(i)[-path[j][k][0] - 1]):
                    judge = False
                    break
    if judge:
        if ans < bin(i).count("1") - 1:
            ans = bin(i).count("1") - 1
print(ans)
Buggy code:
i=input
n=int(i())
a=eval('eval("list(map(int,i().split())),"*int(i())),'*n)
#print(max(all([y==i>>x-1&1for j,t in enumerate(a)if i>>j&1for x,y in t]+[1])*bin(i).count('1')for i in range(2**n)))

Fixed code:
i=input
n=int(i())
a=eval('[list(map(int,i().split()))for _ in"_"*int(i())],'*n)
print(max(all(y==i>>x-1&1for j,t in enumerate(a)if i>>j&1for x,y in t)*bin(i).count('1')for i in range(2**n)))
Buggy code:
N = int(input())

ary = [[-1] * N for i in range(N)]
for i in range(N):
    for j in range(int(input())):
        x, y = map(int, input().split())
        ary[i][x - 1] = y
print(ary)

ret = 0
for a in range(2 ** N):
    flg = True
    for i in range(N):
        if (a >> i & 1) == 1:
            for j in range(N):
                if ary[i][j] == -1:
                    continue
                if (a >> j & 1) != ary[i][j]:
                    flg = False
                    break

    if flg:
        n = sum([a >> i & 1 for i in range(N)])
        ret = max(ret, n)

print(ret)


Fixed code:
N = int(input())

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

ret = 0
for a in range(2 ** N):
    flg = True
    for i in range(N):
        if (a >> i & 1) == 1:
            for j in range(N):
                if ary[i][j] == -1:
                    continue
                if (a >> j & 1) != ary[i][j]:
                    flg = False
                    break

    if flg:
        n = sum([a >> i & 1 for i in range(N)])
        ret = max(ret, n)

print(ret)
Buggy code:
N=int(input())
A,X,Y=[],[],[]
for n in range(N):
    An=int(input())
    Xn,Yn=[],[]
    for a in range(An):
        x,y=map(int,input().split())
        Xn.append(x-1)
        Yn.append(y)
    A.append(An)
    X.append(Xn)
    Y.append(Yn)

max_count=0
for k in range(2**N):
    P=[int(_) for _ in bin(k)[2:].zfill(N)]
    ok=True
    for i in range(N):
        for j in range(A[i]):
            if (Y[i][j]+P[i]+1)%2 != X[i][j]:
                ok=False
    if ok:
        max_count=max(max_count,sum(P))
print(max_count)


Fixed code:
N=int(input())
A,X,Y=[],[],[]
for n in range(N):
    An=int(input())
    Xn,Yn=[],[]
    for a in range(An):
        x,y=map(int,input().split())
        Xn.append(x-1)
        Yn.append(y)
    A.append(An)
    X.append(Xn)
    Y.append(Yn)

max_count=0
for k in range(2**N):
    P=[int(_) for _ in bin(k)[2:].zfill(N)]
    ok=True
    for i in range(N):
        for j in range(A[i]):
            if P[i]==1 and P[X[i][j]]!=Y[i][j]:
                ok=False
    if ok:
        max_count=max(max_count,sum(P))
print(max_count)
Buggy code:
n = int(input())
lst = [(bin(i)[2:]).zfill(n) for i in range(2**n)]
num_list = []
A_list = []
xy_list = []
for i in range(n):
    a = int(input())
    A_list.append(a)
    for j in range(a):
        x,y = map(int,input().split())
        xy_list.append([x,y])
for i in range(len(lst)):
    choose = lst[i]
    one_count = choose.count("1")
    a_count = 0
    print(choose)
    print(one_count)
    flag = True
    for num, j in enumerate(A_list):
        a_count += j
        for k in range(a_count-j, a_count):
            x,y = xy_list[k][0],xy_list[k][1]
            if choose[num] == "1" and choose[x-1] != str(y):
                flag = False
    if flag:
        num_list.append(one_count)
    else:
        num_list.append(0)
print(max(num_list))


Fixed code:
n = int(input())
lst = [(bin(i)[2:]).zfill(n) for i in range(2**n)]
num_list = []
A_list = []
xy_list = []
for i in range(n):
    a = int(input())
    A_list.append(a)
    for j in range(a):
        x,y = map(int,input().split())
        xy_list.append([x,y])
for i in range(len(lst)):
    choose = lst[i]
    one_count = choose.count("1")
    a_count = 0
    flag = True
    for num, j in enumerate(A_list):
        a_count += j
        for k in range(a_count-j, a_count):
            x,y = xy_list[k][0],xy_list[k][1]
            if choose[num] == "1" and choose[x-1] != str(y):
                flag = False
                break
    if flag:
        num_list.append(one_count)
    else:
        num_list.append(0)
print(max(num_list))
Buggy code:
N = int(input())
lst = []
for i in range(N):
  for j in range(int(input())):
    lst.append(list(map(int,input().split())))
ans = 0
for i in range(2**N):
  flag = True
  bin_lst = list(bin(i)[2:].zfill(N))
  for idx,j in enumerate(bin_lst):
    if (j == '1'):
      for v, w in zip(lst[idx][:-1],lst[idx][1:]):
        if (bin_lst[v-1] != str(w)):
          flag = False
  if (flag):
    ans = max(ans,bin_lst.count('1'))
print(ans)


Fixed code:
N = int(input())
lst = [[] for i in range(N)]
for i in range(N):
  for j in range(int(input())):
    lst[i].append(list(map(int,input().split())))
ans = 0
for i in range(2**N):
  flag = True
  bin_lst = list(bin(i)[2:].zfill(N))
  for idx,j in enumerate(bin_lst):
    if (j == '1'):
      for v, w in lst[idx]:
        if (bin_lst[v-1] != str(w)):
          flag = False
  if (flag):
    ans = max(ans,bin_lst.count('1'))
print(ans)