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())
 
testimony = [[] for _ in range(N)]
 
for i in range(N):
    n = int(input())
    for _ in range(n):
        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):
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
from fractions import gcd

NN = 202020
MOD = 10**9+7
INF = float("inf")

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


max_honest = 0
for num in range(1 << n):
    valid = True
    for p in range(n):
        if num >> p & 1:
            for k, v in testi[p].items():
                
                if v ^ ((num >> k) & 1):
                    valid = False
                    break
        if not valid:
            break

    if valid:
        
        max_honest = max(max_honest, bin(num)[2:].count("1"))

print(max_honest)

Solution (Python):


import sys







from itertools import product                






def main():
    mod = 10000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    

    def check_no_contradict(case):
        for i, person in enumerate(case):
            if person == 1:
                for comment in comments[i]:
                    if case[comment[0]] != comment[1]:
                        return False
        return True


    n = ii()
    comments = [[] for _ in range(n)]
    for i in range(n):
        num = ii()
        for _ in range(num):
            a, b = mi()
            comments[i].append(tuple([a-1, b]))
    
    ans = 0
    for case in product([0, 1], repeat=n):
        if check_no_contradict(case):
            
            ans = max(ans, case.count(1))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

N = int(input())
XY = []
for _ in range(N):
    A = int(input())
    tmp = []
    for __ in range(A):
        tmp.append(list(map(int, input().split())))
    XY.append(tmp)
ans = 0


def judge(bit):
    for i in range(N):
        tmp = XY[i]
        if((bit >> i) & 1 == 1):
            for j in tmp:
                
                x = j[0] - 1 
                y = j[1]    

                

                if(y == 1 and (~bit) & (1 << x)):
                    return False
                
                if((y == 0) and bit & (1 << x)):
                    return False
    return True


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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools

n = int(readline())
s = [[] for i in range(n)]
u = [[] for j in range(n)]
for j in range(n):
    a = int(readline())
    for k in range(a):
        x, y = map(int, readline().split())
        if y == 1:
            s[j].append(x)
        else:
            u[j].append(x)
bit = list(itertools.product([0, 1], repeat=n))
ans = 0
for i in range(2 ** n):
    flag = True
    memo = []
    check_s = []
    check_u = []
    for j in range(n):
        if bit[i][j] == 1:
            memo.append(j + 1)
            check_s += s[j]
            check_u += u[j]
    if len(set(check_u) & set(memo)) == 0:
        for j in range(len(check_s)):
            if (check_s[j]) not in memo:
                flag = False
        if flag:
            ans = max(ans, len(memo))
print(ans)

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

def is_valid(nn,p):
	if not (nn>>p)&1:
		return True
	for talk in z[p]:
		if not (nn>>(talk[0]-1))&1 == talk[1]:
			return False
	return True	

def num_true(nn):
	sum = 0
	while nn:
		sum += nn%2
		nn //=2
	return sum
ans = 0
for nn in range(1<<n):
	for p in range(n):
		if not is_valid(nn,p):
			break
		if p == n-1:
			ans = max(ans,num_true(nn))
print(ans)

Solution (Python):
import sys
N = int(sys.stdin.readline())

testimonies = [[-1 for _ in range(N)] for _ in range(N)]
for i in range(N):
    A = int(sys.stdin.readline())
    for _ in range(A):
        x, y = map(int, sys.stdin.readline().rstrip().split())
        testimonies[i][x-1] = y

def check(honest_persons):
    flag = True
    for i in range(N):
        if honest_persons[i]:
            for j in range(N):
                if testimonies[i][j] == -1:
                    continue
                if testimonies[i][j] != honest_persons[j]:
                    flag = False
                    break
            else:
                continue
            break
    return flag

def main():
    ans = 0
    for i in range(1, 2**N):
        honest_persons = bin(i)[2:].zfill(N)
        honest_persons = list(map(int, list(honest_persons)))

        if check(honest_persons):
            ans = max(ans, sum(honest_persons))

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
N = int(sys.stdin.readline())

testimonies = [[-1 for _ in range(N)] for _ in range(N)]
for i in range(N):
    A = int(sys.stdin.readline())
    for _ in range(A):
        x, y = map(int, sys.stdin.readline().rstrip().split())
        testimonies[i][x-1] = y

def check(honest_persons):
    flag = True
    for i in range(N):
        if honest_persons[i]:
            for j in range(N):
                if testimonies[i][j] == -1:
                    continue
                if testimonies[i][j] != honest_persons[j]:
                    flag = False
                    break
    return flag

def main():
    ans = 0
    for i in range(1, 2**N):
        honest_persons = bin(i)[2:].zfill(N)
        honest_persons = list(map(int, list(honest_persons)))

        if check(honest_persons):
            ans = max(ans, sum(honest_persons))

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
g = list([-1] * n for _ in range(n))
ans = 0



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

for i in range(2**n):
    d = [0]*n
    for j in range(n):     
        if((i>>j)&1):
            d[n-1-j] = 1
            

    
    ok = True
    for j in range(n):
        if d[j]:
            for k in range (n):
                if g[j][k] == -1: continue
                if g[j][k] != d[k]: ok = False
    if ok: ans = max(ans,bin(i).count("1"))
print(ans)

Solution (Python):
n=int(input())
l=[0]*n
A=[]
for i in  range(0,n):
    l[i]=int(input())
    A.append([[0,0] for i in range(l[i])])
    for j in range(l[i]):
        A[i][j][0],A[i][j][1]=map(int,input().split())
count=0
for i in range(0,2**n):
    count1=0
    for j in range(n):
        if (i>>(n-j-1))&1:
            count1=count1+1
        for m in range(l[j]):
            if  (i>>(n-j-1))&1:
                if A[j][m][1]!=(i>>(n-A[j][m][0]))&1:
                    break
        else:
            continue
        break
    else:
        if count1>count:
            count=count1
print(count)

Solution (Python):
N = int(input())
A = [0]*N
testi = []
assume = 2**N-1
ans = 0

for i in range(N):
    A[i] = int(input())
    if A[i] == 0:
        testi.append(-1)
    else:
        testi.append([list(map(int, input().split())) for _ in range(A[i])])

while(assume):
    flag = True
    for i in range(N):
        if assume & (2**i) != 0 and testi[i] != -1:
            for j in testi[i]:
                if j[1] != ((assume & (2**(j[0]-1))) >> (j[0]-1)):
                    flag = False
                    break
        
        if not flag:
            break
    
    if flag:
        tmp = bin(assume).count('1')
        if tmp > ans:
            ans = tmp
    assume -= 1
    

print(ans)

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

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

bit = '0' + str(n) + 'b'

cnt = 0
for i in range(2 ** n):
    people = [int(peo) for peo in list(format(i, bit))]
    flg = False
    
    for j in range(n):
        if people[j] == 0:
            continue
        for k in range(n):
            if xy[j][k] == -1:
                continue
            if xy[j][k] != people[k]:
                flg = True
                break
        
        if flg:
            break
        
    if flg:
        continue
    else:
        cnt = max(cnt, sum(people))
    
print(cnt)

Solution (Python):
n=int(input())
link=[[] for _ in range(n)]
for i in range(n):
    for j in range(int(input())):
        a,b=map(int,input().split())
        link[i].append([a-1,b])
def bitj(bit):
    for i in range(n):
        if not (bit>>i)&1:
            continue
        for x,y in link[i]:
          if y==1 and not (bit>>x)&1:
            return False
          elif y==0 and (bit>>x)&1:
            return False
    return True
ans=0
for i in range(1<<n):
    if not bitj(i):
        continue
    res=0
    for j in range(n):
        if (i>>j)&1:
            res+=1
    ans=max(ans,res)
print(ans)

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


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

    print(ans)
main()

Solution (Python):




def main():
    N = int(input())
    g = [[-1]*N for _ in range(N)]

    for i in range(N):
        A = int(input())
        
        for a in range(A):
            x, y = map(int, input().split())
            g[i][x-1] = y
    
    ans = 0
    for i in range(2**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] == 1:
                for k in range(N):
                    if g[j][k] == -1:
                       continue 
                    if g[j][k] != d[k]:
                        ok = False
        if ok:
            ans = max(ans, bin(i).count('1'))
    
    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect



import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  info = []
  for i in range(n):
    a = int(readline())
    for _ in range(a):
      x, y = map(int, readline().split())
      info.append((i, x-1, y))
  A = np.array(list(product([0,1], repeat=n)),np.bool)
  for i, x, y in info:
    bl = (~A[:,i]) | (A[:,x]==bool(y))
    A = A[bl]
  print(A.sum(axis=1).max())
  
  
  
if __name__ == '__main__':
  main()

Solution (Python):
def judge(bit, n, v):
    
    for i in range(n):
        
        if not (bit & (1 << i)):
            continue

        for x, y in v[i]:
            
            if y == 1 and not (bit & (1 << x)):
                return False

            
            if y == 0 and (bit & (1 << x)):
                return False
    return True


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

ans = 0
for bit in range(1 << n):
    if not judge(bit, n, v):
        continue

    
    cnt = 0
    for i in range(n):
        if bit & (1 << i):
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n = int(input())
    l = [[-1]*n for _ in range(n)]
    for i in range(n):
        a = int(input())
        for _ in range(a):
            x,y = map(int, input().split())
            l[i][x-1] = y
    
    res = 0
    for s in range(1<<n):
        flag = 1
        check = [-1]*n
        
        for i in range(n):
            
            if (s>>i) & 1:
                
                for j in range(n):
                    if i==j:
                        continue
                    if l[i][j] == -1:
                        continue
                    if check[j] == -1:
                        check[j] = l[i][j]
                    else:
                        if check[j] != l[i][j]:
                            flag = 0
            
            
            
            
            
            
            
            
            
            
            
            
            
            if flag==0:
                break
        else:
            for i in range(n):
                if check[i] == -1:
                    continue
                if ((s>>i)&1) != check[i]:
                    break
            else:
                res = max(res, bin(s).count('1'))
    print(res)

if __name__ == '__main__':
    main()

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

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

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

N = int(input())
A = []
[A.append([]) for _ in range(N)]

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

maxT = 0

for i in range(2**N ):
    ju = [0] * N
    ind = 0

    trust = 0
    for b in reversed(str(bin(i))[2::]):
        if b == "1":
            ju[ind] = 1
            trust += 1
        ind += 1
    
    flag = 0
    for n in range(N):

        if ju[n] == 0:
            continue

        for  y in A[n]:
            if ju[y[0]-1] != y[1]:
                flag = 1
                break
        
        if flag == 1:
            break
        
    if flag == 0:
        maxT = max(maxT , trust )

print(maxT)

Solution (Python):
n = int( input() )
l = [[]] * n
for i in range( n ):
  a = int( input() )
  k = [ -1 ] * n
  for _ in range( a ):
    x, y = map( int, input().split() )
    k[ x - 1 ] = y
  l[ i ] = k

ret = 0
for i in range( 2 ** n - 1, 0, -1 ):
  o = [int(i) for i in str( "{:b}".format(i).zfill(n) )]
  is_right = True
  for j in range( n ):
    for m in range( n ):
      if o[j] == 1:
        is_right &= ( l[j][m] in [-1, o[m]] )
    if not is_right:
      break
        
  if is_right:
    ret = sum(o)
    break
          
print( ret )

Solution (Python):
from itertools import product

N = int(input())
input_table = list([-1] * N for _ in range(N))
ans = 0

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
        input_table[i][x_i_j] = y_i_j

for pat in product((0, 1), repeat = N):
    for i in range(N):
        if pat[i] == 1:
            for j in range(N):
                i_says_j_is_kind = input_table[i][j]
                if i_says_j_is_kind == -1:
                    continue
                else:
                    if i_says_j_is_kind != pat[j]:
                        break
            else:
                continue
            break
    else:
        honest_persons = sum(pat)
        ans = max(ans, honest_persons)

print(ans)

Solution (Python):
n,ans=int(input()),0
xy=[[list(map(int,input().split())) for _ in range(int(input()))] for _ in range(n)]
for i in range(2**n):
  f=True         
  for j in range(n):
    if (i>>j)&1:    
      for x,y in xy[j]:
        if (i>>(x-1))&1!=y:
          f=False
          break
  if f: 
    ans=max(ans,bin(i)[2:].count('1'))     
print(ans)

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


ans = 0
for S in range((1 << N)):
    is_conflict = False
    bitcount = 0
    for i in range(N):
        if ((S >> i) & 1) == 1:
            
            bitcount += 1
            for ev in evidencies[i]:
                
                is_conflict |= ((S >> ev[0]) & 1) ^ ev[1]
    if not is_conflict:
        ans = max(bitcount, ans)

print(ans)

Solution (Python):













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


























lists = {i : 0 for i in range(1 << 15)}
for i in range(1 << 15):
    count = 0
    for j in range(n):
        if (i >> j) & 1:
            for x, y in shogens[j]:
                if y == 0 and (i >> x) & 1: count -= 1
                if y == 1 and not (i >> x) & 1: count -= 1
    if count == 0:
        ans = 0
        for k in range(n):
            ans += (i >> k) % 2
        lists[i] = ans

print(max(lists.values()))

Solution (Python):
n=int(input())
a=[0]*n
x=[[0]*n for i in range(n)]
y=[[0]*n for i in range(n)]
for i in range(n):
  a[i]=int(input())
  for j in range(a[i]):
    x[i][j],y[i][j]=map(int,input().split())
ans=0
for bit in range(1<<n):
  res=True
  for i in range(n):
    if bit & (1<<i):
      for j in range(a[i]):
        if ((bit>>(x[i][j]-1))&1)^y[i][j]:
          res=False
  if res:
    wklen=len(str(format(bit,"b")).replace("0",""))
    ans = ans if ans>=wklen else wklen
print(ans)

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


OK=[]
for i in range(2**N):
    conflict=0
    for person in range(N): 
        for one_state in state[person]:
            if ((i >> (one_state[0]-1)) & 1): 
                if (i >> person) & 1 and one_state[1] == 0:
                    conflict=1
            else: 
                if (i >> person) & 1 and one_state[1]==1:
                    conflict=1
    if conflict==0:
        OK.append(i)


num=[]
for el in OK:
    count=0
    for j in range(N):
        if (el >> j) & 1:
            count+=1
    num.append(count)

print(max(num))

Solution (Python):
import itertools as it

n = int(input())
lis = [[] for _ in range(n)]
val = list(it.product([0, 1], repeat=n))

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


def honesty(k, lis, n):
    for i in range(n):
        if k[i] == 1:
            for l, m in lis[i]:
                if k[l] != m:
                    return False
    return True


res = 0
for k in val:
    if honesty(k, lis, n):
        res = max(res, sum(k))
print(res)

Solution (Python):
n = int(input())
t = [[] for _ in range(n)]
s = [[] for _ in range(n)]

for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        if y == 1:
            t[i].append(x - 1)
        else:
            s[i].append(x - 1)
res = 0
for k in range(pow(2, n)):
    judge = True
    cnt = 0
    for i in range(n):
        if (k >> i) & 1 == 1:
            for e in t[i]:
                if (k >> e) & 1 == 0:
                    judge = False
            for e in s[i]:
                if (k >> e) & 1 == 1:
                    judge = False
            cnt += 1
    if judge:
        res = max(res, cnt)

print(res)

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


ans = 0
for i in range(1<<N):
    cond = [0] * N
    for j in range(N):
        if 1&(i>>j):
            cond[j] = 1
    
    mujun = False
    for j in range(N):
        if cond[j] == 1:
            for k in range(A[j]):
                if cond[rel[j][k][0]-1] != rel[j][k][1]:
                    mujun = True
    
    if not mujun:
        if ans < sum(cond):
            ans = sum(cond)

print(ans)

Solution (Python):
import sys
import numpy as np
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
XY = [[] for _ in range(N)]
for i in range(N):
    a = ir()
    for j in range(a):
        x, y = lr()
        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 = np.sum(A, axis=1).max()
print(answer)

Solution (Python):
import itertools

N=int(input())
testimony=[]
for i in range(N):
    a=int(input())
    l=[]
    for j in range(a):
        l2=[int(k) for k in input().split()]
        l.append(l2)
    testimony.append(l)

nums=[0,1]
kind=itertools.product(nums,repeat=N)

def is_corect_kind(k,testimony,N):
    for i in range(N):
        if k[i]==1:
            for t in testimony[i]:
                if k[t[0]-1]!=t[1]:
                    return False
    return True

answer=0
for k in kind:
    if is_corect_kind(k,testimony,N):
        answer=max(answer,sum(k))
print(answer)

Solution (Python):
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

answer = 0
N = ir()
honest = [[] for _ in range(N+1)]
liar = [[] for _ in range(N+1)]

for i in range(N):
    a = ir()
    for _ in range(a):
        x, y = lr()
        if y == 1:
            honest[i].append(x-1)
        else:
            liar[i].append(x-1)

for bit in range(1<<N):
    bl = True
    h = []
    for i in range(N):
        if (bit >> i) & 1:
            h.append(i)
    s = set(h)
    for person in h:
        for x in honest[person]:
            if x not in s:
                bl = False
                break
        for y in liar[person]:
            if y in s:
                bl = False
                break
        if not bl:
            break
    if bl:
        answer = max(answer, len(s))

print(answer)

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

ans = 0
for i in range(1,2**n):
    ls = [0] * n
    
    for j in range(n):
        if (i >> j) & 1:
            ls[j] = 1
            
    fl = 1
    for j in range(n):
        for k,l in s[j]:
            if ls[j] == 1:
                if ls[k] != l:
                    fl = 0
    if fl == 1:
        ans = max(ans , sum(ls))
    
print(ans)

Solution (Python):
n=int(input())
a=[[] for _ in range(n)]
for i in range(n):
    cnt=int(input())
    while cnt>0:
        x,y=map(int,input().split())
        x-=1
        a[i].append([x,y])
        cnt-=1
ans=0
for mask in range(1<<n):
    
    
    honest=[]
    for j in range(n):
        if (mask>>j)&1:
            honest.append(j)
    choice=True
    for i in honest:
        for j in a[i]:
            if (j[0] in honest and j[1]==0) or (j[0] not in honest and j[1]==1):
                choice=False
                break
        if choice==False:
            break
    if choice:
        ans=max(ans,len(honest))
print(ans)

Solution (Python):

n = int(input())
a = [0] * (n+1)
x = [[0] * (n+1) for _ in range(n+1)]
y = [[0] * (n+1) for _ in range(n+1)]

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


import itertools
seq = [0, 1]
arr = itertools.product(seq, repeat=(n))



ans = [0]
for v in arr:
    v = [0] + list(v)
    
    flag = True
    
    for i in range(1, n+1):
        if v[i] == 1:
            for k in range(1,a[i]+1):
                if y[i][k] == 1 and v[x[i][k]] == 0:
                    flag = False
                if y[i][k] == 0 and v[x[i][k]] == 1:
                    flag = False
                          
    
    if flag:
        ans.append(sum(v))



print(max(ans))

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

talk = []
for i in range(n):
    a = int(input())
    talk += [[list(map(int,input().split())) for _ in range(a)]]
    
ans = 0
    
for i in range(2 ** n):
    result = [True] * n
    
    for j in range(n):
        if ((i >> j) & 1):
            result[n - 1 -j] = False
    check = 1       
    for k in range(n):
        for x, y in talk[k]:
            if result[k] == True:
                if result[x-1] == y:
                    continue
                else:
                    check = 0
                    break
        else:
            continue
        break
    
    if check == 1:
        ans = max(ans, sum(result))
            
print(ans)

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

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



ls = [-1]*n
ans = 0

for i in range(2**n):
    b = str(bin(i))[2:]
    c = b.zfill(n)
    
    numbers = sum(list(map(int,list(str(c)))))
    for j in range(n):
        if c[j]=="0":
            pass
        else:
            for k in range(a[j]):
                x = xy[j][k][0]
                y = xy[j][k][1]
                
                if c[x-1]==str(y):
                    pass
                else:
                    numbers = 0
        
    ans = max(ans,numbers)
    

print(ans)

Solution (Python):
n=int(input())
men=[0]*(n+1)
sta=[[[0]]]
for i in range(1,n+1):
  men[i]=int(input())
  xy=[list(map(int,input().split())) for j in range(men[i])]
  sta.append(xy)
ho=0
for bi in range(2**n):
  honest=[-1]*(n+1)
  honest[0]=0
  x=format(bi,'b')
  x='0'*(n-len(x)+1)+x
  ok='Yes'
  for i in range(1,n+1):
    if x[i]=='1':
      for j in range(men[i]):
        if sta[i][j][1]!=int(x[sta[i][j][0]]):
          ok='No'
  if ok=='Yes':
    ho=max(ho,x.count('1'))

print(ho)

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

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


ans=0
for i in range(2**N):
  ok=True
  for j in range(N):
    if (i>>j&1)==1:
      for k in range(N):
        if A[j][k]!=-1 and (i>>k&1)!=A[j][k]:
          ok=False
  if ok:
    ans=max(ans, bin(i).count("1"))
  
print(ans)

Solution (Python):
N=int(input())
shougen=[(0,0) for i in range(0,N)]
for i in range(0,N):
    A=int(input())
    honest=0
    unkind=0
    for j in range(0,A):
        x,y=map(int,input().split())
        if y==0:
            unkind+=2**(x-1)
        else:
            honest+=2**(x-1)
    shougen[i]=(honest,unkind)

ans=0
for i in range(0,2**N):
    honest=i
    unkind=2**N-1-i
    check=True
    test=0
    for j in range(0,N):
        if (i>>j)&1 ==1:
            test+=1
            x,y=shougen[j]
            if (honest-x)^x!=honest or (unkind-y)^y!=unkind:
                check=False
    if check:
        if test>ans:
            ans=test

print(ans)

Solution (Python):
from itertools import product
N=int(input())
data=[]
for i in range(N):
    for j in range(int(input())):
        x,y=map(int,input().split())
        data.append((i,x-1,y))
ans=0
for i in product([1,0],repeat=N):
    s=True
    for k in data:
        if i[k[0]]==1 and i[k[1]]!=k[2]:
            s=False
            break
    if s:
        ans=max(ans,sum(i))
print(ans)

Solution (Python):
N=int(input())
g=[[-1]*N for _ in range(N)]
ans=0
for i in range(N):
    A=int(input())
    for _ in range(A):
        x,y=map(int,input().split())
        g[i][x-1]=y
for s in range(2**N):
    flag=1
    for i in range(N):
        if (s>>i&1):
            for j in range(N):
                if g[i][j]!=-1 and (s>>j&1)!=g[i][j]:
                    flag=0
                    break
        if flag==0:break
    if flag==1:
        t=0
        x=s
        while x>0:
            t+=x%2
            x//=2
        ans=max(ans,t)
print(ans)