Problem:
 Score : 300 points    Problem Statement There are N people numbered 1 to N . Each of them is either an honest person whose testimonies are always correct or an unkind person whose testimonies may be correct or not.  Person i gives A_i testimonies. The j -th testimony by Person i is represented by two integers x_{ij} and y_{ij} . If y_{ij} = 1 , the testimony says Person x_{ij} is honest; if y_{ij} = 0 , it says Person x_{ij} is unkind.  How many honest persons can be among those N people at most?      Constraints  All values in input are integers.  1 \leq N \leq 15  0 \leq A_i \leq N - 1  1 \leq x_{ij} \leq N  x_{ij} \neq i  x_{ij_1} \neq x_{ij_2} (j_1 \neq j_2)  y_{ij} = 0, 1         Input Input is given from Standard Input in the following format:  N  A_1  x_{11}  y_{11}  x_{12}  y_{12}  :  x_{1A_1}  y_{1A_1}  A_2  x_{21}  y_{21}  x_{22}  y_{22}  :  x_{2A_2}  y_{2A_2}  :  A_N  x_{N1}  y_{N1}  x_{N2}  y_{N2}  :  x_{NA_N}  y_{NA_N}       Output Print the maximum possible number of honest persons among the N people.        Sample Input 1 3
1
2 1
1
1 1
1
2 0      Sample Output 1 2  If Person 1 and Person 2 are honest and Person 3 is unkind, we have two honest persons without inconsistencies, which is the maximum possible number of honest persons.       Sample Input 2 3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0      Sample Output 2 0  Assuming that one or more of them are honest immediately leads to a contradiction.       Sample Input 3 2
1
2 0
1
1 0      Sample Output 3 1

Solution (Python):
N=int(input())
A=[]
arr=[]
ans=0

for n in range(N):
  a=int(input())
  A.append(a)
  arr.append([ list(map(int,input().split())) for  _ in range(a)])
  
for i in range(2**N):
  ord =[0]*N
  count=0
  flg=0
  
  for n in range(N):
    if (i >>n)&1:
      count +=1
      ord[n]=1
   
  for n in range(N):
    if ord[n]==1:
      for m in range(A[n]):
        if ord[arr[n][m][0]-1]!= arr[n][m][1]:
          flg=1
          break
   
  if flg==1:
    continue
  ans=max(ans,count)
        
      
      
print(ans)

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

ans = 0
for bit in range(1 << N):
  honest_cnt = 0
  flag = True
  for i in range(N):
    if (bit >> i) & 1 == 0:
      continue
    honest_cnt += 1
    for x, y in XY[i]:
      if (bit >> (x-1)) & 1 != y:
        flag = False
        break
  if flag:
    ans = max(ans, honest_cnt)
    
print(ans)

Solution (Python):
import itertools
N = int(input())
talks = []
for i in range(N):
    temp = int(input())
    talks.append([list(map(int, input().split())) for _ in range(temp)])
bit = itertools.product([0, 1], repeat=N)
ans = 0
for b in bit:
    flag = True
    for i in range(N):
        if b[i] == 0:
            continue
        for talk in talks[i]:
            if b[talk[0]-1] != talk[1]:
                flag = False
                break
    if flag:
        ans = max(ans, (sum(b)))
print(ans)

Solution (Python):
n = int(input())
lia,lib,lic,lid = [],[],[],[]
count = 0
for i in range(n):
    lib.append(int(input()))
    for j in range(lib[i]):
        lid.append([int(s) for s in input().split()])
    lic.append(lid)
    lid = []
for i in range(2**n):
    b = "0"*(n-len(bin(i))+2)+bin(i)[2:]
    li = [int(b[s]) for s in range(n)]
    f = 1
    for j in range(n):
        for k in range(lib[j]):
            if li[j] == 1:
                if li[lic[j][k][0]-1] != lic[j][k][1]:
                    f = 0
    if f == 1:
        lia.append(li)
        count += 1
for i in range(count):
    lia[i] = sum(lia[i])
print(max(lia))

Solution (Python):
n = int(input())
lia,lib,lic,lid = [],[],[],[]
count = 0
for i in range(n):
    lib.append(int(input()))
    for j in range(lib[i]):
        lid.append([int(s) for s in input().split()])
    lic.append(lid)
    lid = []
for i in range(2**n):
    b = "0"*(n-len(bin(i))+2)+bin(i)[2:]
    li = [int(b[s]) for s in range(n)]
    f = 1
    for j in range(n):
        for k in range(lib[j]):
            if li[j] == 1:
                if li[lic[j][k][0]-1] != lic[j][k][1]:
                    f = 0
    if f == 1:
        lia.append(li)
        count += 1
for i in range(count):
    lia[i] = sum(lia[i])
print(max(lia))

Solution (Python):

import itertools

N = int(input())

all_list = list(itertools.product([0,1], repeat=N))

xy_list =[]

for i in range(N):
    for j in range(int(input())):
        x, y = map(int, input().split())
        xy_list.append((i+1,x,y))



num_ok = 0
for i in all_list:
    
    flag = True

    for j in xy_list:
        if i[j[0]-1] == 1:
            if i[j[1]-1] != j[2]:
                flag = False        
                break

    if flag == True:
        if num_ok < i.count(1):
            num_ok = i.count(1)


print(num_ok)

Solution (Python):
import itertools

N = int(input())

all_list = list(itertools.product([0,1], repeat=N))

xy_list =[]

for i in range(N):
    for j in range(int(input())):
        x, y = map(int, input().split())
        xy_list.append((i+1,x,y))



num_ok = 0
for i in all_list:
    
    flag = True

    for j in xy_list:
        if i[j[0]-1] == 1:
            if i[j[1]-1] != j[2]:
                flag = False        
    if flag == True:
        if num_ok < i.count(1):
            num_ok = i.count(1)


print(num_ok)

Solution (Python):
from itertools import product
n=int(input())
li=[[] for _ in range(n)]
A=[]
for i in range(n):
    a=int(input())
    A.append(a)
    for _ in range(a):
        x,y=map(int,input().split())
        li[i].append([x,y])
ans=0
for p in product([0, 1], repeat = n):
    f = 0
    for i in range(n):
        if f==0:
            for j in range(A[i]):
                if p[i]==1 and li[i][j][1] == 0:
                    if p[li[i][j][0] - 1] == 1:
                        f += 1
                        break
                elif p[i]==1 and li[i][j][1] == 1:
                    if p[li[i][j][0] - 1] == 0:
                        f += 1
                        break
        else:
            break
    if f==0:
        ans=max(ans,p.count(1))
print(ans)

Solution (Python):
N = int(input())
A = list()
xy = list()
flag = True
num = 0
output=0
for i in range(N):
  A.append(int(input()))
  xy.append([list(map(int,input().split())) for _ in range(A[i])])
  
for i in range(2**N):
  flag = True
  num = str(format(i, 'b').zfill(N))
  for j in range(N):
    if ((i>>j)&1) == 1:
      for k in range(len(xy[N-j-1])):
        if int(num[xy[N-1-j][k][0]-1]) !=  xy[N-1-j][k][1]:
          flag = False
          break
    if flag == False:
      break
  if flag == True and output <= str(bin(i)).count('1') :
    output = str(bin(i)).count('1')
print(output)

Solution (Python):
import itertools
N = int(input())
testimony = []
for n in range(N):
    A = int(input())
    testimony.append([list(map(int,input().split())) for _ in range(A)])

ans = 0
for bit in itertools.product([0,1],repeat = N):
    for n in range(N):
        if bit[n]:
            for t in testimony[n]:
                if bit[t[0]-1] != t[1]:
                    break
            else:
                continue
            break
    else:
        ans = max(ans,sum(bit))
print(ans)

Solution (Python):
2
n = int(input())
a = [[] for _ in range(n)]
for i in range(n): 
  num = int(input()) 
  for j in range(num):
    x,y = map(int,input().split())
    a[i].append([x,y])




ans = 0
for candi in range(1,2**n): 

  ck = 1 

  for i in range(n): 

    if not candi >> i & 1:
      continue

    for x,y in a[i]: 
      if candi >> (x-1) & 1 != y :
        ck = 0
        break
  if ck:
    temp = format(candi,'b').count('1')
    ans = max(ans,temp)

print(ans)

Solution (Python):
N = int(input())
testimony = [[] for _ in range(N)]
ans = 0
for n in range(N):
    A = int(input())
    for _ in range(A):
        x,y = map(int,input().split())
        testimony[n].append([x-1,y]) 

for bit in range(2**N):

    honest_cnt = 0
    for j in range(N):

        if (bit>>j) & 1:
            honest_cnt += 1
            for t in testimony[j]:
                if (bit>>t[0])&1 != t[1]:

                    break
            else:

                continue

            break
    else:

        ans = max(ans,honest_cnt)
print(ans)

Solution (Python):
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)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import product
def main():
    n=int(input())
    XY=[[] 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-1,y))
    tf=list(product([1,0],repeat=n)) 
    ans=0
    for tfx in tf:
        for i,x in enumerate(tfx):
            if x==1: 
                for xxy in XY[i]:
                    if tfx[xxy[0]]!=xxy[1]:
                        break
                else:
                    continue
                break
        else:
            ans=max(ans,sum(1 if a==1 else 0 for a in tfx))
    print(ans)


        
if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import product
def main():
    n=int(input())
    XY=[[] 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-1,y))
    tf=list(product([1,0],repeat=n)) 
    ans=0
    for tfx in tf:
        for i,x in enumerate(tfx):
            if x==1: 
                for xxy in XY[i]:
                    if tfx[xxy[0]]!=xxy[1]:
                        break
                else:
                    continue
                break
        else:
            ans=max(ans,sum(1 if a==1 else 0 for a in tfx))
    print(ans)


        
if __name__=='__main__':
    main()

Solution (Python):
from itertools import product

n = int(input())
a = []
xys = [0] * n
for i in range(n):
    a_tmp = int(input())
    a.append(a_tmp)
    xys[i] = []
    for _ in range(a_tmp):
        xys[i].append(tuple(map(int, input().split())))

li = list(product(range(2), repeat=n))[::-1]
for l in li:
    reps = []
    for i in range(n):
        if l[i]:
            reps.append((i + 1, 1))
            reps += xys[i]
        else:
            reps.append((i + 1, 0))
    reps = list(set(reps))
    flg = True
    for i in range(1, n + 1):
        if (i, 1) in reps and (i, 0) in reps:
            flg = False
            break
    if flg:
        print(sum(l))
        exit()
print(0)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
a = []
xy = []
ans = 0
def hantei(i):
    global bi
    for j in range(a[i]):
        if int(bi[xy[i][j][0]]) != int(xy[i][j][1]):
            return False
    return True
    
for i in range(n):
    s = int(input())
    a.append(s)
    slist = []
    for i in range(s):
        x,y = map(int,input().split())
        x -= 1
        slist.append([x,y])
    xy.append(slist)

for i in range(2**n):
    bi = bin(i)[2:].zfill(n)
    
    for j in range(n):
        if bi[j] == "1":
            if hantei(j) == False:
                break
    else:
        
        ans = max(ans, sum([int(a)for a in bi]))
print(ans)

Solution (Python):
import itertools

n = int(input())
ans = 0
x = [[0 for i in range(15)] for j in range(n)]
y = [[0 for i in range(15)] for j in range(n)]
a = [0 for i in range(n)]
for i in range(n):
    a[i] = int(input())
    for j in range(a[i]):
        tmpx, tmpy = map(int, input().split())
        x[i][j] = tmpx - 1
        y[i][j] = tmpy

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

for i in range(1,n + 1):
    
    for j in itertools.combinations(person,i):
        truth = [0 for i in range(n)]
        flag = True
        
        for k in j:
            
            if truth[k] == -1:
                flag = False
                break
            
            truth[k] = 1
            
            for l in range(a[k]):
                
                if y[k][l] == 0:
                    
                    if truth[x[k][l]] == 1 or x[k][l] in j:
                        flag = False
                        break
                    else:
                        truth[x[k][l]] = -1
                
                else:
                    if truth[x[k][l]] == -1 or not (x[k][l] in j): 
                        flag = False
                        break
                    else:
                        truth[x[k][l]] = 1
            
            if not flag: break
        """
        
        for k in list(set(person) - set(j)):
            
            if truth[k] == 1:
                flag = False
                break
            
            truth[k] = -1
            
            for l in range(a[k]):
                
                if y[k][l] == 0:
                    
                    if truth[x[k][l]] == -1 or x[k][l] in list(set(person) - set(j)):
                        flag = False
                        break
                    else:
                        truth[x[k][l]] = 1
                
                else:
                    if truth[x[k][l]] == 1 or not (x[k][l] in list(set(person) - set(j))):
                        flag = False
                        break
                    else:
                        truth[x[k][l]] = -1
            
            if not flag: break
        """
        if not flag:continue
        
        ans = i
        break

print(ans)

Solution (Python):
n = int(input())
A = []
ans = 0
for i in range(n):
    x =int(input())
    lists = [list(map(int,input().split())) for j in range(x)]
    A.append(lists)

for i in range(2**n):
    honesty = [0]*n
    for j in range(n):
        if (i>>j) & 1:
            honesty[j] = 1
    true = 1
    for j in range(n):
        if honesty[j] == 1:
            for k in range(len(A[j])):
                x,y = A[j][k]
                if not honesty[x-1] == y:
                    true = 0
                    break
    if true == 1:
        ans = max(ans,sum(honesty))
print(ans)

Solution (Python):
N = int(input()) 

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

ans = 0
import itertools
for i in itertools.product([1,0], repeat=N):
    tmp = sum(list(i))
    for j in state:
        if i[j[0]] == 1 and i[j[1]] != j[2]:
            tmp = 0
            break
    ans = max(ans, tmp)
print(ans)

Solution (Python):
import itertools

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

ans = 0

for bit in list(itertools.product([0, 1], repeat=N)):
    ok = True
    for i in range(N):
        if bit[i]:
            for x, y in T[i]:
                if bit[x] != y:
                    ok = False
    if ok:
        ans = max(ans, sum(bit))

print(ans)

Solution (Python):
n = int(input())
shougen=[[-1]*(n+1) for _ in range(n+2)]
for i in range(1,n+1):
  a = int(input())
  for j in range(a):
    x,y = map(int, input().split())
    shougen[i][x]=y
 
ans=0
for i in range(2**n):
  f=True
  for j in range(n):
    if i>>j & 1:
      for k,s in enumerate(shougen[j+1][1:],start=0):
        if s == 1 and not i>>k & 1:
          f=False
        if s == 0 and i>>k & 1:
          f=False
  else:
    if f:
      ans=max(ans, str(bin(i)).count("1"))
 
print(ans)

Solution (Python):
import itertools
n=int(input())
la=[]
for _ in range(n):
  d=int(input())
  for dd in range(d):
    x,y=map(int,input().split())
    la.append([_,x-1,y])
ans=0
for i in itertools.product([0,1],repeat=n):
  s=sum(list(i))
  for l in la:
    if i[l[0]]==1 and i[l[1]]!=l[2]:
      break
  else:
    ans=max(ans,s)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
STATE = [[]]*N
for i in range(N):
    a = int(input())
    STATE[i] = [list(map(int, input().split())) for i in range(a)]

def main():
    ans = 0
    for i in range(1<<N):
        ans = max(ans, detect(i))
    print(ans)

def detect(i):
    ONT = 0
    for j in range(N):
        if  not (i & 1<<j):
            continue
        ONT += 1
        for x, y in STATE[j]:

            if (y==0) ^ (i>>(x-1) & 1) == 0:
                return 0
    return ONT

if __name__ == '__main__':
    main()

Solution (Python):
stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
A = []
i=1
j=-1
while i< len(stdin):
    l=[]
    index=int(stdin[i])
    l.append(index)
    i+=1
    for _ in range(index):
        l.append(list(map(int,stdin[i].split())))
        i+=1
    A.append(l)
ans = 0
for bit in range(2**N):
    s = format(bit,'b').zfill(N)
    flag = True
    for j in range(len(A)):
        if s[j] == '1':
            num = A[j][0]
            for k in range(1,num+1):
                if A[j][k][1]!=int(s[A[j][k][0]-1]):
                    flag = False
                    break
        if not flag:
            break
    if flag:
        ans = max(ans,s.count('1'))
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
STATE = [[]]*N
for i in range(N):
    a = int(input())
    STATE[i] = [list(map(int, input().split())) for i in range(a)]

def main():
    ans = 0
    for i in range(1<<N):
        ans = max(ans, detect(i))
    print(ans)

def detect(i):
    ONT = 0
    for j in range(N):
        if  not (i & 1<<j):
            continue
        ONT += 1
        for x, y in STATE[j]:
            
            
            
            
            
            
            if (y == 1) and (i&(1<<(x-1))) == 0:
                return 0
            
            if (y==0) and (i>>(x-1) & 1) == 1:
                return 0
    return ONT

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = []
xy = []

for _ in range(N):
  a = int(input())
  tmp = [list(map(int, input().split())) for _ in range(a)]
  xy += [tmp]

ans = 0
for i in range(2**N):
  d = {i:-1 for i in range(1, N+1)}
  flag = True
  tmp = 0
  
  for j in range(N):
    
    if (i>>j)&1: 
      tmp += 1
      if d[j+1] == 0:
        flag = False
        break
      d[j+1] = 1
      for x, y in xy[j]:
        if d[x] == -1:
          d[x] = y
        else:
          if d[x] != y:
            flag = False
            break
    else:
      if d[j+1] == 1:
        flag = False
        break
      d[j+1] = 0
    
  if flag:
    ans = max(tmp, ans)

print(ans)

Solution (Python):
n = int(input())
L=[]
for i in range(n):
	a = int(input())
	for j in range(a):
		x,y=map(int, input().split())
		L.append([i,x-1,y])
ans=0
import itertools
for i in itertools.product([1,0], repeat=n):
	s = sum(list(i))
	for l in L:
		if i[l[0]]==1 and i[l[1]]!=l[2]:
			s=0
			break
	ans= max(ans,s)
print(ans)

Solution (Python):


N = int(input())
P = []
ans = 0

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


for i in range(2**N):
  Flag = True
  for j in range(N): 
    
    if (i >> j) & 1 == 1: 
      for YN in P[j]:
        if (i >> YN[0]) & 1 != YN[1]:
          Flag = False
          break

    if Flag:
      continue
    else:
      break

  if Flag:
    ans = max(ans, bin(i).count("1"))

print(ans)

Solution (Python):

n = int(input())
L = [[]*n 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
        L[i].append((x,y))

ans = 0
for i in range(1<<n):
    bit = [(i>>j)&1 for j in range(n)]
    
    flag = True
    for j in range(n):
        if bit[j]:
            for x,y in L[j]:
                if bit[x] != y:
                    flag = False
                    break
            if not flag:
                break
    if flag:
        ans = max(ans,sum(bit))
print(ans)

Solution (Python):
n=int(input())
v=[]
f=True
c=res=0

for i in range(n):
    a=int(input())
    xy=tuple(tuple(map(int,input().split())) for _ in range(a))
    v.append(xy)
for i in range(2**n):
    f=True
    for j in range(n):
        if not (i & (1<<j)):
            continue
        for xy in v[j]:
            x=xy[0]-1
            y=xy[1]
            if y==1 and (not(i & (1<<x))):
                f=False
            if y==0 and (i & (1<<x)):
                f=False
        if not f:
            break
    else:
        c=0
        for k in range(n):
            if (i & (1<<k)):
                c+=1
        res=max(res,c)
print(res)

Solution (Python):
n = int(input())
max_ = 2**n
a = []
for i in range(n):
  p = int(input())
  b = []
  for j in range(p):
    x, y = map(int, input().split())
    b.append((x-1,y))
  a.append(b)
c_max = 0
for i in range(max_):
  mujun = False
  bi = format(i, '0'+str(n)+'b')
  c1 = bi.count("1")
  
  for j in range(len(bi)):
    if bi[j] == "1":
      for syougen in a[j]:
        if bi[syougen[0]] != str(syougen[1]):
          mujun = True
  if not mujun:
    if c1 > c_max:
      c_max = c1
print(c_max)

Solution (Python):
n = int(input())
L = [[]*n 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 = x-1
        L[i].append((x,y))

ans = 0
for i in range(1<<n):
    bit = [(i>>j)&1 for j in range(n)]
    
    flag = True
    for j in range(n):
        if bit[j]:
            for x,y in L[j]:
                if bit[x] != y:
                    flag = False
                    break
            if not flag:
                break
    if flag:
        ans = max(ans,sum(bit)) 
print(ans)

Solution (Python):
n = int(input())
map_list = [[-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())
        map_list[i][x-1]=y
ans=0
for i in range(2**n):
    honest = [0 for i in range(n)]
    for j in range(n):
        if (i>>j)&1:
            honest[j]=1
    flag=True
    for j in range(n):
        if honest[j]:
            for k in range(n):
                if map_list[j][k]==-1:continue
                if map_list[j][k]!=honest[k]:flag=False
    if flag:
        ans=max(ans,honest.count(1))
print(ans)

Solution (Python):


import itertools

n = int(input())

xy = []
for i in range(n):
    a = int(input())
    xy.append([list(map(int, input().split())) for _ in range(a)])
ans = 0
for i in itertools.product([0, 1], repeat=n):
    honest_list = list(i)
    flag = 0
    for index in range(n):
        if i[index] == 0:
            continue
        xy_tmp = xy[index]
        
        for k in range(len(xy_tmp)):
            x, y = xy_tmp[k]

            if honest_list[x-1] != y:
                flag = 1
            
            
            
            
            
            
            
            

        
        
    if flag != 1:
        ans = max(ans, sum(honest_list))

print(ans)

Solution (Python):
from itertools import product

N=int(input())
A=[0]*N
L=[0]*N                    
R=[ [] for _ in range(N)]    
for i in range(N):
  A[i]=int(input())  
  for j in range(A[i]):
    a,b=map(int,input().split())
    R[i].append([a,b])    


pro=product([0,1],repeat=N)
maxi=0
for pat in pro:
  T=[[] for _ in range(N)]
  for i,man in enumerate(pat):
    if man==1:
      for c in R[i]:
        T[c[0]-1].append(c[1])
  
  check=True
  for j,test in enumerate(T):
    for num in test:
      if num!=pat[j]:
        check=False
  if check:
    maxi=max(maxi,sum(pat))
    
print(maxi)

Solution (Python):
N = int(input())
t = []
for _ in range(N):
    A = int(input())
    tt = []
    for _ in range(A):
        tt.append(list(map(int, input().split())))
    t.append(tt)
ans = 0
for b in range(1 << N):
    f = True
    c = 0
    for i, tt in enumerate(t):
        if b >> i & 1:
            c += 1
            for x, y in tt:
                if b >> (x - 1) & 1 != y:
                    f = False
                    break
    if f:
        ans = max(ans, c)

print(ans)

Solution (Python):
N = int(input())
t = []
for _ in range(N):
    A = int(input())
    tt = []
    for _ in range(A):
        tt.append(list(map(int, input().split())))
    t.append(tt)
ans = 0
for b in range(1 << N):
    f = True
    for i, tt in enumerate(t):
        for x, y in tt:
            if b & 1 << i:
                if (b & 1 << (x - 1)) >> (x - 1) != y:
                    f = False
                    break
    if f:
        ans = max(ans, bin(b).count('1'))

print(ans)

Solution (Python):
from itertools import product

n = int(input())
a = []
for _ in range(n):
  a_i = int(input())
  t = []
  for _ in range(a_i):
    t.append(tuple(map(int,input().split())))
  a.append(t)

ans = 0
for case in product(range(2),repeat=n):
  frag = False
  for i in range(n):
    if case[i]==1:
      for x,y in a[i]:
        if case[x-1]!=y:
          frag = True
          break
    if frag:
      break
  if not frag:
    ans = max(ans,sum(case))
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())

from collections import defaultdict
d = defaultdict(list)

for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = [int(x) for x in input().split()]
        d[i].append((x - 1, y))
ans = 0
for k in range(2**n):
    res = 0
    j = bin(k)[2:].zfill(n)
    flag = 1
    for i in range(n):
        if j[i] == "0":
            continue
        for x, y in d[i]:
            if int(j[x]) != int(y):
                flag = 0
                break
        res += 1
    if flag:
        ans = max(ans, res)
print(ans)

Solution (Python):
n=int(input())
axy=[]

for i in range(n):
    ai=int(input())
    axy.append([])
    for j in range(ai):
        axy[-1].append(list(map(int,input().split())))

ans=0
pat=2**n

for p in range(pat):
    
    bin_p=list(map(int,bin(p)[2:].zfill(n)))

    flag=False

    for i in range(n):

        for axyi in axy[i]:

            if(bin_p[i]==1 and bin_p[axyi[0]-1] != axyi[1]):
                flag=True
                break






        if(flag):
            break
    else:

        ans=max(ans,bin_p.count(1))
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    A=[0]*n
    st=[[] for _ in range(n)]
    for i in range(n):
        a=int(input())
        for j in range(a):
            x,y=map(int,input().split())
            st[i].append((x,y))

    
    
    
    
    ans=0
    for i in range(2 ** n):
        inconsistent=False
        cnt=0
        for j in range(n):  
            if ((i >> j) & 1):  
                cnt+=1
                for p in st[j]:
                    if p[1]==1 and not ((i >> (p[0]-1) & 1)):
                        inconsistent=True
                    elif p[1]==0 and not not ((i >> (p[0]-1) & 1)):
                        inconsistent=True
            else:
                continue
            

        if not inconsistent:
            ans=max(ans,cnt)
    print(ans)
    

    
resolve()

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
ls_a = []
ls_xy = []
for i in range(n):
    a = int(input())
    ls_a.append(a)
    xy = mylistinput(a)
    ls_xy.append(xy)



ans = 0
for i in range(2**n):
    flag = True
    for j in range(n):
        if i & (2**j):
            for k in range(len(ls_xy[j])):
                x = ls_xy[j][k][0] - 1
                y = ls_xy[j][k][1]
                if y==1:
                    if i & (2**x) > 0:
                        pass
                    else:
                        flag = False
                elif y==0:
                    if i & (2**x) == 0:
                        pass
                    else:
                        flag = False
    if flag:
        tmp = sum( list(map(int,list(bin(i)[2:]))) )
        ans = max( ans, tmp )

print(ans)

Solution (Python):
import itertools

N = int(input())
L = []
for i in range(N):
    A = int(input())
    x = [tuple(map(int,input().split())) for i in range(A)]
    L.append(x)
    
X = list(itertools.product([0,1],repeat=N))
ans = 0

for i in X:
    cnt = True
    for j,value in enumerate(i):
        if value  == 1:
            for k,m in L[j]:
                if i[k-1] != m:
                    cnt = False
    if cnt:
        ans = max(ans,sum(i))
           
print(ans)

Solution (Python):
import sys, heapq, bisect, math, fractions
from collections import deque

N = int(input())
xy = [[] for _ in range(N)]
for i in range(N):
    a = int(input())
    for _ in range(a):
        xy[i].append(tuple(map(int, input().split())))
        
def ok(i: int, j: int):
    for x, y in xy[j]:
        if y == 0 and (i >> (x - 1) & 1 == 1):
            return False
        if y == 1 and (i >> (x - 1) & 1 == 0):
            return False
    return True

res = 0
for i in range(2 ** N):
    cnt = 0
    for j in range(N):
        if i >> j & 1 == 1:
            cnt += 1
            if not ok(i, j):
                break
    else:
        res = max(res, cnt)

print(res)