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):
def resolve():
    N = int(input())
    XY = []
    for i in range(N):
        A = int(input())
        xy = [list(map(int, input().split())) for _ in range(A)]
        XY.append(xy)
    
    ans = 0
    for _bits in range(1<<N):
        bits = list(map(int, bin(_bits)[2:].zfill(N)))
        unmatch = False
        for i in range(N):
            if bits[i] == 0:
                continue
            for x, y in XY[i]:
                if bits[x-1] != y:
                    unmatch = True
                    break
            if unmatch:
                break
        else:
            ans = max(ans, bin(_bits).count('1'))
    print(ans)



if '__main__' == __name__:
    resolve()

Solution (Python):
n = int(input())
num_of_sug = []
sug = []
for i in range(n):
    m = int(input())
    num_of_sug += [m]
    sug += [[tuple(map(int, input().split())) for _ in range(m)]]

ans = 0

for i in range(2 ** n):
    liar = []
    honest = []
    for j in range(n):
        if ((i >> j) & 1):
            if j + 1 in liar:
                break
            elif j + 1 not in honest:
                honest += [j + 1]
            sug_tmp = sug[j]

            for sug_ in sug_tmp:
                if sug_[1] == 1:
                    if sug_[0] in liar:
                        break
                    elif sug_[0] not in honest:
                        honest += [sug_[0]]
                else:
                    if sug_[0] in honest:
                        break
                    elif sug_[0] not in liar:
                        liar += [sug_[0]]
            else:
                continue
            break
        else:
            if j + 1 in honest:
                break
            elif j + 1 not in liar:
                liar += [j + 1]
    else:
        if ans < len(honest):
            ans = len(honest)
print(ans)

Solution (Python):
from itertools import product


N = int(input())
all_testimonies = []
for i in range(N):
    A = int(input())
    testimony = [list(map(int, input().split())) for _ in range(A)]
    all_testimonies.append({'A': A, 'test': testimony})
    
    

for bits in sorted(product(*[range(2) for _ in range(N)]), key=lambda x: sum(x), reverse=True):
    valid = True
    for i,testimony in enumerate(all_testimonies):
        person_is_honest = bool(bits[i])
        if person_is_honest:
            for j,y in testimony['test']:
                if bits[j-1] == y:
                    continue
                valid = False
    if valid:
        print(sum(bits))
        break

Solution (Python):
n = int(input())
a = []
xy = []

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

ans = 0
for bit in range(1<<n):
    h = [0]*n
    flag = True
    sum = 0

    for i in range(n):
        if (bit>>i) & 1:
            h[i] = 1
            sum += 1
                   
    for i in range(n):
        if (bit>>i) & 1:
            for j in range(a[i]):
                if xy[i][j][1] != h[xy[i][j][0]-1]:
                    flag =False

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

Solution (Python):
n=int(input())
syo=[]
mx=0
for i in range(n):
  a=int(input())
  gen=[]
  for j in range(a):
    x,y=map(int,input().split())
    gen.append([x-1,bool(y)])
  syo.append(gen)
for i in range(2**n):
  brk=False
  table=[False]*n
  for j in range(n):
    if((i>>j)&1):
      table[j]=True
  for j in range(n):
    if table[j]==False:
      continue
    for syogen in syo[j]:
      if table[syogen[0]]!=syogen[1]:
        brk=True
        break
    if brk:
      break
  if brk:
    continue
  cnt=table.count(True)
  if cnt>mx:
    mx=cnt
print(mx)

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

memberlist = []
testinomylist = []


for _ in range(N):

    A = int(input())
    tmpmemberlist = []
    tmptestinomylist = []
    
    for i in range(A):
        x, y = map(int, input().split())
        tmpmemberlist.append(x)
        tmptestinomylist.append(y)

    memberlist.append(tmpmemberlist)      
    testinomylist.append(tmptestinomylist) 
        
ans = 0

for i in range(2 ** N):
    honestlist = []
    liarlist = []

    for j in range(N):  
        if ((i >> j) & 1):
            
            honestlist.append(j+1)
        else:
            
            liarlist.append(j+1)

    
    Flag = 0

    for honestnumber in honestlist: 

        for X,Y in zip(memberlist[honestnumber-1] , testinomylist[honestnumber-1]): 
            if (Y == 0):
                if X in liarlist: 
                    pass
                else:
                    Flag = 1 
            elif (Y == 1):
                if X in honestlist:
                    pass
                else:
                    Flag = 1


    if Flag == 1:
        pass
    else:
        ans = max(ans,len(honestlist))

print(ans)

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

for i in range(N):
  A = int(input())
  for _ in range(A):
    x,y = map(int,input().split())
    evidence[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 == 1:
      for x,y in evidence[j]:
        if (i>>x)&1 != y:
          consistent = False
          break
      if not consistent:
        break
  if consistent:
    result = max(result,bin(i)[2:].count("1"))
    
print(result)

Solution (Python):
def resolve():
    import itertools
    N = int(input())
    A = []
    X = []
    ans = [0]
    for _ in range(N):
        a = int(input())
        xx = []
        for __ in range(a):
            x = list(map(int, input().split()))
            xx.append(x)
        X.append(xx)
        A.append(a)
    for i in itertools.product([0, 1], repeat=N):
        flag = 0
        for p in range(N):
            for q in range(A[p]):
                if i[p] == 1 and X[p][q][1] != i[X[p][q][0]-1]:
                    flag = 1
        if flag == 0:
            ans.append(i.count(1))
    print(max(ans))
resolve()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
XY = []
for _ in range(N):
    A = int(input())
    xy = [list(mapint()) for _ in range(A)]
    XY.append(xy)

ans = 0
for i in range(1<<N):
    honest = [-1]*N
    cnt = 0
    ok = True
    for j in range(N):
        if (i>>j)&1:
            honest[j]=1
        else:
            honest[j]=0
    for j in range(N):
        if (i>>j)&1:
            cnt += 1
            for x, y in XY[j]:
                if honest[x-1]!=y:
                    ok = False
                    break
    if ok:
        ans = max(ans, cnt)

print(ans)

Solution (Python):
n=int(input())
l0=[[] for _ in range(n)]
l1=[[] 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==0:
            l0[i].append(x)
        else:
            l1[i].append(x)
ans=0
for i in range(2**n):
    s0=set()
    s1=set()
    num=0
    num1=[]
    num0=[]
    for j in range(n):
        if (i>>j) & 1:
            num1.append(j+1)
            for k in range(len(l0[j])):
                s0.add(l0[j][k])
            for k in range(len(l1[j])):
                s1.add(l1[j][k])
        else:
            num0.append(j+1)
    for j in range(len(s1)):
        if s1.pop() in num0:
            num=1
            break
    if num==0:
        for j in range(len(s0)):
            if s0.pop() in num1:
                num=1
                break
    if num==0:
        ans=max(ans,len(num1))
print(ans)

Solution (Python):
import sys
from itertools import combinations_with_replacement,product
def input(): return sys.stdin.readline().rstrip()
 
def main():
    n=int(input())
    li=[]
    for i in range(n):
        lia=[]
        A=int(input())
        for j in range(A):

            x,y=map(int, input().split())
            x-=1
            lia.append([x,y])
        li.append(lia)
    ans = 0
    for k in list(product([0,1],repeat=n)):
        if ans >= sum(k):
            continue
        kt = list(k)
        for y in range(n):
            if kt[y]==1:
                for g in li[y]:
                    if g[1] != kt[g[0]]:
                        break
                else:
                    continue
                break
        else:
            ans = sum(k)
            
    print(ans)



if __name__=='__main__':
    main()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = []
    xy = []
    for _ in range(N):
        A.append(I())
        xy.append([LI() for _ in range(A[-1])])

    ans = 0
    for i in range(2 ** N):
        
        is_ok = True
        num = 0
        for j in range(N):
            if i >> j & 1:
                num += 1
                for k in xy[j]:
                    x, y = k
                    x -= 1
                    if i >> x & 1 != y:
                        is_ok = False
        if is_ok:
            ans = max(num, ans)

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
N=int(input())
X=[0]*N
for i in range(N):
 X[i]=[list(map(int,input().split())) for _ in [0]*int(input())]
print(max(['{:b}'.format(i).count('1')for i in range(2**N) if all([all([y[1]==i>>(y[0]-1)&1 for y in X[j]]) for j in range(N) if (i>>j&1)])]))

Solution (Python):
N=int(input())
X=[0]*N
for i in range(N):
    X[i]=[list(map(int,input().split())) for _ in range(int(input()))]
print(max(['{:03b}'.format(i).count('1')for i in range(2**N) if all([i>>j&1 and all([y[1]==i>>(y[0]-1)&1 for y in X[j]]) for j in range(N) if (i>>j&1)])]))

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

says = []

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



max_upright_count = 0
for i in range(1 << N):
    integrate = True
    upright_count = 0
    declares = [-1 for _ in range(N)]
    for j in range(N):
        if not integrate:
            continue
        
        if (i >> j & 1) == 1:
            upright_count += 1
            for x, y in says[j]:
                
                if declares[x - 1] == -1:
                    declares[x - 1] = y
                else:
                    if declares[x - 1] == y:
                        continue
                    else:
                        integrate = False
                        break
    
    for j in range(N):
        
        if ((i >> j) & 1) != declares[j] and declares[j] != -1:
            
            integrate = False
    
    if integrate:
        max_upright_count = max(max_upright_count, upright_count)
print(max_upright_count)

Solution (Python):
n = int(input())
m = []
a = [[] for i in range(n)]
for i in range(n):
    tmp = int(input())
    m.append(tmp)
    for j in range(tmp):
        a[i].append(list(map(int,input().split())))
ans = 0
for i in range(2**n):
    cnt = 0
    for j in range(n):
        flg = True
        if i >> j & 1:
            cnt += 1
            for k in range(m[j]):
                kj = (i >> (a[j][k][0]-1)) & 1
                if a[j][k][1] != kj:
                    flg = False
                    break
            if not flg:
                break
    if flg:
        ans = max(ans, cnt)
            
print(ans)

Solution (Python):
n = int(input())
m = []
a = [[] for i in range(n)]
for i in range(n):
    tmp = int(input())
    m.append(tmp)
    for j in range(tmp):
        a[i].append(list(map(int,input().split())))
ans = 0
for i in range(2**n):
    cnt = 0
    for j in range(n):
        flg = True
        if i >> j & 1:
            cnt += 1
            for k in range(m[j]):
                kj = (i >> (a[j][k][0]-1)) & 1
                if a[j][k][1] != kj:
                    flg = False
                    break
            if not flg:
                break
    if flg:
        ans = max(ans, cnt)
            
print(ans)

Solution (Python):
from collections import defaultdict
import itertools

n = int(input())

l = [[] for i in range(n)]
p = [i 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].append((x,y))

for i in range(n,-1,-1):
    for comb in itertools.combinations(p,i):
        tmp = [1 if j in comb else 0 for j in range(n)]
        F = True
        for c in comb:
            for k in l[c]:
                if tmp[k[0]-1] != k[1]:
                    F = False
        if F:
            print(i)
            exit()

print(0)

Solution (Python):
from typing import List


def io_info() -> List[List[int]]:
    N = int(input())
    res = [[-1] * N for _ in range(N)]
    for n in range(N):
        a = int(input())
        for _ in range(a):
            x, y = map(int, input().split())
            res[n][x-1] = y
    return res


def main():
    infos = io_info()
    n = len(infos)
    ans = 0
    for i in range(1 << n):
        d = [0] * n
        for j in range(n):
            
            if (i >> j) & 1:
                d[j] = 1
        ok = True
        for j in range(n):
            if d[j]:
                for k in range(n):
                    if infos[j][k] == -1: continue
                    if infos[j][k] != d[k]: ok = False

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



if __name__ == '__main__':
    main()

Solution (Python):
def check(i,N,Ls):
    count=0
    for j in range(N):
        if (i>>j)%2==1:
            for k in Ls[j]:
                if ((i>>(k[0]-1))%2)!=k[1]:
                    return 0
            count+=1
    return count
                
N=int(input())
A_ls=[]
Ls=[]
for i in range(N):
    A=int(input())
    A_ls.append(A)
    ls=[]
    for j in range(A):
        x,y=map(int,input().split())
        ls.append((x,y))
    Ls.append(ls)

ans=0
for i in range(2**N):
    num=check(i,N,Ls)
    if num>ans:
        ans=num
print(ans)

Solution (Python):


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

ans = 0
for bit in range(1 << n):
    p = ["不親切"] * n
    ng = False
    
    for i in range(n):
        if bit >> i & 1 == 1:
            
            p[n - i - 1] = "正直者"
    for i in range(n):
        if p[i] == "不親切":
            
            continue
        for s in syogen[i]:
            if p[s[0] - 1] == "正直者" and s[1] == 1:
                
                continue
            elif p[s[0] - 1] == "不親切" and s[1] == 0:
                
                continue
            else:
                
                ng = True
                break

    if not ng:
        ans = max(ans, p.count("正直者"))
print(ans)

Solution (Python):

import itertools

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


ans = 0
for i in range(2 ** n):
    flag = 0
    for j in range(n):
        
        if (i >> j) & 1 == 1:
            
            for ParsonStatement in xy[j]:
                if (i >> (ParsonStatement[0] - 1) & 1 )!= ParsonStatement[1]:
                    
                    flag = 1
                    break
    
    if flag == 0:
        ans=max(ans,bin(i)[2:].count("1"))     
print(ans)

Solution (Python):
def main():
    import itertools
    n = int(input())
    test = []
    for i in range(n):
        a = int(input())
        t = []
        for j in range(a):
            x,y = map(int,input().split())
            t.append([x,y])
        test.append(t)
    stats = ((0,1) for i in range(n))
    ans = 0
    for k in itertools.product(*stats):
        tf = [-1 for i in range(n)]
        flg = 0
        for i in range(len(k)):
            if k[i]==1:
                for t in test[i]:
                    if tf[t[0]-1]==-1:
                        tf[t[0]-1] = t[1]
                    else:
                        if tf[t[0]-1] != t[1]:
                            flg = 1
                            break
        for i in range(len(k)):
            if tf[i] != -1:
                if tf[i] != k[i]:
                    flg = 1
                    break
        if flg == 0:
            if ans < sum(k):
                ans = sum(k)
    print(ans)

if __name__ == "__main__":
    main()

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

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

Solution (Python):
n = int(input())
adjMat = [[-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())
        adjMat[i][x-1] = y
ans = 0
for i in range(1 << (n)):
    
    success = True
    for j in range(n):
        if i & 2**j:
            for k in range(n):
                if k == j:
                    continue
                if  i & 2**k == 0 and adjMat[j][k] == 1:
                    success = False
                if i & 2**k > 0 and adjMat[k][j] == 0:
                    success = False
                
        if not success:
            break
    if success:
        i2 = i
        c = 0
        while i2 > 0:
            c += i2 & 1
            i2 //= 2
        ans = max(c, ans)
print (ans)

Solution (Python):
from itertools import product

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

MAX=0
for p in product(range(2),repeat=N):
  flag=0
  for i in range(N):
    if p[i] == 1:
      for j in range(len(statement[i])):
        if statement[i][j][1]==1:
          x = statement[i][j][0]
          if p[x] != 1:
            flag=1
            break
        if statement[i][j][1]==0:
          x = statement[i][j][0]
          if p[x] == 1:
            flag=1
            break
    if flag==1:break
  if flag==1:continue
  if sum(p) > MAX:
    MAX=sum(p)

print(MAX)

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


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

  max_ = 0
  for bit in range(1 << N):
    for i in range(N):
      mask = (1 << i)
      
      for j in range(N):
        if A[j][i] == -1:
          continue
        
        if (bit & (1 << j)) and A[j][i] != bool(bit & mask):
          
          break
      else:
        
        continue
      break
    else:
      
      max_ = max(max_, bin(bit).count('1'))

  print(max_)


if(__name__ == '__main__'):
  main()

Solution (Python):
import numpy as np
N = int(input())
proof_list=np.array([[None]*N for i in range(N)])
check_list=[True]*N
for i in range(N):
    A = int(input())
    for j in range(A):
        x,y = map(int,input().split())
        proof_list[i][x-1] = y
ans = 0
for i in range(2**N):
    honests = []
    for j in range(N):
        if((i>>j)&1):
            honests.append(j)
    flag = True
    for l in honests:
        for k in range(N):
            if (k in honests) and proof_list[l][k] == 0:
                flag = False
            elif(k not in honests) and proof_list[l][k] ==1:
                flag = False
    if flag:
        ans = max(ans,len(honests))
print(ans)

Solution (Python):
N = int(input())
G = [[-1] * N for i in range(N)]
ans = 0
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 bit in range(2**N):
    honests = []
    for i in range(N):
        if bit & (1<<i):
            honests.append(i)
    flag = True
    for j in honests:
        for k in range(N):
            if (k in honests) and G[j][k] == 0:
                flag = False
            elif(k not in honests) and G[j][k] == 1:
                flag = False
    if flag:
        ans = max(ans, len(honests))
print(ans)

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

    user_remarks = {}

    for i in range(1, N+1):
        A = int(input())
        user_remarks[i] = []

        for _ in range(A):
            user_id, is_honest = [int(x) for x in input().split()]
            user_remarks[i].append((user_id, is_honest == 1))

    max_count = 0

    for i in range(2**N):
        honest = {}
        is_ok = True
        for x in range(N):
            
            if ((i >> x) & 1):
                honest[x+1] = True

                if is_ok:
                    
                    for user_remark in user_remarks[x+1]:
                        target_user = user_remark[0]
                        target_is_honest = user_remark[1]

                        
                        if target_is_honest:
                            
                            if not ((i >> (target_user-1)) & 1):
                                is_ok = False

                        
                        if not target_is_honest:
                            
                            if ((i >> (target_user-1)) & 1):
                                is_ok = False

        if is_ok:
            max_count = max(max_count, len(honest))

    print(max_count)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
say = {}
for i in range(N):
    say[i] = []
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        x -= 1
        say[i].append((x, y))
ans = 0
for i in range(1 << N):
    ok = True
    Honecount = 0
    for j in range(N):
        if((i >> j) & 1 == 0):
            continue
        Honecount += 1
        for k in say[j]:
            if ((i >> k[0]) & 1) != k[1]:
                ok = False
                break
        if ok == False:
            break
    if ok == True:
        ans = max(ans, Honecount)

print(ans)

Solution (Python):
from itertools import product

def solve():
    N = int(input())
    graph = {i: [] for i in range(1, N+1)}
    for i in range(N): 
        A = int(input())
        for _ in range(A):
            x,y = map(int, input().split())
            graph[i+1].append((x,y))
            
    def dfs(nodes):
        searched = [-1] * N
        stack = [i+1 for i,node in enumerate(nodes) if node == 1]
        ret_len = len(stack)
        
        while stack:
            node = stack.pop(0)
            for x,y in graph[node]:
                if nodes[x-1] != y: return -1
                if searched[x-1] == -1:
                    searched[x-1] = y
                    if y == 1: stack.append(x)
                        
        
        return ret_len
                    
        
    ret = 0
    for nodes in product([0,1], repeat=N):
        ret = max(ret, dfs(nodes))
        
    print(ret)
    
solve()

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

ans=[0]
for i in range(2**n):
    ch=1
    for k in range(0,n):
        if ((i>>k)&1):
            for q in a[k]:
                if ((i>>q[0])&1)==(q[1]^1):
                    ch=0

    if ch==1:
        ans.append(bin(i).count("1"))
print(max(ans))

Solution (Python):
n = int(input())
v = [[tuple(map(int, input().split()))for i in range(int(input()))]
     for i in range(n)]

ans = 0
for i in range(2**n):
    f = True
    a = 0
    for j in range(n):
        if (i >> j) & 1:
            if all(i >> (x - 1) & 1 == y for x, y in v[j]):
                a += 1
            else:
                f = False
                break
    if f:
        ans = max(ans, a)
print(ans)

Solution (Python):
n = int(input())
v = [[tuple(map(int, input().split()))for i in range(int(input()))]
     for i in range(n)]

ans = 0
for i in range(2**n):
    f = [0] * n
    xy = []
    for j in range(n):
        if (i >> j) & 1:
            f[j] = 1
            xy.append(v[j])
    flag = True
    for xyi in xy:
        for x, y in xyi:
            
            if (i>>(x-1))&1 != y:
                flag = False
                break
    if flag:
        ans = max(ans, len(xy))
print(ans)

Solution (Python):
n = int(input())
v = [[tuple(map(int, input().split()))for i in range(int(input()))]
     for i in range(n)]

ans = 0
for i in range(2**n):
    f = [False] * n
    xy = []
    for j in range(n):
        if (i >> j) & 1:
            f[j] = True
            xy.append(v[j])
    flag = True
    for xyi in xy:
        for x, y in xyi:
            if f[x - 1] is not bool(y):
                flag = False
                break
    if flag:
        ans = max(ans, len(xy))
print(ans)

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

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [set() for _ in range(n)]
b = [set() for _ in range(n)]
for i in range(n):
    nn = int(input())
    for j in range(nn):
        x,y = list(map(int, input().split()))
        x -= 1
        if y==1:
            a[i].add(x)
        else:
            b[i].add(x)
ans = -1
for bit in range(1<<n):
    tmpa = set()
    tmpb = set()
    tmp2a = set()
    tmp2b = set()
    for j in range(n):
        if bit>>j&1:
            tmpa |= a[j]
            tmpb |= b[j]
            tmp2a.add(j)
        else:
            tmp2b.add(j)
    if len(tmpa&tmpb)==0 and len(tmp2a&tmpb)==0 and len(tmpa&tmp2b)==0: 
        ans = max(ans, len(tmp2a))
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

ans = 0
for bit in range(2**n):
    flag = True
    for i in range(n):
        if bit & (1 << i):
            for j in xy[i]:
                x = j[0]
                y = j[1]
                b = bit & (1 << x)
                if (b and y) or (b == 0 and y == 0):
                    continue
                else:
                    flag = False
                    break
        if not flag:
            break
    if flag:
        ans = max(ans, bin(bit).count('1'))
print(ans)

Solution (Python):
g = [[-1 for i in range(15)] for j in range(15)]


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


ans=0

for i in range (1<<n): 
  honests = [0 for _ in range(n)] 
  for j in range(n):
    if (i >> j) & 1:
      honests[j] = 1 


  hantei = True
  for j in range(n):
    if honests[j]==1: 
      
      for k in range(n):
        if g[j][k] == -1: 
          continue 
        if g[j][k] != honests[k]:
          
          
          hantei = False
  if hantei == True:
    ans = max(ans, honests.count(1))
                     
print(ans)

Solution (Python):
N = int(input())
table = []

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

res = 0
for i in range(2**N):
    bi = [j for j in range(N) if (i >> j &1)]
    dic = {}
    for b in bi:
        dic[b] = 1
    
    endfor = False
    for b1 in bi:
        if endfor:
            break
        said = table[b1]
        for k in said.keys():
            if k not in dic.keys():
                if said[k]:
                    endfor = True
                    break
                dic[k] = said[k]
            elif dic[k] == said[k]:
                continue
            else:
                endfor = True
                break
    if not endfor:
        res = max(res, len(bi))

print(res)