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
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

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

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

Solution (Python):

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

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

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

Solution (Python):

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

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

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

Solution (Python):
def main():
    N = int(input())
     
    testimony = [[] for _ in range(N)]
     
    for i in range(N):
        num = int(input())
        for j in range(num):
            person, state = map(int, input().split())
            testimony[i].append([person-1, state])
            
    honest = 0
    for i in range(1, 2**N):
        flag = 0
        for j in range(N):
            if (i>>j)&1 == 1: 
                for x,y in testimony[j]:
                    if (i>>x)&1 != y: 
                        flag = 1
                        break
        if flag == 0:  
            honest = max(honest, bin(i)[2:].count('1'))  
    print(honest)
if __name__=="__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
n = int(input())
people = []
shogens = [[]for i in range(n)]
def check():
    for i in range(n):
        if i not in people:continue
        for shogen in shogens[i]:
            person = shogen[0]
            honest = shogen[1]
            if honest and person not in people:return False
            if (not honest) and person in people:return False
    return True
        
            
            
            
        
for i in range(n):
    a = int(input())
    for j in range(a):
        p,q = map(int,input().split())
        p -= 1
        shogens[i].append((p,q))
def dfs(d,people):
    if d == n:
        
        if check():
            
            return len(people)
        else:
            return 0
    res = dfs(d+1,people)
    people.append(d)
    res = max(res,dfs(d+1,people))
    people.pop()
    return res
print(dfs(0,people))

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

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

ans = 0
fm = "0"+str(n)+"b"
for i in range(2**n):
    flag = True
    s = str(format(i,fm))
    for j in say:
        if s[j[0]] == "1" and int(s[j[1]]) + j[2] == 1:
            flag = False
            break
    if flag and ans < s.count("1"):
        ans = s.count("1")

print(ans)

Solution (Python):
N = int(input())
honest = [[] for _ in range(N)]
unkind = [[] for _ in range(N)]
MAX = 0
for i in range(0,N):
    A = int(input())
    for _ in range(A):
        x, y =map(int,input().split(' '))
        if y == 0:
            unkind[i].append(x-1)
        else:
            honest[i].append(x-1)

for i in range(2**N):
    flg = 1
    for j in range(N):
        if ((i>>j) & 1):
            bool1 = all([(i>>k) & 1 for k in honest[j]])
            bool2 = all([~(i>>k) & 1 for k in unkind[j]])
            if not all([(i>>k) & 1 for k in honest[j]]) or not all([~(i>>k) & 1 for k in unkind[j]]):
                flg =0

    if flg:
        cnt = 0
        num = i
        while num:
            num &= num -1
            cnt += 1
        MAX = max(cnt,MAX) 

print(MAX)

Solution (Python):


N = int(input())
testimony = [[None for _ in range(N)] for _ in range(N)]
person = [None] * N

for i in range(N):
    person[i] = int(input())
    for _ in range(person[i]):
        j, good_or_bad = map(int, input().split())
        j -= 1
        testimony[i][j] = good_or_bad



ans = 0

for i in range(1, 1<<N):
    which_person = [None] * N
    for j in range(N):
        which_person[j] = i>>j & 1
        
    ok = True
    for j in range(N):
        if which_person[j]:
            for k in range(N):
                if testimony[j][k] == None:
                    continue
                if testimony[j][k] != which_person[k]:
                    ok = False
    if ok:
        ans = max(ans, which_person.count(1))
print(ans)

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

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

ans=0

for i in range(2**n):
    flag=0
    cnt=0
    for j in range(n):
        if((i>>j)&1)==1 and flag==0:
            for k in range(len(word[j])):
                if ((i>>word[j][k][0]-1)&1) != word[j][k][1]:
                    flag=1
                    break
    
    if flag==0:
        cnt=bin(i).count("1")
        ans=max(ans, cnt)

print(ans)

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

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

ans=0

for i in range(2**n):
    flag=0
    cnt=0
    for j in range(n):
        if((i>>j)&1)==1 and flag==0:
            for k in range(len(word[j])):
                if ((i>>word[j][k][0]-1)&1) != word[j][k][1]:
                    flag=1
                    break
    
    if flag==0:
        cnt=bin(i).count("1")
        ans=max(ans, cnt)

print(ans)

Solution (Python):

n = int(input())


a = []

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

def judge(bit):
    
    
    

    
    for i in range(n):
        
        if not(bit & (1 << i)):
            continue
        
        for j in xy[i]:
            
            
            if j[1] == 1 and not(bit & (1 << (j[0]-1))):
                return False

            
            if j[1] == 0 and (bit & (1 << (j[0]-1))):
                return False

    return True

max_person = 0

for bit in range(1 << n):
    if judge(bit):
        count = 0
        
        for i in range(n):
            if bit & (1 << i):
                count += 1
        if max_person < count:
            max_person = count

print(max_person)

Solution (Python):
n = int(input())
l = [[] for _ in range(n)]
ans = 0

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

for i in range(2**n):
    judge = True
    for j in range(n):
        if judge == False:
            break
        if i & (1 << j): 
            for x, y in l[j]:
                if y == 0 and i & 1 << (x - 1): 
                    judge = False
                if y == 1 and i & 1 << (x - 1) == 0: 
                    judge = False
    if judge == True:
        cnt = bin(i).count("1")
        ans = max(ans, cnt)

print(ans)

Solution (Python):
n = int(input())
l = [[] for _ in range(n)]
ans = 0

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

for i in range(2**n):
    judge = True
    for j in range(n):
        if i & (1 << j): 
            for x, y in l[j]:
                if y == 0 and i & 1 << (x - 1): 
                    judge = False
                if y == 1 and i & 1 << (x - 1) == 0: 
                    judge = False
    if judge == True:
        cnt = bin(i).count("1")
        ans = max(ans, cnt)

print(ans)

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

a = []

evidences = []
for i in range(n):
    ls = []
    x = int(input())
    a.append(x)
    for j in range(x):
        l = [int(_) for _ in input().split(' ')]
        ls.append(l)
    evidences.append(ls)

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

honest = 0
for pattern in patterns:
    contradict = False
    for i in range(n):
        for evidence in evidences[i]:
            if(pattern[i] == 1):
                if (pattern[evidence[0]-1] != evidence[1]):
                    contradict = True
    if (contradict == False):
        honest = max(honest, pattern.count(1))

print(honest)

Solution (Python):
if __name__ == "__main__":
    n = int(input())
    info = []
    for _ in range(n):
        a = int(input())
        tmp = []
        for __ in range(a):
            tmp.append(list(map(int, input().split())))
        info.append(tmp)
    
    mask = 0
    honest = [0] * n
    ans = 0
    while mask < (1 << n):
        part = 0
        is_ok = True
        for i in range(n):
            if 1  & mask >> i  == 1:
                 honest[i] = 1
                 part += 1
            else:
                honest[i] = 0

        for i in range(n):
            if honest[i] == 1:
                for w in info[i]:
                    if honest[w[0] - 1] != w[1]:
                        is_ok = False
        
        if is_ok:
            if part > ans:
                ans = part
        mask += 1
    print(ans)

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

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

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

Solution (Python):
from collections import defaultdict


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

    
    for i in range(2**N):
        trust = True

        
        
        
        trust_combs = []
        for j in range(N):
            if (i >> j) & 1:
                trust_combs.append(1)
            else:
                trust_combs.append(0)
  
        
        
        for k in range(len(trust_combs)):
            if trust_combs[k] == 1:
                for l in d[k]:
                    if not l[1] == trust_combs[l[0]-1]:
                        trust = False
        if trust:
            max_trust_num = max(max_trust_num, sum(trust_combs))

    print(max_trust_num)


if __name__ == "__main__":
    main()

Solution (Python):
import sys, math
from pprint import pprint
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = []
for i in range(N):
	a = []
	for j in range(ri()):
		x, y = rl()
		a.append((x-1, y))
	A.append(a)

def check(A, b):
	for i, a in enumerate(A):
		for x, y in a:
			if b[i] == 1:
				if b[x] != y:
					return False
	return True

import itertools
ans = 0
for b in itertools.product([0,1], repeat=N):
	if check(A, b):
		ans = max(ans, sum(b))
print(ans)

Solution (Python):
from itertools import product
n = int(input())
tells = [[] for _ in range(n)]
for i in range(n):
    for j in range(int(input())):
        tells[i].append(list(map(int, input().split())))
for i in product(['1', '0'], repeat=n):
    a = list(map(int, i))
    flag = True
    for j in range(n):
        for k in tells[j]:
            if a[j] and a[k[0]-1] != k[1]:
                flag = False
                break
    if flag:
        print(sum(a))
        break

Solution (Python):
N = int(input())
li = []
for i in range(N):
    A = int(input())
    li.append([[int(j) for j in input().split()] for k in range(A)])

ans = 0

for i in range(1 << N):
    consistent = True  
    honests = 0  
    for j in range(N):  
        if not consistent:
            break
        claims = li[j]  
        if (i >> j) & 1 == 1:
            
            honests += 1
            for claim in claims:
                if (i >> (claim[0] - 1)) & 1 != claim[1]:
                    
                    consistent = False
                    break
    if consistent:
        ans = max(ans, honests)

print(ans)

Solution (Python):
n=int(input())
X=[]*n

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

ans=0
for i in range(2**n):
	cnt=0
	for j in range(n):
		if (i>>j)&1:
			for k,l in X[j]:
				if not ((i>>(k-1))&1)==l:
					cnt=1
					break

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

print(ans)

Solution (Python):
n=int(input())
X=[]*n
A=[]*n

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

ans=0
for i in range(2**n):
	cnt=0
	for j in range(n):
		if (i>>j)&1:
			for k,l in X[j]:
				if not ((i>>(k-1))&1)==l:
					cnt=1
					break

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

print(ans)

Solution (Python):
n=int(input())
X=[]*n
A=[]*n

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

ans=0
for i in range(2**n):
	cnt=0
	for j in range(n):
		if (i>>j)&1:
			for k,l in X[j]:
				if not ((i>>(k-1))&1)==l:
					cnt=1

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

print(ans)

Solution (Python):
n = int(input())
honest = []
unkind = []
for _ in range(n):
    a = int(input())
    ho = []
    un = []
    for _ in range(a):
        x, y = map(int, input().split())
        if y == 1:
            ho.append(x-1)
        else:
            un.append(x-1)
    honest.append(ho)
    unkind.append(un)


ans = []
for i in range(2 ** n):
    person = []
    for j in range(n):
        person.append(i % 2)
        i //= 2

    flag = False

    
    for j in range(n):
        if person[j] == 1:
            for k in honest[j]:
                if person[k] == 0:
                    flag = True
                    break
            if flag:
                break
    if flag:
        continue
    
    
    for j in range(n):
        if person[j] == 1:
            for k in unkind[j]:
                if person[k] == 1:
                    flag = True
                    break
            if flag:
                break
    if flag:
        continue

    ans.append(sum(person))
print(max(ans))

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

h = []

for i in range(N):
  m = int(input())
  g = []
  for j in range(m):
    a, b = map(int, input().split())
    g.append((a-1, b))
  h.append(g)
  
def judge(a, b):
  for i in range(N):
    if (b >> i) & 1:
      for j in a[i]:
        if ((b >> j[0]) & 1) != j[1]:
          return False
  return True
  
x = 0b0
ans = -1
for i in range(2**N):
  if judge(h, x):
    tmp = 0
    for i in range(N):
      if (x >> i) & 1:
        tmp += 1
    if tmp > ans:
      ans = tmp
  x += 1

print(ans)

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

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

result = 0
for i in range(1, 2 ** N): 
    consistent = True
    for j in range(N):
        if (i >> j) & 1 == 0: 
            continue
        for x, y in evidences[j]: 
            if (i >> x) & 1 != y: 
                consistent = False
    if consistent:
        result = max(result, bin(i).count('1'))
print(result)

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


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

max_honest = 0  


for i in range(1 << n):
    ishonest = [False] * n
    for j in range(n):
        if ((i >> j) & 1) == 1:
            ishonest[j] = True
    

    ok = True

    for k in range(n):
        
        if ishonest[k] == False:
            continue
        
        
        for l in range(len(testimony[k])):
            person = testimony[k][l][0]
            true_false = testimony[k][l][1]
            
            
            
            if (ishonest[person] == True) and (true_false == 0) or (ishonest[person] == False) and (true_false == 1):
                ok = False

        if ok == False:
            break
        
    if ok == True:

        if ishonest.count(True) > max_honest:
            max_honest = ishonest.count(True)

print(max_honest)

Solution (Python):
n = int(input())
a = [0 for _ in range(n)]
xyies = [[] for _ in range(n)]
for i in range(n):
    aa = int(input())
    a[i] += aa
    xyies[i] = [list(map(int,input().split())) for _ in range(aa)]
ans = 0
for i in range(2**n):
    H_or_U = [0 for _ in range(n)]
    for j in range(n):
        if (i >> j) & 1:
            H_or_U[j] += 1
    syougens = []
    for j in range(n):
        if H_or_U[j]:
            syougen = xyies[j]
            for k in range(a[j]):
                if H_or_U[syougen[k][0]-1] == syougen[k][1]:
                    syougens.append(True)
                else:
                    syougens.append(False)
    if all(syougens):
        ans = max(ans,sum(H_or_U))
print(ans)

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

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


best = 0  









for honest in range(1 << n):  
    for i in range(n):  
        if not (honest >> i) & 1:  
            continue 
        for j, t in testimony[i]:  
            if (honest >> j) & 1 != t:  
                break 
        else:
            continue
        break
    else:  
        best = max(best, bin(honest).count('1'))

print(best)

Solution (Python):
N=int(input())
L=[[] for i in range(N)]
for i in range(N):
  M=int(input())
  L[i]=[list(map(int,input().split())) for j in range(M)]


L_2=[[i,None] for i in range(N)]
L_3=[0 for i in range(N)]
ans=0
for k in range(2**N):
	L_3=[0 for i in range(N)]
	Y_N=True
	count=0
	for a in range(N):
		if ((k >> a) & 1):  
			L_3[a]=1
	for a in range(N):  
		if ((k >> a) & 1):  
			count += 1
			for b in range(len(L[a])):
				if L_3[a] == 0: 
					Y_N=False 
				person = L[a][b][0]-1
				if L_3[person]==1-L[a][b][1]: 
					Y_N=False 
				L_3[person]=L[a][b][1] 
				
	
	if Y_N:
		ans = max(ans, count)
print(ans)

Solution (Python):
n = int(input())
testimony = []  
for i in range(n):
    t = []
    for _ in range(int(input())):
        x, y = map(int, input().split())
        t.append((x - 1, y))
    testimony.append(t)
best = 0  
for honest in range(1 << n):  
    for i in range(n):  
        if not (honest >> i) & 1:  
            continue
        for j, t in testimony[i]:  
            if (honest >> j) & 1 != t:  
                break
        else:
            continue
        break
    else:  
        best = max(best, bin(honest).count('1'))
print(best)

Solution (Python):
n = int(input())
testimony = []  
for i in range(n):
    t = []
    for _ in range(int(input())):
        x, y = map(int, input().split())
        t.append((x - 1, y))
    testimony.append(t)
best = 0  
for honest in range(1 << n):  
    tmp = 0
    for i in range(n):  
        if not (honest >> i) & 1:  
            continue
        tmp += 1
        for j, t in testimony[i]:  
            if (honest >> j) & 1 ^ t:  
                break
        else:
            continue
        break
    else:  
        best = max(best, tmp)
print(best)

Solution (Python):
n = int(input())
testimony = []  
for i in range(n):
    t = []
    for _ in range(int(input())):
        x, y = map(int, input().split())
        t.append((x - 1, y))
    testimony.append(t)
best = 0  
for honest in range(1 << n):  
    for i in range(n):  
        if not (honest >> i) & 1:  
            continue
        for j, t in testimony[i]:  
            if (honest >> j) & 1 ^ t:  
                break
        else:
            continue
        break
    else:  
        best = max(best, bin(honest).count('1'))
print(best)

Solution (Python):
def spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_)


n = int(input())
testimony = [[] for _ in range(n)]  
for i in range(n):
    for _ in range(int(input())):
        x, y = spline()
        x -= 1
        testimony[i].append((x, y))
best = 0  
for honest in range(1 << n):  
    for i in range(n):  
        if not (honest >> i) & 1:  
            continue
        for j, t in testimony[i]:  
            if (honest >> j) & 1 ^ t:  
                break
        else:
            continue
        break
    else:  
        best = max(best, bin(honest).count('1'))
print(best)

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


l = [[-1] * 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())
        
        l[i][x-1] = y

ans = 0

for i in range(2**n):
    Val = True
    for j in range(n):
        if (i >> j & 1) == 1:   
            for k in range(n):
                if l[j][k] == -1: continue
                if (i >> k & 1) != l[j][k]: Val = False
    if Val:
        res = 0
        num = i
        while num > 0:
            res += num % 2
            num //= 2
            ans = max(ans, res)

print(ans)

Solution (Python):
n=int(input())
rel=[{'good':set(),'bad':set()} for _ in range(n)]
for i in range(n):
  a=int(input())
  for j in range(a):
    x,y=map(int,input().split())
    if y==1:
      rel[i]['good'].add(x-1)
    else:
      rel[i]['bad'].add(x-1)
ans=0
for i in range(2**n):
  true=set()
  c=0
  for j in range(n):
    if (i>>j) & 1==1:
      true.add(j)
  for j in true:
    if len(rel[j]['bad']&true)>0 or not rel[j]['good']<=true:
      break
    c+=1
  if c==len(true):
    ans=max(ans,c)
print(ans)

Solution (Python):
N = int(input())
xy = [0] * N
ans = 0
for i in range(N):
    a = int(input())
    xy[i] = [list(map(int, input().split())) for _ in range(a)]
is_honest = [False for i in range(N)]
for i in range(2 ** (N)):
    for j in range(N):
        if i >> j & 1:
            is_honest[j] = True
        else:
            is_honest[j] = False
    broke = False
    for j in range(N):
        if is_honest[j]:
            for k in xy[j]:
                if is_honest[k[0]-1] != bool(k[1]):
                    broke = True
                    break
            if broke:
                break
    if broke == False:
        ans = max(ans, is_honest.count(True))
print(ans)

Solution (Python):
n = int(input())
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)

Solution (Python):










N = int(input())
ARR = []
for i in range(N):
    A = int(input())
    X = []
    Y = []
    for j in range(A):
        x, t = map(int, input().split())
        if t == 1:
            X.append(x)
        else:
            Y.append(x)
    ARR.append([X,Y])

def calculate(n,arr):
    result = []
    for i in range(2**n):
        cases = []
        goods = set()
        suspicious = set()
        for j in range(n):
            cases.append(i >> j & 1)
            if i >> j & 1:
                goods.add(j)
            else:
                suspicious.add(j)
        res = judge(arr,cases,goods,suspicious)
        if res:
            result.append(len(goods))

    if len(result) == 0:
        print(0)
    else:
        print(max(result))

def judge(arr,cases,goods,suspicious):
        tempGoods = set()
        tempSuspicious = set()

        if sum(cases) == 0:
            return False

        for index,ca in enumerate(cases):
            if ca == 1:
                for g in arr[index][0]:
                    tempGoods.add(g - 1)
                for s in arr[index][1]:
                    tempSuspicious.add(s - 1)

        if len(list(tempGoods & suspicious)) > 0:
            return False

        if len(list(tempSuspicious & goods)) > 0:
            return False

        return True


calculate(N,ARR)

Solution (Python):
def abc147_c():
  
  n = int(input())
  query = []
  for _ in range(n):
    a = int(input())
    q = [tuple(map(int, input().split())) for _ in range(a)]
    query.append(q)

  
  ans = 0
  for mask in range(1, 2**n):
    
    honest = [False] * n
    for i in range(n):
      if (mask >> i) & 1: honest[i] = True

    
    succ = True
    for i, q in enumerate(query):
      if (mask >> i) & 1:
        for x, y in q:
          if y == 1 and (not honest[x-1]):
            succ = False
            break
          elif y == 0 and honest[x-1]:
            succ = False
            break
      if not succ: break

    
    if succ:
      ans = max(ans, honest.count(True))
  print(ans)

abc147_c()

Solution (Python):
from itertools import product

N = int(input())
B = 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])
ans = 0
for b in B:
    for l in L:
        if b[l[2]-1] == 1 and l[1] != b[l[0]-1]:
            break
    else:
        if ans < b.count(1):
            ans = b.count(1)
print(ans)

Solution (Python):
n=int(input())
xy=[]
for i in range(n):
  a=int(input())
  xy.append([list(map(int,input().split())) for j in range(a)])
 
ans=0
for i in range(2**n):
  honest=[]
  for j in range(n):
    if (i>>j)&1:
      honest.append(1)
    else:
      honest.append(0)
  p=0
  for j,k in enumerate(honest):
    if k==1:
      r=0
      for l in xy[j]:
        if honest[l[0]-1]!=l[1]:
          r=1
          break    
      if r==0:
        p=p+1
  if p==sum(honest) and p>ans:
    ans=p
print(ans)

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

ans=[]
for i in range(2**n):
  honest=[]
  for j in range(n):
    if (i>>j)&1:
      honest.append(1)
    else:
      honest.append(0)
  p=0
  q=0
  for j,k in enumerate(honest):
    if k==1:
      q=q+1
      r=0
      for l in xy[j]:
        if honest[l[0]-1]==l[1]:
          r=r+1
      if r==len(xy[j]):
        p=p+1
  if p==q:
    ans.append(p)
print(max(ans))

Solution (Python):
n=int(input())
xy=[]
ans=0
for i in range(n):
  a=int(input())
  xy.append([list(map(int,input().split())) for _ in range(a)])
for i in range(2**n):
  cnt=[]
  k=0
  for j in range(n):
    if (i >> j) & 1:
      cnt.append(1)
    else:
      cnt.append(0)
  for p,j in enumerate(cnt):
    e=0
    if j==0:
      for o in xy[p]:
        if cnt[o[0]-1]==o[1]:
          break
        e+=1
      if e==len(xy[p]):
        k+=1
      else:
        k=0
        break
  if ans < k:
    ans=k
print(ans)

Solution (Python):
from collections import deque












N = int(input())
ARR = []

for i in range(N):
    A = int(input())
    X = []
    Y = []
    for j in range(A):
        x, t = map(int, input().split())
        if t == 1:
            X.append(x)
        else:
            Y.append(x)
    ARR.append([X,Y])

def calculate(n, arr):
    result = []
    for i in range(2 ** n):
        q = deque()
        possibilities = []
        teacherGoods = set()
        teacherBads = set()
        for j in range(n):
            identity = (i >> j & 1) == 1
            if identity:
                q.append(j)
                possibilities.append(identity)
                teacherGoods.add(j + 1)
            else:
                teacherBads.add(j + 1)
            
            
        res = judge(q, arr, teacherGoods, teacherBads)
        if res == True:
            result.append(sum(possibilities))

    print(max(result))


def judge(possibilities, arr, teacherGoods, teacherBads):
    goodMans = set()
    badMans = set()
    trueStatus = {}
    result = True
    while len(possibilities) > 0:

        trueIndex = possibilities.popleft()
        if trueStatus.get(trueIndex) == True:
            continue
        trueStatus.__setitem__(trueIndex, True)
        for g in arr[trueIndex][0]:
            goodMans.add(g)
            possibilities.append(g - 1)
        for b in arr[trueIndex][1]:
            badMans.add(b)

        if len(list(goodMans & teacherBads)) > 0:
            result = False
            break

        if len(list(badMans & teacherGoods)) > 0:
            result = False
            break
    return result


calculate(N, ARR)