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

Solution (Python):

n=int(input())
lst=[]
for i in range(n):
    a=int(input())
    b=[]
    for j in range(a):
        x,y=map(int,input().split())
        x-=1
        b.append([x,y])
    lst.append(b)
ans=0
for i in range(2**n):
    on=[]
    switch=0
    for j in range(n):
        if ((i>>j)&1):
            on.append(j)
    for j in on:
        judge=lst[j]
        for k in judge:
            if k[1]==1:
                if not k[0] in on:
                    switch=1
            else:
                if k[0] in on:
                    switch=1
    if switch==0:
        ans=max(ans,len(on))

print(ans)

Solution (Python):

from itertools import product

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 product([0, 1], repeat=N):
    consistent = True
    for j in range(N):
        if i[j] == 0:
            continue
        for x, y in evidences[j]:
            if i[x] != y:
                consistent = False
                break
        if not consistent:
            break
    if consistent:
        result = max(result, i.count(True))
print(result)

Solution (Python):
import numpy as np
N = int(input())
S = [[] for I in range(0,N)]
for T in range(0,N):
    A = int(input())
    S[T] = np.zeros((A,2),dtype=int)
    for TT in range(0,A):
        S[T][TT,:] = np.array([int(X) for X in input().split()])
    
MAX = 0
for P in range(pow(2,N)-1,-1,-1):
    Bin    = [int(X) for X in list(('{:0'+str(N)+'b}').format(P,'b'))]
    BIndex = [I for I,N in enumerate(Bin) if N==1]
    Flag   = True
    for PT in BIndex:
        for PTB in range(0,S[PT].shape[0]):
            if S[PT][PTB,1]==0 and (S[PT][PTB,0]-1) in BIndex:
                Flag = False
                break
            if S[PT][PTB,1]==1 and (S[PT][PTB,0]-1) not in BIndex:
                Flag = False
                break
        if not Flag:
            break
    if Flag:
        MAX = len(BIndex)
        break
print(MAX)

Solution (Python):
def main():
    n = int(input())
    A = [[] for i in range(n)]
    ans = 0
    for i in range(n):
        a = int(input())
        tmp = {}
        for j in range(a):
            x,y = map(int,input().split())
            tmp[x-1] = y
        A[i] = tmp
    
    for i in range(2**n):
        kouho = []
        for j in range(n):
            if  (i>>j)&1:
                kouho.append(j)
        honest = {}
        for j in range(n):
            if j in kouho:
                honest[j] = 1
            else:
                honest[j] = 0
        flag = True
        
        for j in kouho:
            hatugen = A[j]
            for k in hatugen.keys():
                if honest[k]!=hatugen[k]:
                    flag = False
        if flag:
            ans = max(ans,len(kouho))
    print(ans)

main()

Solution (Python):
from itertools import product

N = int(input())
xy = [[] for i in range(N)]

for i in range(N):
    for j in range(int(input())):
        xy[i].append(list(map(int, input().split())))
        
ans = 0
for bit in product([0,1], repeat=N):
    f = 0
    for i, j in enumerate(bit):
        if j == 1:
            for x, y in xy[i]:
                if bit[x-1] != y:
                    f = 1
                    break
    if f == 0:
        ans = max(ans, sum(bit))
print(ans)

Solution (Python):
n = int(input())
XY = []
for i in range(n):
    a = int(input())
    xy = []
    for j in range(a):
        x, y = map(int, input().split())
        xy.append([x, y])
    XY.append(xy)
ans = 0
for i in range(2 ** n):
    s = [0] * n
    cnt = 0
    case = True
    for j in range(n):
        if (i >> j) & 1:
            s[j] = 1
            cnt += 1
    for k in range(n):
        if s[k] == 1:
            for l in range(len(XY[k])):
                if s[XY[k][l][0] - 1] != XY[k][l][1]:
                    case = False
    if case is True:
        ans = max(ans, cnt)
print(ans)

Solution (Python):
n = int(input())
XY = []
for i in range(n):
    a = int(input())
    xy = []
    for j in range(a):
        x, y = map(int, input().split())
        xy.append([x, y])
    XY.append(xy)
ans = 0
for i in range(2 ** n):
    s = [0] * n
    cnt = 0
    case = True
    for j in range(n):
        if (i >> j) & 1:
            s[n - 1 - j] = 1
            cnt += 1
    for k in range(n):
        if s[k] == 1:
            for l in range(len(XY[k])):
                if s[XY[k][l][0] - 1] != XY[k][l][1]:
                    case = False
    if case is True:
        ans = max(ans, cnt)
print(ans)

Solution (Python):
n = int(input())
XY = []
for i in range(n):
    a = int(input())
    xy = []
    for j in range(a):
        x, y = map(int, input().split())
        xy.append([x, y])
    XY.append(xy)
ans = 0
for i in range(2 ** n):
    s = [0] * n
    cnt = 0
    case = 0
    for j in range(n):
        if (i >> j) & 1:
            s[n - 1 - j] = 1
            cnt += 1
    for k in range(n):
        if s[k] == 1:
            for l in range(len(XY[k])):
                if s[XY[k][l][0] - 1] != XY[k][l][1]:
                    case = 1
    if case == 0:
        ans = max(ans, cnt)
print(ans)

Solution (Python):
N = int(input())
X = {}

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

ans = 0
for bit in range(2 ** N):
    tmp = bit
    flag = True
    for i in range(N):
        if not (bit >> i & 1):
            continue

        for x, y in X[i]:
            if (bit >> (x - 1) & 1) != y:
                flag = False
                break
                
    if flag:
        ans = max(ans, bin(bit).count("1"))

print(ans)

Solution (Python):


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

ans = 0
for i in range(2**n):
    hone = set()
    unki = set()
    for j in range(n):
        if i >> j & 1:
            hone |= {j + 1}
            for k in a[j]:
                if k[1] == 1:
                    hone |= {k[0]}
                else:
                    unki |= {k[0]}
        else:
            unki |= {j + 1}
    if hone & unki == set():
        ans = max(ans, len(hone))
print(ans)

Solution (Python):
from itertools import product
N = int(input())
G = {i:[] for i in range(1,N+1)}
for i in range(1,N+1):
    a = int(input())
    G[i] = [list(map(int,input().split())) for _ in range(a)]
cmax = 0
for z in product((0,1),repeat=N+1):
    if z[0]==0:
        X = []
        for i in range(1,N+1):
            if z[i]==1:
                X.append(i)
        A = []
        B = []
        for i in X:
            for x,y in G[i]:
                if y==1:
                    A.append(x)
                else:
                    B.append(x)
        flag = 0
        for a in A:
            if a not in X:
                flag = 1
                break
        for b in B:
            if b in X:
                flag = 1
                break
        if flag==0:
            cmax = max(cmax,sum(z[1:]))
print(cmax)

Solution (Python):




import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=[[] for i in range(n)]
for i in range(n):
    a=I()
    for j in range(a):
        lis[i].append(LI())

ans=[]
for x in product([0,1],repeat=n):
    count=0
    flag=True
    for j in range(n):
        if x[j]==1:
            count+=1
            for k in range(len(lis[j])):
                if x[lis[j][k][0]-1]!=lis[j][k][1]:
                    flag=False
    if flag==True:
        ans.append(count)
print(max(ans))

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

g = [[] for _ in range(n)]

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

ans = 0
for i in range(2**n):
    temp = [-1]*n
    for j in range(n):
        if (i >> j) & 1:
            temp[j] = 1
        else:
            temp[j] = 0
    flag = True
    for j in range(n):
        if temp[j] == 1:
            for x, y in g[j]:
                if temp[x] != y:
                    flag = False
    if flag:
        ans = max(ans, sum(temp))
print(ans)

Solution (Python):

import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)
def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]

N = z()
A = [0]*N
X = {}
Y = {}
for i in range(N):
    A[i] = z()
    X[i] = [0]*A[i]
    Y[i] = [0]*A[i]
    for j in range(A[i]):
        x, y = zz()
        X[i][j] = x-1
        Y[i][j] = y
ans = 0
for bits in itertools.product([0, 1], repeat=N):
    
    
    false_flg = False
    for i, b in enumerate(bits):
        if (b == 1):
            
            for x, y in zip(X[i], Y[i]):
                
                if (bits[x] != y):
                    
                    false_flg = True
                if false_flg:
                    break
            if false_flg:
                break
    if false_flg:
        continue
    else:
        ans = max(ans, sum(bits))
print(ans)

Solution (Python):
import itertools

N = int(input())

H = []
for n in range(N):
    A = int(input())
    tmp = []
    for a in range(A):
        tmp.append(list(map(int, input().split())))
    H.append(tmp)
ans = 0 
for pro in itertools.product([0, 1], repeat=N):
    flag = 0
    for p in range(len(pro)):
        if pro[p] != 0:
            for h in H[p]:
                if pro[h[0]-1] != h[1]:
                    flag = 1
                    break
        if flag == 1:
            break
        if p == len(pro) - 1:
            ans = max(ans, sum(pro))

print(ans)

Solution (Python):
def II(): return int(input())
def MI(): return map(int, input().split())
N=II()
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]=II()
  for j in range(a[i]):
    x[i][j],y[i][j]=MI()
    x[i][j]-=1
def check(honest):
  for i in range(N):
    if not honest[i]:
      continue
    for j in range(a[i]):
      if y[i][j]==0 and honest[x[i][j]]:
        return False
      if y[i][j]==1 and not honest[x[i][j]]:
        return False
  return True
def dfs(honest):
  if len(honest)==N:
    if check(honest):
      return sum(honest)
    else:
      return 0
  return max(dfs(honest+[True]),dfs(honest+[False]))
print(dfs([]))

Solution (Python):
def II(): return int(input())
def MI(): return map(int, input().split())
N=II()
shogens=[]
for i in range(N):
  a=II()
  shogens.append([])
  for j in range(a):
    x,y=MI()
    x-=1
    shogens[-1].append((x,y))
def is_honest(i,j):
  return (i>>j)%2==1
def honest_cnt(i):
  ans=0
  for j in range(N):
    ans+=is_honest(i,j)
  return ans
ans=0
for i in range(1<<N):
  ok=True
  for j in range(N):
    if not is_honest(i,j):
      continue
    for (x,y) in shogens[j]:
      if y==0 and is_honest(i,x):
        ok=False
      if y==1 and not is_honest(i,x):
        ok=False  
  if ok:
    ans=max(ans,honest_cnt(i))
print(ans)

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




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


mujun=[0]*(N+1)
count=0
ans=0
for L in Ls:
    
    flag=0
    hito=1
    
    count=sum(list(L))
    mujun=[0] + list(L)
    for i in L:
        
        if i==1:
            for xy in xys[hito-1]:
                
                if xy[1] == 1:
                    if mujun[xy[0]]==0:
                        count=0
                        
                        flag=1
                        break
                    
                        
                        
                else:
                    if mujun[xy[0]]==1:
                        count=0
                        
                        flag=1
                        break
                    
                        


                
                
        hito+=1
    if flag==0:
        ans=max(ans,count)
    


print(ans)

Solution (Python):
import itertools
N = int(input())
lis_hl = list(itertools.product('01',repeat = N))

A = []
X = []
for i in range(N):
    A.append(int(input()))
    Y =[]
    for j in range(A[-1]):
        Y.append(list(map(int,input().split())))
    X.append(Y)
honesty = 0
for hl in lis_hl:
    flag = 0
    for i in range(N):
        if flag == 0:
            is_hl = hl[i]
            if is_hl == '1':
                
                for xi in X[i]:
                    if xi[1] != int(hl[xi[0]-1]):
                        flag = 1
                        break
    if flag == 0:
        honesty = max(honesty,hl.count('1'))
print(honesty)

Solution (Python):

from collections import defaultdict, deque, Counter, OrderedDict
from functools import reduce, lru_cache
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N = I()
    A = []
    for _ in range(N):
        ni = I()
        A.append(LIR(ni))

    ans = 0
    for bit in range(1 << N):
        pattern = [bit >> i & 1 for i in range(N)]
        for (i, Ai) in enumerate(A):
            if not pattern[i]:
                continue
            
            for (x, y) in Ai:
                target = pattern[x-1]
                if target != y:
                    break
            else:
                continue
            break
        else:
            ans = max(ans, pattern.count(1))

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):


import sys
stdin = sys.stdin
from itertools import product

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    t = [[-1] * n for _ in range(n)]
    for j in range(n):
        a = ni()
        for i in range(a):
            x, y = na()
            t[j][x-1] = y
    l = list(product([0, 1], repeat=n))
    ans = 0
    
    for li in l:
        f = True
        for i in range(n):
            people = li[i]
            if people:
                for j in range(n):
                    if t[i][j] == 1 and li[j] == 0:
                        f = False
                    if t[i][j] == 0 and li[j] == 1:
                        f = False
        if f:
            
            ans = max(ans, sum(li))
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import itertools
N=int(input())
A=[]
for i in range(N):
  a=[]
  B=int(input())
  for _ in range(B):
    x,y=map(int,input().split())
    a.append([x,y])
  A.append(a)
ans=0
for i in list(itertools.product(range(2),repeat=N)):
  for j in range(len(A)):
    flag=True
    if i[j]==0:
      continue
    for x,y in A[j]:
      if i[x-1]!=y:
        flag=False
        break
    if not flag:
      break
  if flag:
    ans=max(ans,sum(i))
print(ans)

Solution (Python):
n=int(input())
xy=[[] 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
    xy[i].append((x,y))
ans=0
for i in range(1<<n):
  cnt=bin(i).count("1")
  if cnt<=ans:continue
  for j in range(n):
    if i&(1<<j):
      for x,y in xy[j]:
        if y==1 and i&(1<<x):continue
        if y==0 and i&(1<<x)==0:continue
        break
      else:
        continue
      break
  else:
    ans=cnt
print(ans)

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

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

ans = 0

for i in range(2**n):
    ans_t = 0
    id_list =list(bin(i))[2:]
    id_list = [int(x) for x in id_list]
    while len(id_list) != n:
        id_list.insert(0,0)
    for j in range(n):
        flag = 0
        if id_list[j] == 0:
            continue
        else:
            for k in range(a[j][0]):
                if id_list[a[j][1][k][0]-1] != a[j][1][k][1]:
                    flag = 1
                    break
        if flag == 1:
            ans_t = 0
            break
        else:
            ans_t += 1
    if ans_t > ans:
        ans = ans_t

print(ans)

Solution (Python):
N=int(input())
B=[]
for i in range (N):
    a=int(input())
    b=[]
    for j in range(a):
        x,y=map(int,input().split())
        b.append([x,y])
    B.append(b)
ans=0
for k in range(2**N):
    num=0
    L=[0]*N
    p=0
    for j in range(N):
        if ((k>>j)&1):
            L[N-1-j]=1
            num+=1
    for k in range(N):
        if L[k]==1:
            for m in range(len(B[k])):
                if L[B[k][m][0]-1]!=B[k][m][1]:
                    p=1
    if p==0:
        ans=max(ans,num)

print(ans)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    B = [[] for _ in range(N)]
    for i in range(N):
        k = int(readline())
        for _ in range(k):
            x, y = map(int, readline().split())
            B[i].append((x - 1, y))

    ans = 0
    for bit in range(1 << N):
        ok = True
        for i in range(N):
            if not (bit & (1 << i)):
                continue
            for x, y in B[i]:
                if bool(bit & (1 << x)) != bool(y):
                    ok = False
                    break
            if not ok:
                break

        if ok:
            ans = max(ans, str(bin(bit)).count('1'))

    print(ans)
    return


if __name__ == '__main__':
    main()

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 j in range(1,2**N):
  consistent = True
  for k in range(N):
    if (j >> k) & 1 == 0:
      continue
    for x,y in evidence[k]:
      if (j >> x) & 1 != y:
        consistent = False
        break
    if not consistent:
      break
  if consistent:
    result = max(result, bin(j)[2:].count("1"))
print(result)

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

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

ans = 0
for i in range(2**n):
  ans_list = [0]*n
  cnt=0
  while i!=0:
    ans_list[cnt] = i%2
    cnt+=1
    i//=2
  
  flg = True
  for j, syogens in enumerate(a_list):
    if ans_list[j]==0:
      pass
    else:
      for syogen in syogens:
        person = syogen[0]-1
        status = syogen[1]
        if ans_list[person] != status:
          flg=False
  if flg:
    ans = max(ans,sum(ans_list))
print(ans)

Solution (Python):
import itertools

n = int(input())

l = list(itertools.product([0,1], repeat=n))[::-1]

A = {}
for i in range(n):
    ai = int(input())
    for j in range(ai):
        x, y = map(int, input().split())
        if i not in A:
            A[i] = []
        A[i].append((x, y))
    if ai == 0:
        A[i] = []


def shoujiki(i):
    check = {}
    cnt = 0
    for j in range(n):
        check[j+1] = i[j]
    for j in range(n):
        ai = len(A[j])
        if i[j] == 1:
            for k in range(ai):
                x, y = A[j][k]
                if check[x] != y:
                    return 0
    
    return sum(i)

mans = 0
for i in l:
    mans = max(shoujiki(i), mans)

print(mans)

Solution (Python):
from collections import deque


def do_code():
    num = int(input())
    matrix = [[2] * (num + 1) for _ in range(num + 1)]
    honests = [set() for _ in range(num + 1)]
    unkinds = [set() for _ in range(num + 1)]
    
    for n in range(1, num + 1):
        u = set()
        h = set()
        ans = int(input())
        for a in range(ans):
            x, y = map(int, input().split(" "))
            if y == 1:
                h.add(x)
            else:
                u.add(x)
        honests[n] = h
        unkinds[n] = u
    count = 0
    for n in range(1, 2 ** num):
        honest_set = set()
        for j in range(num):
            t = 2 ** j
            if n & t == t:
                honest_set.add(j + 1)
        th = set()
        tu = set()
        queue = deque(honest_set)
        visited = set()
        while len(queue) > 0:
            t = queue.popleft()
            if t in visited:
                continue
            visited.add(t)
            queue.extend(honests[t])
            th |= honests[t]
            tu |= unkinds[t]
        if not th.isdisjoint(tu):
            
            continue
        if not honest_set.isdisjoint(tu):
            continue
        honest = max(len(th), len(honest_set))
        count = max(count, honest)
    print(count)


if __name__ == '__main__':
    do_code()

Solution (Python):
import itertools
n = int(input())
b = []
for i in range(n):
  a = int(input())
  c = []
  for j in range(a):
    x, y = map(int, input().split())
    c.append([x,y])
  b.append(c)
g = []
for i in list(itertools.product(range(2) ,repeat = n)):
  flag = True
  for j in range(n):
    if i[j] == 0:
      continue
    for x,y in b[j]:
      if i[x-1] != y:
        flag = False
        break
    if not flag:
      break
  if flag:
    g.append(sum(i))
print(max(g))

Solution (Python):

from itertools import product

def solve(n,a):
    testimony = product([0,1],repeat=n)
    ans = 0
    for l in testimony:
        flag = True
        for test in a:
            if l[test[0]] and l[test[1]] and (test[2] == 0):
                flag = False
            if l[test[0]] and l[test[1]]==0 and test[2]:
                flag = False
        if flag:
            ans = max(ans,sum(l))
    return ans



def main():
    N = int(input())
    a = []
    for i in range(N):
        tmp = int(input())
        for _ in range(tmp):
            x,y = map(int,input().split())
            a.append([i,x-1,y])
    print(solve(N,a))
    return

if __name__ == '__main__':
    main()

Solution (Python):
A=[]
for i in range(n:=int(input())):
  for _ in range(int(input())): x,y=map(int,input().split()); A+=[(i,x-1,y)]
print(max(sum(map(int,bin(i)[2:]))*all(i>>j&1<1 or i>>x&1==y for j,x,y in A) for i in range(2**n)))

Solution (Python):
n=int(input())
A=[]
for i in range(n):
  for _ in range(int(input())):
    x,y=map(int,input().split())
    A+=[(i,x-1,y)]
print(max(sum(map(int,bin(i)[2:]))*all(i>>j&1<1 or i>>x&1==y for j,x,y in A) for i in range(2**n)))

Solution (Python):
n=int(input())
A=[]
for i in range(n):
  for _ in range(int(input())):
    x,y=map(int,input().split())
    A+=[(i,x-1,y)]
print(max(sum(map(int,bin(i)[2:])) for i in range(2**n) if all(i>>j&1<1 or i>>x&1==y for j,x,y in A)))

Solution (Python):
n=int(input())
A=[]
for i in range(n):
  for _ in range(int(input())):
    x,y=map(int,input().split())
    A+=[(i,x-1,y)]
a=0
for i in range(2**n):
  if all(i>>j&1<1 or i>>x&1==y for j,x,y in A):
    a=max(a,sum(map(int,bin(i)[2:])))
print(a)

Solution (Python):
n=int(input())
A=[{} for _ in range(n)]
for i in range(n):
  for _ in range(int(input())):
    x,y=map(int,input().split())
    A[i][x]=y
a=0
for i in range(2**n):
  t=0
  for j in range(n):
    if i>>j&1:
      if A[j] and any(i>>~-k&1!=A[j][k] for k in A[j]): break
      else: t+=1
  else: a=max(a,t)
print(a)

Solution (Python):
n=int(input())
lst=[]
for i in range(n):
    a=int(input())
    b=[]
    for j in range(a):
        x,y=map(int,input().split())
        x-=1
        b.append([x,y])
    lst.append(b)
ans=0
for i in range(2**n):
    on=[]
    switch=0
    for j in range(n):
        if ((i>>j)&1):
            on.append(j)
    for j in on:
        judge=lst[j]
        for k in judge:
            if k[1]==1:
                if not k[0] in on:
                    switch=1
            else:
                if k[0] in on:
                    switch=1
    if switch==0:
        ans=max(ans,len(on))

print(ans)

Solution (Python):
n=int(input())
lst=[]
for i in range(n):
    a=int(input())
    b=[]
    for j in range(a):
        x,y=map(int,input().split())
        x-=1
        b.append([x,y])
    lst.append(b)
ans=0
for i in range(2**n):
    on=[]
    switch=0
    for j in range(n):
        if ((i>>j)&1):
            on.append(j)
    for j in on:
        judge=lst[j]
        for k in judge:
            if k[1]==1:
                if not k[0] in on:
                    switch=1
            else:
                if k[0] in on:
                    switch=1
    if switch==0:
        ans=max(ans,len(on))

print(ans)

Solution (Python):
n = int(input())
tst = [[] for i in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        tst[i].append([x,y])
ans = 0
for bit in range(1<<n):
    honest = [0]*n
    check = 1
    for i in range(n):
        if (bit>>i)&1:
            honest[-1-i] = 1
    for i in range(n):
        if not honest[i]:
            continue
        for l in tst[i]:
            if l[1]!=honest[l[0]-1]:
                check = 0
                break
    if check:
        ans = max(ans,sum(honest))
print(ans)

Solution (Python):
n = int(input())
tst = [[] for i in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        tst[i].append([x,y])
ans = 0
for bit in range(1<<n):
    honest = [0]*n
    check = 1
    for i in range(n):
        if (bit>>i)&1:
            honest[-1-i] = 1
    for i in range(n):
        if not honest[i]:
            continue
        for l in tst[i]:
            if l[1]!=honest[l[0]-1]:
                check = 0
                break
    if check:
        ans = max(ans,sum(honest))
print(ans)

Solution (Python):
n = int(input())
tst = [[] for i in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        tst[i].append([x,y])
ans = 0
for bit in range(1<<n):
    liars = [0]*n
    check = 1
    for i in range(n):
        if (bit>>i)&1:
            liars[-1-i] = 1
    for i in range(n):
        if not liars[i]:
            continue
        for l in tst[i]:
            if l[1]!=liars[l[0]-1]:
                check = 0
                break
    if check:
        ans = max(ans,sum(liars))
print(ans)

Solution (Python):
n = int(input())
tst = [[] for i in range(n)]
for i in range(n):
  a = int(input())
  for j in range(a):
    x,y = map(int,input().split())
    tst[i].append([x,y])
ans = 0
for bit in range(1<<n):
  liars = [0]*n
  check = 1
  for i in range(n):
    if (bit>>i)&1:
      liars[-1-i] = 1
  for i in range(n):
    if liars[i]:
      for l in tst[i]:
        if l[1]!=liars[l[0]-1]:
          check = 0
          break
  temp = 0
  if check:
    temp = sum(liars)
  ans = max(ans,temp)
print(ans)

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

output = 0
for combination in range(2 ** n):
    consistent = True
    for index in range(n):
        if (combination >> index) & 1 == 0:
            continue
        for x,y in testimonies[index]:
            if (combination >> x) & 1 != y:
                consistent = False
                break
        if not consistent:
            break
    if consistent:
        output = max(output, bin(combination)[2:].count("1"))
print(output)

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

max_person = 0
for i in range(2**N):
  judge = True
  bin_num = bin(i)
  times = 0
  for j in reversed(bin_num):
    if j == "b":
      break
    if j == "1":
      for k in a[times]:
        if ((i >> k[0]-1) & 1) != k[1]:
          judge = False
    times += 1
  true_person = bin_num.count("1")
  if judge == True:
    max_person = max(max_person, true_person)
print(max_person)

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

max_person = 0
for i in range(2**N):
  judge = True
  bin_num = bin(i)
  times = 0
  end = False
  for j in reversed(bin_num):
    if j == "b":
      break
    if j == "1":
      for k in a[times]:
        if ((i >> k[0]-1) & 1) != k[1]:
          judge = False
    times += 1
  true_person = bin_num.count("1")
  if judge == True:
    max_person = max(max_person, true_person)
print(max_person)