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

honest = 0
for i in range(2 ** N): 
    count = 0
    flag = True
    for j in range(N): 
        if((i >> j) & 1): 
            count += 1
            for k in range(N): 
                if xy[j][k] == -1:
                    continue
                elif ((i >> k) & 1) != xy[j][k]: 
                    flag = False
    if flag:
        honest = max(honest, count)

print(honest)

Solution (Python):
from itertools import combinations, count

n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)
ans = next(i for i in count(n, - 1) for x in map(set, combinations(r, i))
           if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x))
print(ans)

Solution (Python):
from itertools import combinations, count

n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)
ans = next(i for i in count(n, - 1) for x in combinations(r, i)
           if all(a[j][0].isdisjoint(x) and a[j][1].issubset(x) for j in x))
print(ans)

Solution (Python):
import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
data = [[] for i in range(N+1)]

for i in range(N):
  a = I()
  for j in range(a):
    data[i].append(IL())

ans = 0
for i in range(1 << N):
  TF = [-1]*N
  cnt = 0
  for j in range(N):
    if ((i >> j) & 1) == 1: 
      TF[j] = True
      cnt += 1
    else:
      TF[j] = False
  
  for k in range(N):
    if TF[k] == True:
      for x,y in data[k]:
        if TF[x-1] == y:
          continue
        else:
          break
      else:
        continue
      break
  else:
    ans = max(ans, cnt)

print(ans)

Solution (Python):
I=int
i=input
n=I(i())
a=eval('[i().split()for _ in"_"*I(i())],'*n)
print(max(all(I(y)==i>>I(x)-1&1for j,t in enumerate(a)if i>>j&1for x,y in t)*bin(i).count('1')for i in range(1<<n)))

Solution (Python):
from itertools import combinations, count

n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)
r = next(i for i in count(n, - 1) for x in map(set, combinations(r, i))
         if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x))
print(r)

Solution (Python):
import sys

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

def main():
    ans = 0
    for comb in range(2 ** n):
        cnt = 0
        for i in range(n):
            if comb >> i & 1 ^ 1:
                continue
            for x, y in xy[i]:
                if comb >> x & 1 ^ y:
                    break
            else:
                cnt += 1
                continue
            break
        else:
            ans = max(ans, cnt)
    return ans
                
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
i=input
n=int(i())
a=eval('[i().split()for _ in"_"*int(i())],'*n)
print(max(all(int(y)==i>>int(x)-1&1for j,t in enumerate(a)if i>>j&1for x,y in t)*bin(i).count('1')for i in range(2**n)))

Solution (Python):

N = int(input())
A = [0] * N
xy = [[] for _ in range(N)]
for i in range(N):
    A[i] = int(input())
    for j in range(A[i]):
        a,b = list(map(int,input().split()))
        a -= 1
        xy[i].append([a,b])

ans = 0
for i in range(1<<N):
    state = [False] * N
    tmp = i
    for j in range(N):
        state[j] = (tmp%2==1)
        tmp = tmp//2
    
    flag = True
    for j in range(N):
        if state[j]:
            for k in range(A[j]):
                if state[xy[j][k][0]] != xy[j][k][1]:
                    flag = False
                    break
                
            if not flag:
                break
    if flag:
        ans = max(ans,sum(state))
        
print(ans)

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()

input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    a=sorted([random.randint(0,5) for _ in range(n)])[::-1]
    return n,a

show_flg=False
show_flg=True

n=I()
ans=0
c=[[] for i in range(n)]
for i in range(n):
    a=I()
    for j in range(a):
        x,y=LI()
        x-=1
        c[i].append((x,y))

for bit in range(2**n):
    t=[1 if (bit>>i)&1 else 0 for i in range(n)]
    flg=True    
    for i in range(n):
        if t[i]==1:
            for x,y in c[i]:
                if t[x]!=y:
                    flg=False
    if flg:
        ans=max(ans,sum(t))
    
print(ans)

Solution (Python):
import copy

def main():
    n = int(input())

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

    ans = 0
    for bit in range(0, 2**n):
        temp_ans = 0
        flag = True

        temp_table = []
        b = 1
        for i in range(n):
            if b & bit:
                temp_table.append(table[i][:])
                temp_table[-1][i] = 1
                temp_ans += 1
                for j in range(n):
                    temp_j_bit = bit >> j & 1
                    table_i_j = table[i][j]
                    if table_i_j == -1:
                        continue
                    elif temp_j_bit != table_i_j:
                        flag = False
            b <<= 1
        if temp_table and flag:
            temp_table_t = list(zip(*temp_table))
            for j, t in enumerate(temp_table_t):
                if 1 in t and 0 in t:
                    flag = False
        if flag:
            ans = max(ans, temp_ans)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
i=input
n=int(i())
a=eval('[list(map(int,i().split()))for _ in"_"*int(i())],'*n)
print(max(all(y==i>>x-1&1for j,t in enumerate(a)if i>>j&1for x,y in t)*bin(i).count('1')for i in range(2**n)))

Solution (Python):
n = int(input())
a =[0]*n
x = [[0] *n for i in range(n)]
y = [[0] *n for i in range(n)]
ans = []
for i in range(n):
    a[i] = int(input())
    for j in range(a[i]):
        x[i][j],y[i][j] = map(int,input().split())
        x[i][j]-=1
        
ishonest= [-1]*n + [0]
def check(ishonest):
    for i in range(n):
        if not ishonest[i]:continue
        for j in range(a[i]):
            if y[i][j] == 1 and ishonest[x[i][j]] == 0:
                return False
            if y[i][j] == 0 and ishonest[x[i][j]] == 1:
                return False
    return True

def dfs(now,h_or_not= -1):
    ishonest[now] = h_or_not
    if now == n-1:
        if check(ishonest):
      
            return sum(ishonest)+1
        else:
            return 0
  
    return max(dfs(now+1,0),dfs(now+1,1))

print(dfs(-1))

Solution (Python):
def c():
  from math import log2

  def get_ones(n):
    while n:
      k = n & -n
      yield int(log2(k))
      n ^= k

  N = int(input())
  guys = []
  for i in range(N):
    guys.append([])
    A = int(input())
    for j in range(A):
      guys[-1].append(tuple(map(int,input().split())))
  guys = guys[::-1]
  
  ans = 0
  for i in range(2**N):
    cnt = 0
    for j in get_ones(i):
      cnt += 1
      for k in range(len(guys[j])):
        if (int(i & (1 << (N - guys[j][k][0]))) != 0) != guys[j][k][1]:
          break
      else:
        continue
      break
    else:
      ans = max(cnt,ans)
  print(ans)
c()

Solution (Python):
n = int(input())
len_a = [0]*n
x = [0]*n
y = [0]*n
for i in range(n):
    len_a[i]=int(input())
    x[i]=[0]*len_a[i]
    y[i]=[0]*len_a[i]
    for j in range(len_a[i]):
        x[i][j], y[i][j] = map(int,input().split())
ans = 0
for i in range(2**n):
    honest_list = bin(i)[2:].zfill(n)
    honest_all = True
    for j in range(n):
        if honest_list[j]=='1':
            for k in range(len(x[j])):
                if str(y[j][k]) != honest_list[x[j][k]-1]:
                    honest_all = False
                    break
        if honest_all==False:
            break
    if honest_all:
        if ans < str(honest_list).count('1'):
            ans = str(honest_list).count('1')
print(ans)

Solution (Python):
import sys
import numpy as np

n = int(sys.stdin.readline().rstrip())
x = []
y = []
for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    xy = [sys.stdin.readline().split() for _ in range(a)]
    if not xy:
        x.append(None)
        y.append(None)
        continue
    xi, yi = np.array(xy, np.int64).T
    x.append(xi-1)
    y.append(yi)

def main():

    ans = 0
    for comb in range(2 ** n):
        cnt = 0
        for i in range(n):
            if not comb >> i & 1:
                continue
            if x[i] is None:
                cnt += 1
                continue
            if np.count_nonzero(comb >> x[i] & 1 ^ y[i]):
                break
            cnt += 1
        else:
            ans = max(ans, cnt)
    return ans
                
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
import sys
import numpy as np

n = int(sys.stdin.readline().rstrip())
A = []
x = []
y = []
for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    A.append(a)
    if a == 0:
        x.append(None)
        y.append(None)
        continue
    xi, yi = np.array([sys.stdin.readline().split() for _ in range(a)], dtype=np.int64).T
    x.append(xi-1)
    y.append(yi)

def main():
    ans = 0
    for comb in range(2 ** n):
        cnt = 0
        for i in range(n):
            if not comb >> i & 1:
                continue
            if not A[i]:
                cnt += 1
                continue
            if np.count_nonzero(comb >> x[i] & 1 ^ y[i]):
                break
            cnt += 1
        else:
            ans = max(ans, cnt)
    return ans
                
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
A = [0 for _ in range(20)]
x = [[0 for _ in range(20)] for _ in range(20)]
y = [[0 for _ in range(20)] for _ in range(20)]
N = int(input())
for i in range(N):
    A[i] = int(input())
    for j in range(A[i]):
        temp_x, temp_y = map(int, input().split(' '))
        x[i][j] = temp_x
        y[i][j] = temp_y
res = 0
for i in range(2 ** N):
    flg = True
    for j in range(N):        
        if(not ((i >> j) & 1)): continue
        for a in range(A[j]):
            if(((i >> (x[j][a] - 1)) & 1) ^ y[j][a]):
                flg = False        
    if(flg):
        res = max(res, str(bin(i)).count('1'))
            
print(res)

Solution (Python):
import sys
input = sys.stdin.readline
N, = map(int, input().split())
rs = []
for _ in range(N):
    A, = map(int, input().split())
    ts, fs = set(), set()
    for _ in range(A):
        x, y = map(int, input().split())
        if y:
            ts.add(x-1)
        else:
            fs.add(x-1)
    rs.append((ts, fs))
r = 0
for i in range(2**N):
    ok = True
    c = 0
    for j in range(N):
        if (i>>j) % 2:
            for t in rs[j][0]:
                if not (i>>t) % 2:
                    ok = False
            for t in rs[j][1]:
                if (i>>t) % 2:
                    ok = False
            c += 1
    if ok:
        r = max(r, c)
print(r)

Solution (Python):
import sys
input = sys.stdin.readline
N, = map(int, input().split())
rs = []
for _ in range(N):
    A, = map(int, input().split())
    ts, fs = set(), set()
    for _ in range(A):
        x, y = map(int, input().split())
        if y:
            ts.add(x-1)
        else:
            fs.add(x-1)
    rs.append((ts, fs))
r = 0
for i in range(2**N):
    i = i+2**N
    bi = bin(i)[3:]
    ok = True
    for j in range(N):
        if int(bi[j]):
            for t in rs[j][0]:
                if not int(bi[t]):
                    ok = False
            for t in rs[j][1]:
                if int(bi[t]):
                    ok = False
    if ok:
        r = max(r, bi.count("1"))
print(r)

Solution (Python):
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    A = [[] for _ in range(N)]
    for i in range(N):
        for _ in range(inputInt()):
            A[i].append(inputIntList())
    ret = 0
    for i in range(2 ** N):
        bits = [i >> j & 1 for j in range(N)]
        for i, a in enumerate(A):
            if bits[i] == 0:
                continue
            for x, y in a:
                
                if bits[x - 1] == y:
                    continue
                break
            else:
                continue
            break
        else:
            ret = max(ret, sum(bits))
    return ret


if __name__ == "__main__":
    print(main())

Solution (Python):
import sys


n = int(sys.stdin.readline().rstrip())
xy = [[] for _ in range(n)]

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






def main():
    ans = 0
    for comb in range(2 ** n):
        cnt = 0
        ok = True
        for i in range(n):
            if not comb >> i & 1:
                continue
            for x, y in xy[i]:
                if comb >> x & 1 ^ y:
                    ok = False
                    break
            if ok:
                cnt += 1
            else:
                break
        else:
            ans = max(ans, cnt)
    return ans
                
if __name__ == '__main__':
    ans = main()
    print(ans)

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

import itertools
import numpy as np

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

A = np.array(list(itertools.product([0,1],repeat=N)),np.bool)

for i in range(N):
    for x,y in XY[i]:
        bl = (~A[:,i]) | ((A[:,x]) == bool(y))
        A = A[bl]

answer = A.sum(axis = 1).max()
print(answer)

Solution (Python):
N = int(input())
A = [[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, a in enumerate(A):
        if bits[i] == 0:
            continue
        for x, y in a:
            if bits[x - 1] == y:
                continue
            flag = False
    if flag:
        res = max(res, sum(bits))

print(res)

Solution (Python):
import re
n=int(input())
A=[]
for i in range(n):
    B=["."]*n
    for x,y in [list(map(int,input().split())) for k in range(int(input()))]:
        B[x-1]=str(y)
    A.append("".join(B))
ans=0
for i in range(2**n):
    num=format(i,"b").zfill(n)
    cnt,flag=0,1
    for k,j in enumerate(num):
        result=re.search(r"".join(A[k]),num)
        if result is not None and j=="1":
            cnt +=1
        elif (result is not None and j=="0") or (result is None and j=="1"):
            flag=0
            break
    if flag:ans=max(ans,cnt)
print(ans)

Solution (Python):
import re
n=int(input())
A=[]
for i in range(n):
    B=["."]*n
    for x,y in [list(map(int,input().split())) for k in range(int(input()))]:
        B[x-1]=str(y)
    A.append("".join(B))
ans=0
for i in range(2**n):
    num=format(i,"b").zfill(n)
    cnt,flag=0,1
    for k,j in enumerate(num):
        result=re.search(r"".join(A[k]),num)
        if result is not None and j=="1":
            cnt +=1
        elif (result is not None and j=="0") or (result is None and j=="1"):
            flag=0
            break
    if flag:
        ans=max(ans,cnt)
print(ans)

Solution (Python):
import re
n=int(input())
A=[]
for i in range(n):
    B=["."]*n
    for x,y in [list(map(int,input().split())) for k in range(int(input()))]:
        B[x-1]=str(y)
    A.append("".join(B))
ans=0
for i in range(2**n):
    num=format(i,"b").zfill(n)
    cnt,flag=0,1
    for k,j in enumerate(num):
        result=re.search(r"".join(A[k]),num)
        if result is not None and j=="1":
            cnt +=1
        elif (result is not None and j == "0") or (result is None and j == "1"):
            flag=0
            break
    if flag:
        ans=max(ans,cnt)
print(ans)

Solution (Python):
import re
n=int(input())
A=[]
for i in range(n):
    B=["."]*n
    for x,y in [list(map(int,input().split())) for k in range(int(input()))]:
        B[x-1]=str(y)
    A.append("".join(B))
ans=0
for i in range(2**n):
    num=format(i,"b").zfill(n)
    cnt,flag=0,1
    for k,j in enumerate(num):
        result=re.search(r"".join(A[k]),num)
        if result!=None and j=="1":
            cnt +=1
        elif (result!=None and j=="0") or (result==None and j=="1"):
            flag=0
            break
    if flag:
        ans=max(ans,cnt)
print(ans)

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


res = 0
for bit in range(2**n):
    for i in range(n):
        if bit & (1 << i):
            for x, y in a[i]:
                if (bit >> x-1) & 1 != y:
                    break
            else:
                continue
            break
    else:
        res = max(res, bin(bit).count('1'))

print(res)

Solution (Python):
from itertools import combinations

n = int(input())
l = (1 << n) - 1
r = range(n)
a = [[0, 0] for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y] |= 1 << x - 1

def fail(x):
  x = sum(1 << i for i in x)
  return not all(a[i][0] & x == a[i][1] & l - x == 0 for i in r if x >> i & 1)

while all(map(fail, combinations(r, n))):
  n -= 1
print(n)

Solution (Python):
from itertools import combinations
 
n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)
 
fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1] < x for i in x)
 
while all(map(fail, map(set, combinations(r, n)))):
  n -= 1
print(n)

Solution (Python):
def popcount(x):
  r = 0
  while x:
    if x & 1:
      r += 1
    x >>= 1
  return r

n = int(input())
r = range(n)
a = [[0, 0] for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y] |= 1 << (x - 1)

m = 0
l = (1 << n) - 1
for x in range(1, l + 1):
  if all(a[i][0] & x == a[i][1] & l - x == 0 for i in r if x >> i & 1):
    m = max(m, popcount(x))
print(m)

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


for k in range(1 << n):
    ev = [0]*n
    for l in range(n):
        if (k >> l) & 1:
            ev[l] = 1
    
    f = True
    for p,q in enumerate(xy_l):  
        if ev[p]:
            for r in q:  
                if r[1] != ev[r[0] - 1]:
                    f = False
    if f:
        cnt = max(cnt, ev.count(1))

print(cnt)

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

def mujunsearch(n,n15,wrd):
    cnt = 0
    s = {}
    for i in range(n):
        if(n15>>i&1) == 1:
            cnt += 1
            for j in wrd[i]:
                x = j[0]
                y = j[1]
                if s.get(x,y) != y:
                    return 0
                else:
                    s[x] = y
    for i in range(n):
        if(n15>>i&1) == 0:
            if s.get(i+1,0) == 1:
                return 0
        else:
            if s.get(i+1,1) == 0:
                return 0
    
    
    return cnt

st = 0
for i in range(1<<n):
    st = max(st,mujunsearch(n,i,wrd))
print(st)

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

ans = 0
for i in range(1 << N):
    chk = []
    for j in range(N):
        if ((i >> j) & 1):
            chk.append(1)
        else:
            chk.append(0)
    for a, x, y in lst:
        if ((i >> a) & chk[a]):
            if chk[x] ^ y:
                chk = [0] * N
                break
    ans = max(ans, sum(chk))

print(ans)

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

messages = [[] for i in range(n)]

for i in range(n):
    num = int(input())

    for j in range(num):
        person, truth = map(int, input().split())
        messages[i].append([person-1, truth])

ans = 0
for i in range(2**n):
    check = i
    count = sum([(check >> t) & 1 for t in range(n)])
    if count <= ans:
        continue
    possible = True
    for k in range(n):
        if (check >> k) & 1:  
            message = messages[k]

            for person, truth in message:
                if (check>>person)&1 == truth:
                    continue
                else:
                    possible = False
                    break
        else:  
            continue

        if not possible:
            break

    if possible:
        ans = max(ans, count)

print(ans)

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

bN = 2**N
ans = 0
for b in range(bN):
    lis = [int(("00000000000000"+bin(b)[2:])[-1-i]) for i in range(N)]
    
    for n,l in enumerate(lis):
        
        if l:
            for x,y in xy[n]:
                if y != lis[x-1]:
                    break
            else:
                continue
            break
    else:
        ans = max(ans,lis.count(1))
print(ans)

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

ans = 0
for i in range(1 << n):
    ok = True
    cnt = 0
    t = [-1] * n
    for j in range(n):
        if (i & (1 << j)) and ok:
            if t[j] == -1:
                t[j] = 1
            elif t[j] == 0:
                ok = False
                break
            cnt += 1
            for k in range(a[j]):
                if t[x[j][k]] == -1:
                    t[x[j][k]] = y[j][k]
                elif t[x[j][k]] != y[j][k]:
                    ok = False
                    break
        else:
            if t[j] == -1:
                t[j] = 0
            elif t[j] == 1:
                ok = False
                break
    if ok:
        ans = max(ans, cnt)
        

print(ans)

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

bN = 2**N
ans = 0
for b in range(bN):
    for n in range(N):
        if (b >> n) & 1:
            for x,y in xy[n]:
                if y != (b >> (x-1) & 1):
                    break
            else:
                continue
            break
    else:
        ans = max(ans,bin(b).count("1"))
print(ans)

Solution (Python):
n = int(input())
XY = []
ans = 0
for i in range(n):
  a = int(input())
  XY.append([])
  for j in range(a):
    XY[i].append(list(map(int,input().split())))
for i in range(2**n):
  i = format(i, 'b')
  i = i.zfill(n)
  temp = i.count("1")
  temp2 = 0
  for j in range(n):
    if i[j] == "1":
      for k in range(len(XY[j])):
        if str(XY[j][k][1]) != i[XY[j][k][0]-1]:
          temp2 = 1
          break
  if temp2 == 0:
    if ans < temp:
      ans = temp
print(ans)

Solution (Python):




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




























max_num = 0
for i in range(2**N): 
    res=True
    i = str(bin(i))[2:]
    i=i.zfill(N)
    for l,a in enumerate(A):
        flag=bool(int(i[l]))
        if flag: 
            for k,ai in enumerate(a):
                if not str(ai[1]) == i[ai[0]-1]:
                    res = False
                    break
        if not res: 
            break
    if res:
        res_list = list(map(int,i))
        max_num = max(max_num, sum(res_list))

print(max_num)

Solution (Python):
def solve():
  n = int(input())
  query = [0]*n
  for i in range(n):
    a = int(input())
    tmp = []
    for j in range(a):
       x,y = (int(_) for _ in input().split())
       tmp.append((x-1,y))
    query[i] = tmp

  ans = 0
  for bit in range(1,2**n):
    bitsum = 0
    tmp = [0]*n
    for j in range(n):
      if bit>>j&1 == 1:
        bitsum += 1
        tmp[j] = 1
    ispossible = True
    for j in range(n):
      if tmp[j] == 1:
        check = query[j]
        
        for x,y in check:
          if tmp[x] == y:
            continue
          else:
            ispossible = False
    if ispossible:
      ans = max(ans,bitsum)
  print(ans)
        
        
solve()

Solution (Python):
N = int(input())
E = []
for n in range(N):
    A = int(input())
    for _ in range(A):
        x, y = list(map(int, input().split()))
        E.append((n, x - 1, y))
ans = 0
for k in range((1 << N) - 1, -1, -1):
    status = [(k >> i) & 1 for i in range(N)]
    no_paradox = True
    for Xa, Xb, yb in E:
        if (status[Xa] == 1 and status[Xb] != yb):
            no_paradox = False
            break
    if no_paradox:
        ans = max(ans, sum(status))
print(ans)

Solution (Python):
N = int(input())
L = []
for i in range(N):
  A = int(input())
  LA = []
  for j in range(A):
    LA.append(list(map(int,input().split())))
  L.append(LA)
cnt = 0

for i in range(2**N):
  flg = True
  for j in range(len(L)):
    
    
    for x,y in L[j]:
      
      
      
      if (i >> j) & 1 == 1:
        if i>>(x-1) & 1 !=y:
          flg = False
          break
  if flg:
    cnt = max(cnt,bin(i).count('1'))
print(cnt)

Solution (Python):
N = int(input())
L = []
for i in range(N):
  A = int(input())
  LA = []
  for j in range(A):
    LA.append(list(map(int,input().split())))
  L.append(LA)
from itertools import product
LL = list(product(range(2), repeat=N))
cnt = 0
for i in LL:
  flg = True
  for j in range(len(L)):
    
    
    for x,y in L[j]:
      
      
      
      if i[j]==1:
        if i[x-1]!=y:
          flg = False
          break
  if flg:
    cnt = max(cnt,sum(i))
print(cnt)

Solution (Python):
N = int(input())
graph = []
for _ in range(N):
  A = int(input())
  row = []
  for j in range(A):
    x,y = map(int,input().split())
    row.append([x,y])
  graph.append(row)

res = 0
for state in range(2**N):
  for person in range(N):
    if (state >> person) & 1:
      for x, y in graph[person]:
        x -= 1
        if (state >> x & 1) != y:
          break
      else:
        continue
      break
  else:
    res = max(res, bin(state).count('1'))
print(res)

Solution (Python):
N = int(input())
A = []
W = [[] for i in range(N)]
for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        a, b = input().split()
        W[i].append((int(a) - 1, int(b)))

L = 2 ** N
max_cnt = 0
for G in range(L):
    n = 0
    ok = True
    while n < N:
        if G & (1 << n) > 0:
            for i in range(A[n]):
                no = W[n][i][0]
                hl = W[n][i][1]
                c = 1 << no
                if (c & G > 0 and hl == 0) or (c & G == 0 and hl == 1):
                    ok = False
                    break

            if not ok:
                break
        n += 1
    if ok:
        cnt = bin(G)[2:].count('1')
        max_cnt = max(cnt, max_cnt)

print(max_cnt)

Solution (Python):
N = int(input())
A = []
W = [[] for i in range(N)]
for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        a, b = input().split()
        W[i].append((int(a) - 1, int(b)))

L = 2 ** N
max_cnt = 0
for G in range(L):
    b = 1
    n = 0
    ok = True
    while n < N:
        if G & b > 0:
            for i in range(A[n]):
                no = W[n][i][0]
                hl = W[n][i][1]
                c = 1 << no
                if (c & G > 0 and hl == 0) or (c & G == 0 and hl == 1):
                    ok = False
                    break

            if not ok:
                break
        b <<= 1
        n += 1
    if ok:
        cnt = bin(G)[2:].count('1')
        max_cnt = max(cnt, max_cnt)

print(max_cnt)