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 itertools

n = int(input())

a = []

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

for p in itertools.product([0,1], repeat=n):
    katei_list = list(p)
    mujun = False
    for i in range(n):
        if katei_list[i] == 1:
            for shogen in a[i]:
                if katei_list[shogen[0]] != shogen[1]:
                    mujun = True
                    break
            if mujun:
                break
        if mujun:
            break
    if not mujun and sum(p) > ans:
        ans = sum(p)

print(ans)

Solution (Python):
n = int(input())
g = [[0,0] for _ in range(n)]
for i in range(n):
  a = int(input())
  for _ in range(a):
    x,y = map(int,input().split())
    g[i][y] |= 1 << (x-1)
ans = 0
for num in range(1<<n):
  p = [g[j] for j in range(n) if num&(1<<j)]
  fl = 0
  if all(num & y == y and not num & x for x,y in p):
    if ans < len(p): ans = len(p)
print(ans)

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

for i in range(2**N):
    people=[]
    for k in range(N):
        people.append(i%2)
        i//=2

    flag=True    
    for n in range(N):
        for t in say[n]:
            if people[n]!=0 and people[t[0]-1]!=t[1]:
                flag=False    
    if flag and sum(people)>ans:
        ans=sum(people)
print(ans)

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

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

for i in range(n):
    for C in itertools.combinations(range(n), n-i):
        for c in C:
            for x, y in tes[c]:
                if (y == 0 and x in C) or (y == 1 and x not in C):
                    break
            else:
                continue
            break
        else:
            print(n-i)
            exit()
print(0)

Solution (Python):
N = int(input())
A = []
lst = [list(format(i, '0%db' % N)) for i in range(2**N)]
X = [[] for i in range(N)]
Y = [[] for i in range(N)]

for i in range(N):
    tmp_A = int(input())
    A.append(tmp_A)
    for j in range(tmp_A):
        tmp_x,tmp_y = input().split()
        X[i].append(int(tmp_x)-1)
        Y[i].append(tmp_y)

ans = -1

for i in range(2**N):
    flag = 1
    for j in range(N):
        if lst[i][j] == "1":
            for k in range(A[j]):
               if lst[i][X[j][k]] != Y[j][k]:
                   flag = 0
    if flag:
        tmp = 0
        for j in lst[i]:
            if j == "1":
               tmp += 1
        if tmp > ans:
            ans = tmp

print(ans)

Solution (Python):
N = int(input())
xy = [0]*N
A = []
ans = 0
cnt = 0
hatan = 0
for i in range(N):
    A.append(int(input()))
    xy[i] = [list(map(int,input().split())) for i in range(A[i])]
for i in range(2**N):
    cnt = 0
    hatan = 0
    bits = "0" + str(N) + "b"
    Honest_line = str(format(i,bits))
    for people in range(N):
        if(Honest_line[people] == "1"):
            cnt += 1
            for syougen in range(A[people]):
                if(int(Honest_line[xy[people][syougen][0]-1]) != xy[people][syougen][1]):
                    hatan = 1
    if(hatan == 0):
        ans = max(ans,cnt)
print(ans)

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

ans = 0
for i in range(1, 2 ** N):
    is_ok = True
    for j in range(N):
        if (i >> j) & 1 == 1:
            for x, y in msg[j]:
                if (i >> x) & 1 != y:
                    is_ok = False
                    break
    if is_ok:
        ans = max(ans, bin(i)[2:].count('1'))
print(ans)

Solution (Python):
import itertools


def judge(bits):
    for n in range(N):
        if not bits[n]:
            continue
        for s in X[n]:
            x, y = s
            
            if (y == 1 and (not bits[x - 1])):
                return 0
            
            if (y == 0 and bits[x - 1]):
                return 0
    return sum(bits)


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

ans = []
for bits in itertools.product([False, True], repeat=N):
    ans.append(judge(bits))

print(max(ans))

Solution (Python):
from itertools import product

n = int(input())
a = []
xy = []

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

    xy.append(new)

ans = 0
for pat in product([1, 0], repeat=n):
    bl = True
    for i, e in enumerate(pat):
        if e:
            for x, y in xy[i]:
                if pat[x] != y:
                    bl = False

    if bl:
        ans = max(ans, sum(pat))

print(ans)

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


class Human:

    def __init__(self, statements):
        self.statements = statements

    def is_honest(self, honest_list):
        for x, y in self.statements:
            if y:
                if x not in honest_list:
                    return False
            else:
                if x in honest_list:
                    return False
        return True


class Humans:

    def __init__(self):
        self.humans = [None]

    def add(self, human: Human):
        self.humans.append(human)

    def is_all_honest(self, honest_list):
        for i in honest_list:
            if not self.humans[i].is_honest(honest_list):
                return False
        return True


def main():
    n = int(input())
    humans = Humans()
    for _ in range(n):
        a = int(input())
        xy = [tuple(map(int, input().split())) for _ in range(a)]
        humans.add(Human(xy))
    max_honest = 0
    for bit in range(2**n):
        honest_list = []
        for i in range(n):
            if (bit >> i) & 1:
                honest_list.append(i+1)  
        if humans.is_all_honest(honest_list):
            max_honest = max(max_honest, len(honest_list))
    print(max_honest)


if __name__ == "__main__":
    main()

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

def decode(i):
    ret = []
    for _ in range(n):
        ret.append(i & 1)
        i >>= 1
    return ret

ans = 0
for k in range(1 << n):
    l = decode(k)
    coh = True
    for i, w in enumerate(t):
        if l[i]:
            for x, y in w:
                if l[x-1] != y:
                    coh = False
    if coh:
        ans = max(ans, sum(l))
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = [0 for _ in range(N)]
xy = [0 for _ in range(N)]
for i in range(N) :
    A[i] = int(input())
    xy[i] = [0 for _ in range(A[i])]
    for j in range(A[i]) :
        x, y = map(int, input().split())
        xy[i][j] = (x, y)

ans = 0
for i in range(2**N):
    pat = str("{:0>{}b}".format(i, N))
    flag = True
    for j in range(N):
        if pat[j] == "1":
            for t in range(A[j]) :
                man = xy[j][t][0] - 1
                tru = xy[j][t][1]
                if pat[man] != str(tru) :
                    flag = False
    if flag == True :
        ans = max(ans, pat.count("1"))

print(ans)

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

res = 0
for k in range(1 << N):
    bits = [(k >> i) & 1 for i in range(N)]
    flag = True
    for i in range(N):
        if (k >> i) & 1 == 0:
            continue
        for x, y in XY[i]:
            if bits[x - 1] == y:
                continue
            flag = False
    if flag:
        res = max(res, sum(bits))
print(res)

Solution (Python):
n=int(input())
a=[]
for i in range(n):
    x=int(input())
    aa=[[int(i) for i in input().split()] for i in range(x)]
    a.append(aa)


ans=0
for i in range(2**n):
    status=[True]*n
    for j in range(n):
        if ((i>>j)&1):
            status[j]=False
    check=[None]*n
    flag=True
    for i in range(n):
        if status[i]==True:
            for x,y in a[i]:
                if y==1 and status[x-1]==True and (check[x-1]==None or check[x-1]==True):
                    check[x-1]=True
                elif y==1 and (check[x-1]==False or status[x-1]==False):
                    flag=False
                elif y==0 and status[x-1]==False and (check[x-1]==None or check[x-1]==False):
                    check[x-1]=False
                elif y==0 and (check[x-1]==True or status[x-1]==True):
                    flag=False
    if flag:
        
        cnt=status.count(True)
        ans=max(ans,cnt)
print(ans)

Solution (Python):
from itertools import combinations

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


for i in range(0, n+1):
    for liers in combinations(list(range(0,n)), i):
        who_ishonest = [1] * n
        for lier in liers:
            who_ishonest[lier] = 0

        for j in range(n):
            if j in liers:
                continue
            
            for testimony in testimonies[j]:
                if who_ishonest[testimony[0]-1] != testimony[1]:
                    break
            else:
                continue
            break
        else:
            print(n-i)
            break
    else:
        continue
    break

Solution (Python):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    xys = []
    for _ in range(N):
        A = int(stdin.readline().rstrip())
        xys.append([tuple(int(x) for x in stdin.readline().rstrip().split()) for _ in range(A)])
    max_ = int('1' * N, 2)
    result = 0
    for i in range(max_ + 1):
        sb = bin(i)[2:]
        sb = '0' * (N - len(sb)) + sb
        for idx, c in enumerate(sb):
            if c == '0':
                continue
            is_break = False
            tmp = [None] * N
            for x, y in xys[idx]:
                if (y == 0 and sb[x - 1] == '1') or (y == 1 and sb[x - 1] == '0'):
                    is_break = True
                    break
                if tmp[x - 1] == None:
                    tmp[x - 1] = y
                elif tmp[x - 1] != y:
                    is_break = True
                    break
            if is_break:
                break
        else:
            result = max(result, sb.count('1'))
    print(result)


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=[]
h=[]
for _ in range(n):
    x=int(input())
    h.append([tuple(map(int,input().split())) for _ in range(x)])
    a.append(x)
ans=0
for i in range(2**n):
    f=1
    for j in range(n):
        if (i>>j)&1:
            for k in range(a[j]):
                x,y=h[j][k]
                if (i>>(x-1))&1!=y:
                    f=0

    if f:
        c=0
        for j in range(n):
            c+=(i>>j)&1

        ans=max(ans,c)
print(ans)

Solution (Python):
n = int(input())
a = ["0","1"]
ab = [0] * n
x = [[0] * n for i in range(n)]
y = [[0] * n for i in range(n)]
for i in range(n):
	ab[i] = int(input())
	for j in range(ab[i]):
		x[i][j], y[i][j] = map(int, input().split())
		x[i][j] -= 1

def check(hit):
	for i in range(n):
		if hit[i] == "0":
			continue
		for j in range(ab[i]):
			if y[i][j] == 1 and hit[x[i][j]] == "0":
				return False
			if y[i][j] == 0 and hit[x[i][j]] == "1":
				return False
	return True

ans = []
def dfs(i, s):
	for j in a:
		if len(s) == n:
			
			if check(s):
				ans.append(s.count("1"))
			return
		else:
			dfs(i+1,s+j)
dfs(0,"")

print (max(ans))

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

Axy={}

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

ans=0
for i in range(2**N):
    bi=list(format(i,'b').zfill(N))
    flag=True
    for j in range(N):
        if bi[j]=='0': continue
        if bi[j]=='1':
            for v in Axy[j]:
                if int(bi[v[0]-1])!=v[1]:
                    flag=False
    if flag: ans=max(ans,bi.count('1'))
print(ans)

Solution (Python):
from itertools import combinations
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    person = list(range(1, N + 1))
    xy = []
    for i in range(N):
        A = int(stdin.readline().rstrip())
        xy.append([tuple(int(x) for x in stdin.readline().rstrip().split()) for _ in range(A)])
    for i in range(N, 0, -1):
        for comb in combinations(person, i):
            result = [None] * N
            is_fail = False
            for num in comb:
                for x, y in xy[num - 1]:
                    if y == 0:
                        if x in comb:
                            is_fail = True
                            break
                    else:
                        if x not in comb:
                            is_fail = True
                            break

                    if result[x - 1] is None:
                        result[x - 1] = y
                    elif result[x - 1] == y:
                        pass
                    else:
                        is_fail = True
                        break
                if is_fail:
                    break
            else:
                print(i)
                return
    print(0)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


import itertools

N = int(readline())

syougen = []
for i in range(N):
    A = int(readline())
    hoge = []
    for i in range(A):
        s = tuple(map(int,readline().split()))
        hoge.append(s)
    syougen.append(hoge)
    
ans = 0
for i in list(itertools.product([0,1],repeat = N)):
    test = True
    for j in range(N):
        if i[j] == 0:
            pass
        else:
            for k,m in syougen[j]:
                if i[k-1] == int(m):
                    continue
                else:
                    test = False
    if test:ans = sum(i)
print(ans)

Solution (Python):
n = int(input())
table = []
for _ in range(n):
    a = int(input())
    tmp = []
    for _ in range(a):
        person,assessment = map(int,input().split())
        person -=  1
        tmp.append([person,assessment])
    table.append(tmp)

def check(i,n):
    
    for j in range(n):
        if i >> j & 1:
            for person,assessment in table[j]:
                if (i >> person)&1 !=  assessment:
                    return False
    
    return True

ans = 0
for i in range(2**n-1,-1,-1):
    if check(i,n):
        ans = max(ans,bin(i).count("1"))
        

print(ans)

Solution (Python):
n = int(input())
table = []
for _ in range(n):
    a = int(input())
    tmp = []
    for _ in range(a):
        person,assessment = map(int,input().split())
        person -=  1
        tmp.append([person,assessment])
    table.append(tmp)

def check(i,n):
    
    for j in range(n):
        if i >> j & 1:
            for person,assessment in table[j]:
                if (i >> person)&1 !=  assessment:
                    return False
    
    return True

ans = 0
for i in range(2**n):
    if check(i,n):
        ans = max(ans,bin(i).count("1"))

print(ans)

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

times = n
table = []
for _ in range(times):
    a = int(input())
    temp = []
    for _ in range(a):
        x , y = map(int,input().split())
        temp.append([x-1,y])
    table.append(temp)  

    
def check(i,n):
    flg = True
    for j in range(n):
        if i>>j & 1:
            for x,y in table[j]:
                if (i>>x)&1 != y:
                    flg = False
                    
                    return flg
    
    return flg


ans = 0
for i in range(2**n):   
    if check(i,n):
        ans = max(bin(i).count("1"),ans)

print(ans)

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

times = n
table = []
for _ in range(times):
    a = int(input())
    temp = []
    for _ in range(a):
        x , y = map(int,input().split())
        temp.append([x-1,y])
    table.append(temp)  
    
def check(i,n):
    flg = True
    for j in range(n):
        if i>>j & 1:
            for x,y in table[j]:
                if (i>>x)%2 != y:
                    flg = False
                    
                    return flg
    
    return flg


ans = 0
for i in range(2**n):   
    if check(i,n):
        ans = max(bin(i).count("1"),ans)

print(ans)

Solution (Python):
N=int(input())
A=[[[],[]] for _ in range(N)]
for i in range(N):
  a=int(input())
  for j in range(a):
    n,p = map(int, input().split())
    A[i][p].append(n)
def test(i):
  T=[]
  F=[]
  TT=set()
  TF=set()
  for n in range(N):
    if 1 & i>>n:
      T+=A[n][1]
      F+=A[n][0]
      TT.add(n+1)
    else: TF.add(n+1)
  if set(T)<=TT and set(F)<=TF: return len(TT)
  else: return -1
        
s=0
for i in range(2**N):
  s=max(s,test(i))
print(s)

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))

ans = 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
            break

      if not consistent:
         break

   if consistent:
      ans = max(ans, bin(i)[2:].count('1'))

print(ans)

Solution (Python):
def f(i):
    global m
    if i == n:
        for j in range(n):
            for k in range(n):
                if G[j][k] == 1:
                    if s[j] == 1 and s[k] == 0:
                        return
                elif G[j][k] == 0:
                    if s[j] == 1 and s[k] == 1:
                        return
        if m < sum(s):
            m = sum(s)
        return
    f(i + 1)
    s[i] = 1
    f(i + 1)
    s[i] = 0

n = int(input())
G = [[-1 for _ in range(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
s = [0] * n
m = 0
f(0)
print(m)

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

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

def count(x,check):
    l = []
    for j in range(n):
        if ((x >> j) & 1):
            l.append(1)
        else:
            l.append(0)
    chec = True
    for i in range(n):
        if l[i] == 1:
            for k in check[i]:
                if k[1] == 1 and l[k[0]-1] == 0:
                    chec = False
                elif k[1] == 0 and l[k[0]-1] == 1:
                    chec = False
    if chec:
        return l.count(1)
    else:
        return 0

ans = 0
for i in range(2**n):
    ans = max(ans,count(i,check))
print(ans)

Solution (Python):
n=int(input())
a=[0]*n
x=[[0]*n for i in range(n)]
y=[[0]*n for i in range(n)]
for i in range(n):
  a[i]=int(input())
  for j in range(a[i]):
    u,v=map(int,input().split())
    x[i][j]=u-1
    y[i][j]=v
ans=0
for k in range(2**n):
  arr=[0]*n
  cnt=0
  flag=True
  for i in range(n):
    if k>>i&1:
      arr[i]=1
      cnt+=1
  for i in range(n):
    for j in range(a[i]):
      if arr[i]==1:
        if (y[i][j]==1 and arr[x[i][j]]==0) or (y[i][j]==0 and arr[x[i][j]]==1):
          flag=False
  if flag:
    ans=max(ans,cnt)
print(ans)

Solution (Python):
N=int(input())
testimony=[[-1]*N for i in range(N)]
count=0
for i in range(N):
    A=int(input())
    for j in range(A):
        x,y=map(int,input().split())
        testimony[i][x-1]=y
for i in range(1<<N):
    honest=[0]*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 testimony[j][k]==-1:
                    continue
                if testimony[j][k]!=honest[k]:
                    flag=False
    if flag:
        count=max(count,honest.count(1))
print(count)

Solution (Python):
n=int(input())
L=[['nd']*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
r=0
for bit in range(1<<n):
    flag=0
    for k in range(n):
        if bit&(1<<k):
            for l in range(n):
                if l!=k:
                    if L[k][l]==1:
                        if bit&(1<<l):
                            pass
                        else:
                            flag=1
                            break
                    elif L[k][l]==0:
                        if bit&(1<<l):
                            flag=1
                            break
                        else:
                            pass
            
        if flag==1:
            break
        if k==n-1:
            r=max(r,str(bin(bit)).count('1'))
print(r)

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

def judge(bit):
    for i in range(N):
        if bit&(1<<i)==False: 
            continue
        for j in range(A[i]): 
            tmpx=pairs[i][j][0]
            tmpy=pairs[i][j][1]
            if tmpy==1  and (bit&(1<<tmpx)==False):
                return False
            if tmpy==0 and (bit&(1<<tmpx)):
                return False
    return True

ans=0
for bit in range((1<<N)):
    if judge(bit):
        count=0
        for i in range(N):
            if (bit&(1<<i)):
               count+=1
        ans=max(ans,count)

print(ans)

Solution (Python):

N=int(input())
ans=0
A=[[] for _ in range(N)]
for i in range(N):
    a=int(input())
    for j in range(a):
        A[i].append(tuple(int(i) for i in input().split()))
for i in range(2**N):
    flag=True
    tmp=0
    S=bin(i)[2:][::-1]
    TF=list(S)+['0' for _ in range(N-len(S))]
    
    for j,s in enumerate(list(S)):
        if s=='1':
            tmp+=1
            for x,y in A[j]:
                if TF[x-1]!=str(y):
                    
                    flag=False
    if flag:
        ans=max(ans,tmp)
print(ans)

Solution (Python):
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  
def grid(n): return [s_list() for _ in range(n)]


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

    
    
    

    ans = 0
    for i in range(2**n):   
        flag = False
        count = 0
        for j in range(n):                

            if i >> j & 1 == 1:                         
                for k in range(len(xy[j])):
                    if (i >> xy[j][k][0]-1 & 1) != xy[j][k][1]:        
                        flag = True
                        break

                if flag == True:
                    break

                else:
                    count += 1


        if flag == False:
            ans = max(ans, count)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

N = int(input())
testimony = [[0] * N for i in range(N)]
A = []

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

testimony = np.array(testimony)

A = np.array(A)
ans = 0

for i in range(2 ** N):
    honesty = [-1] * N
    h = 0
    for j in range(N):
        if (i >> j) & 1:
            honesty[j] = 1
            h += 1
    honesty = np.array(honesty)
    B = np.dot(testimony,honesty) - A
    if any(honesty[j] == 1 and B[j] != 0 for j in range(N)):
        continue

    ans = max(ans, h)

print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = []
L = []

for i in range(N):
    a = INT()
    A.append(a)
    l = []
    for j in range(a):
        l.append(LIST())
    L.append(l)

from itertools import product
num = N
bits = product([0, 1], repeat=N)

ans = 0

for x in bits:
    flag = 0
    for j in range(N):
        if x[j] == 1:
            for a, b in L[j]:
                if b != x[a-1]:
                    flag = 1
                    break
        if flag == 1:
            break
    else:
        tmp = sum(x)
        if ans <= tmp:
            ans = tmp
print(ans)



exit()

for l in L:
    info = [False] * 2 ** num
    print(info)
    for y in l:
        a, b = y
        print(a, b)
        for x in bits:
            
            if x[a-1] == b:
                info[a-1] = True
                print(info)
        
    print(info)

Solution (Python):
n = int(input())
shogen = []
for i in range(n):
    shogen.append({})
for i in range(n):
    for k in range(int(input())):
      x,y = map(int,input().split())
      shogen[i][x] = y 
MaxHonest = 0
for i in range(2**n):
    num = format(i,'b').zfill(n)
    lst = list(map(int,list(num)))
    flag = True
    for k in range(n):
        if lst[k] == 1:
            for l in shogen[k]:
                if shogen[k][l] != lst[l-1]:
                    flag = False
    if flag:
        MaxHonest = max(MaxHonest,sum(lst))
print(MaxHonest)

Solution (Python):
n=int(input())
a=[[] for i in range(n)]
for i in range(n):
    b=int(input())
    for j in range(b):
        c,d= map(int, input().split())
        a[i].append((c-1,d))

ans=0
for i in range(2**n):
    flag=True
    count=0
    for j in range(n):
        if (i>>j)&1:
            
            count+=1
            for k in range(len(a[j])):
                if a[j][k][1]==1:
                    if (i>>(a[j][k][0]))&1==1:
                        continue
                    else:
                        flag=False
                        break

                if a[j][k][1]==0:
                    if (i>>(a[j][k][0]))&1!=1:
                        continue
                    else:
                        flag=False
                        break
    if flag:
        ans=max(ans,count)
print(ans)

Solution (Python):
def main():
    N = int(input())
    edge = [[-1]*N for i in range(N)]
    for i in range(N):
        A = int(input())
        for a in range(A):
            x, y = (int(i) for i in input().split())
            edge[i][x-1] = y
    
    ans = 0
    for bit in range(1 << N):
        cur = [0] * N
        flag = True  
        for i in range(N):
            if bit & (1 << i):
                cur[i] = 1
        for i in range(N):
            for j in range(N):
                if edge[i][j] == -1:
                    continue
                elif edge[i][j] == 1 and cur[i] and not(cur[j]):
                    flag = False
                elif edge[i][j] == 0 and cur[i] and cur[j]:
                    flag = False
        if flag:
            ans = max(ans, sum(cur))
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
testimony=[[-1]*N for i in range(N)]
count=0
for i in range(N):
    A=int(input())
    for j in range(A):
        x,y=map(int,input().split())
        testimony[i][x-1]=y
for i in range(1<<N):
    honest=[0]*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 testimony[j][k]==-1:
                    continue
                if testimony[j][k]!=honest[k]:
                    flag=False
    if flag:
        count=max(count,honest.count(1))
print(count)