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):
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
from itertools import product
l=list(product([1,0],repeat=N))
L=[]
for i in range(N):
    A=int(input())
    for j in range(A):
        x,y=map(int,input().split())
        L.append([x,y,i+1])
a=0
for i in l:
    t=N
    for j in L:
        if i[j[2]-1]==1 and j[1]!=i[j[0]-1]:
            break
    else:
        if a<i.count(1):
            a=i.count(1)
print(a)

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

alist=[]
for i in range(N):
  ai=int(input())
  ailist=[]
  for j in range(ai):
    xij,yij=map(int,input().split())
    if yij==0:
      ailist.append((xij-1,False))
    else:
      ailist.append((xij-1,True))
    
  alist.append(ailist)


answer=0
for i in range(2**N):
  bin_str=format(i, '0'+str(N)+'b')
  dlist=list(map(int,list(bin_str)))
  
  
  contra=False
  for j in range(N):
    
    if dlist[j]==1:
      for aj in alist[j]:
        x,y=aj
        if y and dlist[x]==0:
          contra=True
          break
        elif not y and dlist[x]==1:
          contra=True
          break
    if contra:
      break
  else:
    
    answer=sum(dlist)

print(answer)

Solution (Python):
N=int(input())
X=[[] for _ in range(N)]
Y=[[] for _ in range(N)]
for i in range(N):
    m=int(input())
    for j in range(m):
        x,y=map(int,input().split())
        X[i].append(x-1)
        Y[i].append(y)
max_=0
for i in range(2 ** N):
    op = [0] * N  
    for j in range(N):
        if ((i >> j) & 1):
            op[N - 1 - j] = 1  
    
    exit=False
    for j in range(N):
        if op[j] == 1:
            for k in range(len(X[j])):
                if Y[j][k]!=op[X[j][k]]:
                    
                    exit=True
                    break
        if exit:
            break
    else:
        
        max_=max(max_,sum(op))
print(max_)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=[]
xy=[]
for i in range(n):
    tmp=int(input())
    a.append(tmp)
    tmp2=[list(map(int,input().split())) for i in range(tmp)]
    xy.append(tmp2)
bit=2**n
ans=0

for i in range(bit):
    flag=1
    for j in range(n):
        if i&(1<<j)!=0:
            for k in range(a[j]):
                if (i>>xy[j][k][0]-1)&1!=xy[j][k][1]:
                    flag=0
    
    if flag==1:
        tmp=0
        for j in range(n):
            if i&(1<<j)!=0:
                tmp+=1
        ans=max(ans,tmp)
print(ans)

Solution (Python):
n = int(input())
g = [[-1] * n for _ in range(n)]
for i in range(n):
	a = int(input())
	for _ in range(a):
		x, y = map(int, input().split())
		g[i][x - 1] = y
ans = 0
for m in range(2 ** n):
	f = 1
	for i in range(n):
		for j in range(n):
			if g[i][j] < 0:
				continue
			if (1 << i) & m:
				if g[i][j] != int((1 << j) & m > 0):
					f = 0
					break
	if f:
		ans = max(ans, bin(m).count("1"))
print(ans)

Solution (Python):
n = int(input())
xy = []
for _ in range(n):
    a = int(input())
    ls = []
    for _ in range(a):
        x, y = map(int, input().split())
        ls.append((x - 1, y))
    xy.append(ls)

ans = 0
for p in range(2 ** n + 1):
    candidate = 0
    friends = {}
    for i in range(n):
        if p & (1 << i) > 0:
            friends[i] = 1
        else:
            friends[i] = 0

    valid = True
    for i in range(n):
        if p & (1 << i) > 0:
            friendly = True
            for x, y in xy[i]:
                if friends[x] != y:
                    friendly = False

            if friendly:
                candidate += 1
            else:
                valid = False
                break
    if valid:
        ans = max(ans, candidate)

print(ans)

Solution (Python):

N = int(input())
XY = []
for i in range(N):
    a = int(input())
    kari = []
    for j in range(a):
        kari.append(list(map(int,input().split())))
    XY.append(kari)
    
N2 = 2**N
ans = 0
for i in range(N2):
    b = bin(i)
    b = b.lstrip("0b")
    while len(b) < N:
        b = "0"+b
        
    flag = 0
    boo = [-1]*N
    for j in range(N):
        if b[j] == "1":
            if boo[j] == 0:
                flag = 1
                break
            else:
                boo[j] = 1
                for xy in XY[j]:
                    x,y = xy
                    if boo[x-1] == -1:
                        boo[x-1] = y
                    else:
                        if boo[x-1] != y:
                            flag = 1
                            break
        else:
            if boo[j] == 1:
                flag = 1
                break
            else:
                boo[j] = 0
    if flag == 0:
        kari = 0
        for bo in boo:
            if bo == 1:
                kari+=1
        ans = max(ans,kari)
    
print(ans)

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

seq = []
for i in range(N):
   seq.append(i) 
max_num = 0
for i in range(N):
    comb_list = list(itertools.combinations(seq,i))
    for comb in comb_list:
        tmp = [-1]*N
        flag = True
        for i2 in range(N):
            if i2 in comb:
                continue
            for xy in An[i2]:
                if tmp[xy[0]-1] == -1:
                    tmp[xy[0]-1] = xy[1]
                else:
                    if tmp[xy[0]-1] != xy[1]:
                        flag = False
        for i2 in range(N):
            if i2 in comb: 
                if tmp[i2] == 1:
                    flag = False
            else:
                if tmp[i2] == 0:
                    flag = False
        if flag:
            max_num = N - i
    if max_num > 0:
        break
print(max_num)

Solution (Python):
n=int(input())
l=[]
for i in range(n):
  x=[]
  a=int(input())
  x=[list(map(int,input().split())) for j in range(a)]
  l.append(x)

b=[]
for k in range(2**n):
  b.append(format(k,'0'+str(n)+'b'))
ans=[]
for i in range(2**n):
  ct1=0
  ct2=0
  for j in range(n):
    if b[i][j]=='1':
      ct1+=1
      ct=0
      for k in range(len(l[j])):
        if int(b[i][l[j][k][0]-1])!=l[j][k][1]:
          ct+=1
      if ct==0:
        ct2+=1
    else:
      ct2+=1
  if ct2==n:
    ans.append(ct1)
print(max(ans))

Solution (Python):
def c_honest_or_unkind_2():
    N = int(input())
    Answers = []
    for _ in range(N):
        a = int(input())
        Answers.append([[int(i) for i in input().split()] for j in range(a)])

    
    ret = -1
    for bits in range(1 << N):
        honests = set()
        unkinds = set()
        for k in range(N):
            if (bits >> k) & 1 == 1:
                honests.add(k)
            else:
                unkinds.add(k)
        
        is_contradict = False
        for k, answer in enumerate(Answers):
            if k not in honests:
                continue

            for x, y in answer:
                x -= 1
                if (y == 1 and x in unkinds) or (y == 0 and x in honests):
                    
                    is_contradict = True
                    break
            if is_contradict:
                break
        else:
            
            ret = max(ret, len(honests))
    return ret

print(c_honest_or_unkind_2())

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

to_bit = [1 << i for i in range(n)]
from_bit = {1 << i: i for i in range(n)}
ans = 0
for check in range(1 << n):
    b = check
    flag = True
    while b:
        bit = b & -b
        i = from_bit[bit]
        for x, y in testimonies[i]:
            if (check >> x) & 1 != y:
                flag = False
                break
        if not flag:
            break
        b ^= bit

    if flag:
        ans = max(ans, bin(check).count('1'))

print(ans)

Solution (Python):
from itertools import product
N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
    na = int(input())
    for j in range(na):
        x, y = map(int, input().split())
        A[i].append((x-1, y))
ans = 0
for pat in product((0, 1), repeat=N):
    num = pat.count(1)
    mujun = False
    for i, shogen in enumerate(A):
        if pat[i] == 0:
            continue
        for s in shogen:
            x, y = s
            if pat[x] != y ^ (1 - pat[i]):
                mujun = True
                break
        if mujun:
            break
    if mujun:
        continue
    ans = max(ans, num)
print(ans)

Solution (Python):
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res



n = int(input())
ms = []
say = []
for i in range(n):
    m = int(input())
    ms.append(m)
    say.append([])
    for j in range(m):
        p,q = list(map(int, input().split()))
        say[i].append([p,q])


ans=0

for i in range(2**n):
    flag = 1
    nowbit = bitlist(i,n)
    total = sum(nowbit)
    for j in range(n):
        for k in range(ms[j]):
            
            
            if(nowbit[j]==1):
                if(nowbit[say[j][k][0]-1]!=say[j][k][1]):
                    flag=0
    if(flag==1 and ans<total):
        ans=total


print(ans)

Solution (Python):
from collections import defaultdict 

n=int(input())
yes=defaultdict(list)
no=defaultdict(list)
for i in range(1,n+1):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        if y==0:
            no[i].append(x)
        else:
            yes[i].append(x)

maxi=0 
tot=(1<<n)
def ok(curr):
    for a  in range(1,n+1):
        if a in curr:
            for z in yes[a]:
                if z not in curr:
                    return 0 
            for z in no[a]:
                if z in curr:
                    return 0
    return 1 


for i in range(tot):
    curr=[]
    for j in range(n):
        if i&(1<<j):
            curr.append(j)
    curr=[i+1 for i in curr]
    if ok(curr):
       
        maxi=max(maxi,len(curr))
print(maxi)

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

A = []
xy = []
for i in range(N):
    A.append(int(input()))
    xy_tmp = []
    for j in range(A[i]):
        xy_tmp.append(list(map(int, input().split())))
    xy.append(xy_tmp)

ans = 0
for state in range(2 ** N):
    
    ans_tmp = 0
    state_tmp = state
    honest = [None] * N
    valid = True
    state_bin = [(state >> i) % 2 for i in range(N)]
    for i in range(N):
        if state_bin[i] > 0:
            xy_tmp = xy[i]
            for xj, yj in xy_tmp:
                if honest[xj - 1] == None:
                    honest[xj - 1] = yj
                elif honest[xj - 1] != yj:
                    valid = False
                    break
            ans_tmp += 1
        if valid == False: break
    if valid == False: continue
    
    for i in range(N):
        if state_bin[i] == 1 and honest[i] == 0:
            valid = False
            break
        if state_bin[i] == 0 and honest[i] == 1:
            valid = False
            break
    
    if valid:
        
        ans = max(ans, ans_tmp)

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n = ri()
ls = []
for _ in range(n):
    a = ri()
    s0 = set()
    s1 = set()
    for _ in range(a):
        i, b = ril()
        if b == 0:
            s0.add(i - 1)
        else:
            s1.add(i - 1)
    ls.append((s0, s1))

res = 0
for b in range(1, 2**n):
    b = bin(b)[2:].rjust(n, '0')
    count = b.count('1')
    if count <= res:
        continue
    ss0 = set()
    ss1 = set()
    t0 = set()
    t1 = set()
    for i, c in enumerate(b):
        s0, s1 = ls[i]
        if c == '1':
            t1.add(i)
            ss0.update(s0)
            ss1.update(s1)
        else:
            t0.add(i)
    if ss0 & ss1 or ss0 & t1 or ss1 & t0:
        continue
    res = count
print(res)

Solution (Python):
N=int(input())
def bi(num):
  ls_bi=[0 for _ in range(N+1)]
  for bi_i in range(N):
    if (2**bi_i)&num>0:
      ls_bi[bi_i]=1
      ls_bi[N]+=1
  return ls_bi

syogen=[[-1 for _  in range(N)] for _ in range(N)]

for i in range(N):
  Ai=int(input())
  for j in range(Ai):
    x,y=[int(s) for s in input().split()]
    syogen[i][x-1]=y

ans=[]
for n in range(2**N):
  ls=bi(n)
  flag=1
  for i in range(N):
    if ls[i]==1:
      for j in range(N):
        if ls[j]==syogen[i][j] or syogen[i][j]==-1:
          continue
        else:
     
          flag=0
          break
    if flag==0:
      break
  else:
    ans.append(ls[N])
print(max(ans))

Solution (Python):
import itertools

n = int(input())
tt = [[] for _ in range(n + 1)]
for i in range(n ):
	j = int(input())
	for _ in range(j):
		a, b = list(map(int, input().split()))
		tt[i].append([a - 1, b])


max_ans = 0
for xx in list(itertools.product([0, 1], repeat = n)):
	flg = 1
	for i in range(n):
		x = xx[i]
		if x == 1:
			for t in tt[i]:
				if xx[t[0]] != t[1]:
					flg = 0
					break
	if flg == 1:
		
		max_ans = max(max_ans, sum(xx))

print(max_ans)

Solution (Python):
n = int(input())
a = []
s = []
for i in range(n):
  _a = int(input())
  a.append(_a)
  s.append([list(map(int, input().split())) for j in range(_a)])
bins = []
for i in range(2**n):
  binary = bin(i)[2:]
  binary = '0' * (n-len(binary)) + binary
  bins.append(list(map(int,list(binary))))

ans = 0
for binlist in bins:
  for i, p in enumerate(binlist):
    if p == 1:
      cnt = 0
      for state in s[i]:
        if binlist[state[0]-1] != state[1]:
          break
        else:
          cnt += 1
      if cnt < len(s[i]):
        break
  else:
    ans = max(ans, len(list(filter(lambda x: x==1, binlist))))
print(ans)

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

reply = [[-1] * N for _ in range(N)]

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

ans = 0

for i in range(1<<N):
    flag = True
    for j in range(N):
        if i>>j&1 == 1:
            for k in range(N):
                if reply[j][k] == 1:
                    if i>>k&1 == 0:
                        flag = False
                        break
                elif reply[j][k] == 0:
                    if i>>k&1 == 1:
                        flag = False
                        break
            if not flag:
                break
    if flag:
        count = 0
        for j in range(N):
            if i>>j&1:
                count += 1
        ans = max(ans, count)

print(ans)

Solution (Python):
import sys
from itertools import product

input = sys.stdin.readline
def main():
    N = int( input())
    A = [[0]*N for _ in range(N)]
    C = [0]*N
    for i in range(N):
        C[i] = int( input())
        for _ in range(C[i]):
            x, y = map( int, input().split())
            A[i][x-1] = -1+y*2
    ans = 0
    T = [-1, 1]
    for P in product( range(-1, 2, 2), repeat = N):
        check = True
        for i in range(N):
            if P[i] == -1:
                continue
            for j in range(N):
                if A[i][j] == 0:
                    continue
                if A[i][j]*P[i] != P[j]:
                    check = False
                    break
        if check:
            if ans < (sum(P) + N)//2:
                ans = (sum(P) + N)//2
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import sys
input=sys.stdin.readline
def two(x):
	p=bin(x)
	ans=p[2:]
	if len(ans)<n:
		ans="0"*(n-len(ans))+ans
	return ans
n=int(input())
aa=[]
aaa=[]
for i in range(n):
	a=int(input())
	aaa.append(a)
	qw=[]
	for j in range(a):
		x,y=map(int,input().split())
		qw.append([x,y])
	aa.append(qw)
anst=0
for i in range(2**n):
	p=two(i)
	flag=True
	syojiki=[]
	for u in range(n):
		if p[u]=="1":
			syojiki.append(1)
		else:
			syojiki.append(0)
	ans=p.count("1")
	for j in range(n):
		if flag==False:
			break
		if p[j]=="0":
			continue
		for k in range(aaa[j]):
			if aa[j][k][1]==0:
				if syojiki[aa[j][k][0]-1]==1:
					flag=False
					break
				syojiki[aa[j][k][0]-1]=0
			else:
				if syojiki[aa[j][k][0]-1]==0:
					flag=False
					break
				syojiki[aa[j][k][0]-1]=1
	if flag:
		anst=max(anst,ans)
print(anst)

Solution (Python):

import sys
from heapq import heappush, heappop
from itertools import product
from math import sqrt
from collections import defaultdict

def inpl(): return list(map(int, input().split()))
N = int(input())
D = [[-1]*N for i in range(N)]

for i in range(N):
    a = int(input())
    for _ in range(a):
        x, y = inpl()
        D[i][x-1] = y

ans = 0
for X in product(range(2), repeat=N):
    OK = True
    for i in range(N):
        if X[i] == 0:
            continue
        for j in range(N):
            if D[i][j] == -1:
                continue
            if D[i][j] != X[j]:
                OK = False
                break
    if OK:
        ans = max(ans, sum(X))
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
g=[[] for i in range(n)]
for i in range(n):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        g[i].append((x-1,y))
N=2**n
ans=0
for i in range(N):
    c_list=[]
    for j in range(n):
        c_list.append((i>>j)%2)
    check=1
    for j in range(n):
        if c_list[j]:
            for z in g[j]:
                if not c_list[z[0]]==z[1]:
                    check=0
    if check:
        ans=max(ans,sum(c_list))
print(ans)

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

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


def bc(x):
    return bin(x).count("1")

ans = 0
for i in range(2**n):
    is_ok = True
    for j in range(n):
        if (i>>j) & 1:
            for x, y in xys[j]:
                if ((i>>(x-1)) & 1) != y :
                    is_ok = False
                    break
    if is_ok:
        cnt = bc(i)
        if ans < cnt:
            ans = cnt
print(ans)

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

ls = {}
for i in range(n):
    a = int(input())
    ls[i] = []
    for j in range(a):
        ls[i].append(list(map(int,input().split())))

c = 0
check = [0]*n
ans = 0
while c < (2 ** n):
    count = 0
    wari = c
    while wari > 0:
        
        check[count] = ((wari % 2 != 0) + 0)
        wari //= 2
        count += 1
    c += 1
    wari = 0
    
    mujyun = 0

    for v in check:
        if v == 0:
            wari += 1
            continue
        for a,b in ls[wari]:
            a -= 1
            if b != check[a]:
                mujyun = 1
                break
        if mujyun != 0:
            break
        wari += 1
    if mujyun != 0:continue
    else:ans = max(ans,sum(check))
print(ans)

Solution (Python):
import itertools
n = int(input())

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


def check(_ts):
    _ts = list(_ts)
    ts = list(_ts[:])
    a = [-1] * n
    while ts:
        t = ts.pop()
        for i in range(n):
            if a[i] == -1:
                a[i] = graph[t][i]
                if graph[t][i] == 1:
                    ts.append(i)
                    _ts.append(i)
            if graph[t][i] == -1:
                pass
            elif a[i] != graph[t][i]:
                return False
    for t in _ts:
        if a[t] == 0:
            return False
    return True


for m in range(n, 0, -1):
    for p in itertools.combinations(range(n), r=m):

        if check(p):
            print(m)
            exit()
print(0)

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

ans = 0
for i in range(1 << n):
    for j in range(n):
        count_j = True
        if i & 1 << j:
            for say_j in say[j]:
                if say_j[1] == 1:
                    if not i & 1 << (say_j[0] - 1):
                        count_j = False
                        break
                else:
                    if i & 1 << (say_j[0] - 1):
                        count_j = False
                        break
        if not count_j:
            break
    if  count_j:
        cnt = 0
        for j in range(n):
            if i & 1 << j:
                cnt += 1
        ans = max(ans, cnt)
print(ans)

Solution (Python):
n = int(input())
arr = []
for i in range(n):
    A = int(input())
    t = []
    for _ in range(A):
        t.append(list(map(int, input().split())))
    arr.append(t)
ans = 0
for i in range(2 ** n):
    tmp = ''
    for k in range(n):
        if 1 & i>>k:
            tmp = '1' + tmp
        else:
            tmp = '0' + tmp
    flg = True
    for k in range(n):
        if tmp[k] == '1':
            for l in arr[k]:
                if (l[1] == 1 and tmp[l[0]-1] == '1') or (l[1] == 0 and tmp[l[0]-1] == '0'):
                    continue
                else:
                    flg = False
    if flg:
        ttmp = 0
        for k in tmp:
            ttmp += int(k)
        if ans < ttmp:
            ans = ttmp
print(ans)

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



def check(arr):
    for idx, a in enumerate(A):
        
        if arr[idx] == 0:
            continue
        
        for x, y in a:
            if arr[x-1] != y:
                return False
    return True

all_comb = []
for i in range(2**N):
    comb = []
    for j in range(N):
        if (i >> j) & 1:
            comb.append(1)
        else:
            comb.append(0)
    all_comb.append(comb)
ret = 0
for comb in all_comb:
    if check(comb):
        ret = max(ret, sum(comb))

print(ret)

Solution (Python):
import copy
import itertools
def main():
    n = int(input())
    m = []
    for i in range(n):
        a = int(input())
        am = []
        for j in range(a):
            am.append(tuple(map(int,input().split())))
        m.append(copy.deepcopy(am))
    it = itertools.product([0,1],repeat=n)
    ans = 0
    for i in it:
        flag = True
        for x in range(len(i)):
            if i[x] == 1:
                if not all([k==i[j-1] for j,k in m[x]]):
                    flag = False
                    break
        if flag:
            ans = max([ans,sum(i)])
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

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

ans = 0
for i in range(1<<n):
    l = [i&(1<<j)!=0 for j in range(n)]
    f = True
    for j in range(n):
        if l[j]:
            if not all(G[j][k] == -1 or l[k] == G[j][k] for k in range(n)):
                f = False
                break
    if f:
        ans = max(ans, sum(l))

print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

n = int(input())
a_xy = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = [int(item) for item in input().split()]
        a_xy[i].append((x-1, y))
    
ans = 0

for i in range(2**n):
    ok = True
    for j in range(n):
        
        if i & (1 << j):
            for x, y in a_xy[j]:
                if y == 1:
                    if not (i & (1 << x)):
                        ok = False
                        break
                else:
                    if i & (1 << x):
                        ok = False
                        break
        if not ok:
            break
    if ok:
        ans = max(ans, bin(i).count("1"))

print(ans)

Solution (Python):
N = int(input())
lis = [[] for _ in range(N)]

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

ans = 0
for i in range(2**N):
    s = True
    person =[]
    for _ in range(N):
        person.append(i%2)
        i = i // 2
    for j in range(N):
        if person[j]==1:
            for k in lis[j]:
                if person[k[0]-1] != k[1]:
                    s = False
                    break
            if not s:
                break
    if s and ans < person.count(1):
        ans = person.count(1)
print(ans)

Solution (Python):
import itertools
n = int(input())

po = {}

for i in range(n):
  ai = int(input())
  po_dict = {}
  for j in range(ai):
    x,y = map(int, input().split())
    po_dict[x-1]=y
  po[i]=po_dict


  
def check(lis):
  for i, yi in enumerate(lis):
    if yi==1:
      
      for k,v in po[i].items():
        if lis[k]!=v:
          return False
  return True

ys=[0,1]
max_t=0
for lis in itertools.product(ys,repeat=n):
  if check(lis):
    if max_t <sum(lis):
      max_t = sum(lis)

print(max_t)

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = [0]*n
z = [ [] for i in range(n) ]
for i in range(n):
    aa = inn()
    a[i] = aa
    for j in range(aa):
        x,y = inm()
        x -= 1
        z[i].append((x,y))

mx = 0
for i in range(2**n):
    honest = [ ((i>>j)&1 == 1) for j in range(n) ]
    nbits = sum([ ((i>>j)&1) for j in range(n) ])
    ok = True
    for j in range(n):
        if not honest[j]:
            continue
        for u in z[j]:
            x,y = u
            if honest[x] and y==0 or not honest[x] and y==1:
                ok = False
                break
        if not ok:
            break
    
    if ok and nbits>mx:
        mx = nbits

print(mx)

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

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

ans=0
for k in range(2**N):
  hu=list(map(int,bin(k)[2:].zfill(N)))
  j=0
  for i in range(len(XY)):
    if hu[i]==1:
      for x,y in XY[i]:
        if hu[x-1]!=y:
          j=1
  if j==0:
    ans=max(ans,hu.count(1))
print(ans)

Solution (Python):

import itertools

N = int(input().split()[0])

a_list = []
xy_list_list = []

for _ in range(N):
    a = int(input().split()[0])
    a_list.append(a)
    xy_list = []
    for _ in range(a):
        x, y = list(map(int, input().split()))
        xy_list.append((x, y))
    xy_list_list.append(xy_list)


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

for pattern in p_list:  
    is_ok = True
    for i in range(N):  
        if pattern[i] == 0:
            
            continue
        for xy in xy_list_list[i]:  
            x, y = xy
            x = x - 1
            if pattern[x] != y:
                
                is_ok = False
                break
        if not is_ok:
            
            break
    if is_ok:
        max_c = max(max_c, sum(pattern))

ans = max_c
print(ans)

Solution (Python):
N = int(input())
A = []
X = [[] for _ in range(N)]
for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        X[i].append(list(map(int,input().split())))
ans = 0
for i in range(2**N):
    flag = False
    for j in range(N):
        if ((i >> j) & 1):
            for k in range(A[j]):
                if X[j][k][1]==1 and not ((i>>X[j][k][0]-1)&1):
                    flag = True
                    break
                if X[j][k][1]==0 and ((i>>X[j][k][0]-1)&1):
                    flag = True
                    break
        if flag:
            break
    if not flag:
        tmp = 0
        for j in range(N):
            if ((i >> j) & 1):
                tmp += 1
        ans = max(tmp,ans)
print(ans)

Solution (Python):
import queue
import math
import copy
"""
N = int(input())



A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
P = 0
N = int(input())
ans = 0
mp =[]
for i in range(N):
	a = int(input())
	mp.append([])
	for j in range(a):
		(s,t) = (int(i) for i in input().split(" "))
		mp[-1].append([s-1,t])

for P in range(1 << N):
	p_num = P
	pp = []
	for i in range(N):
		pp.append(p_num&1)
		p_num >>= 1
	p_len = sum(pp)
	
	ch = True
	for i in range(N):
		for info in mp[i]:
			if pp[i]==1 and (pp[info[0]] != info[1]):
				ch = False
				break
	
	if ch and p_len > ans:
		ans = p_len
print(ans)

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

ans = 0
for S in range(2**N):
    numHonest = 0
    isOK = True
    for i in range(N):  
        if (S>>i)&1 == 0:
            continue

        numHonest += 1
        xys = xyss[i]
        A = len(xys)
        for x, y in xys:  
            if (S>>x)&1 != y:
                isOK = False
                break
        if not isOK:
            break

    if isOK:
        ans = max(ans, numHonest)

print(ans)