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

Solution (Python):
import itertools

n=int(input())

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

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

ans=0


for xxx in itertools.product(range(2),repeat=n):
    table=[[] for i in range(n)]
    for j in range(n):
        if xxx[j]==1:
            for k in lst[j]:
                table[k[0]].append(k[1])
    
    flag=True

    for j in range(n):
        if xxx[j]==1:
            if table[j].count(0)!=0:
                flag=False
        
        else:
            if table[j].count(1)!=0:
                flag=False
    

    if not flag:
        continue
    

    ans=max(ans,xxx.count(1))



print(ans)

Solution (Python):



import sys
from io import StringIO
import unittest
from collections import deque


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
1
2 1
1
1 1
1
2 0"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """2
1
2 0
1
1 0"""
        output = """1"""
        self.assertIO(input, output)


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

    ans = 0
    for bit in range(1 << N):
        f = True
        for i in range(N):
            if bit & (1 << i):
                for c in C[i]:
                    if bit & (1 << c[0]-1) != (1 << c[0]-1)*c[1]:
                        f = False
                        break
        if f == True:
            ans = max(ans, bin(bit).count("1"))
    print(ans)


def resolve():
    global N, C
    N = int(input())
    C = []
    for i in range(N):
        a = int(input())
        C.append([list(map(int, input().split())) for j in range(a)])

    V = deque()
    print(dfs(0, V))


def dfs(n, V):
    if n == N:
        count = 0
        for v in V:
            if count == -1:
                break
            for c in C[v-1]:
                if (c[0] in V and c[1] == 0) or (c[0] not in V and c[1] == 1):
                    count = -1
                    break
            else:
                count += 1
        if count == -1:
            return 0
        else:
            return count

    ans = 0
    V.append(n+1)
    ans = max(ans, dfs(n+1, V))
    V.pop()
    ans = max(ans, dfs(n+1, V))

    return ans


if __name__ == "__main__":
    
    resolve()

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

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

ans=0

for h in range(2**N):
	flag=0
	cnt=0
	l=[0]*N
	for g in range(N):
		if h>>g &1:
			l[g]=1
	
	for gg in range(N):
		if l[gg]==1:
			temp_=syogen[gg]
			
			for n in range(temp_[0]):
				if l[temp_[1][n][0]-1]==temp_[1][n][1]:
					continue
				else:
					flag=1
					break
		if flag==1:
			break
		elif flag==0 and gg==N-1:
			
			ans=max(ans,sum(l))

print(ans)

Solution (Python):
n = int(input())
g = [[-1 for _ in range(15)] for _ in range(15)]
for i in range(n):
  a = int(input())
  for j in range(a):
    x, y = map(int, input().split())
    g[i][x-1] = y
    
ans = 0
for bit in range(1<<n):
  honests = [0]*n
  for i in range(n):
    if bit & 1<<i: honests[i] = 1
  flg = True
  for i in range(n):
    if honests[i]:
      for j in range(n):
        if g[i][j] == -1: continue
        if g[i][j] != honests[j]: flg = False
  if flg:
    ans = max(ans, honests.count(1))
print(ans)

Solution (Python):
n=int(input())
a=[]
l=[]
for i in range(n):     
      A=int(input())
      L=[list(map(int,input().split())) for _ in range(A)]
      a.append(A)
      l.append(L)
ans=0
for i in range(2**n):
      b=[0]*n
      for j in range(n):
            if (i>>j)&1:
                  b[j]=1
      for k in range(n):
            for h in range(a[k]):
                  hito=l[k][h][0]-1
                  singi=l[k][h][1]
                  if b[k]==1 and b[hito]!=singi:
                        break      
            else:
                  continue
            break
      else:
            ans=max(ans,sum(b))

print(ans)

Solution (Python):
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

from collections import defaultdict
test = defaultdict(list)
test_per = defaultdict(dict)
n = int(input())
for i in xrange(n):
    nn = int(input())
    for j in xrange(nn):
        x,y = (int(x) for x in input().split())
        test[x-1].append(y)
        test_per[i][x-1] = y
ans = 0
for i in xrange(2**n):
    bini= bin(i)[2:]
    bini = '0'*(n-len(bini)) + bini
    valid = True
    for j,c in enumerate(bini):
        if c == '1':  
            for other_person in test_per[j]:
                if test_per[j][other_person] != int(bini[other_person]):
                    valid = False
                    break
        if not valid:
            break
    if valid:
        ans = max(ans, bini.count('1'))
print(ans)

Solution (Python):
n=int(input())
a=[]
x=[]
for _ in range(n):
    A=int(input())
    X=[list(map(int,input().split())) for _ in range(A)]
    a.append(A)
    x.append(X)
ans=0

for i in range(2**n):
    tmp=[0]*n
    for j in range(n):
        if (i>>j)&1:
            tmp[j]=1
    for k in range(n):
        for h in range(a[k]):
            hito=x[k][h][0]-1
            singi=x[k][h][1]
            if tmp[k]==1:
                if tmp[hito]!=singi:
                    break
        else:
            continue
        break 
    else:
        ans=max(ans,sum(tmp))

print(ans)

Solution (Python):
n=int(input())
a=[]
x=[]
for _ in range(n):
    A=int(input())
    X=[list(map(int,input().split())) for _ in range(A)]
    a.append(A)
    x.append(X)
ans=0

for i in range(2**n):
    tmp=[0]*n
    for j in range(n):
        if (i>>j)&1:
            tmp[j]=1
    for k in range(n):
        
        
        for h in range(a[k]):
            hito=x[k][h][0]-1
            singi=x[k][h][1]
            if tmp[k]==1:
                if tmp[hito]!=singi:
                    break
        else:
            continue
        break
    else:
        ans=max(ans,sum(tmp))

print(ans)

Solution (Python):
n=int(input())
a=[]
x=[]
for _ in range(n):
    A=int(input())
    X=[list(map(int,input().split())) for _ in range(A)]
    a.append(A)
    x.append(X)
ans=0

for i in range(2**n):
    tmp=[0]*n
    for j in range(n):
        if (i>>j)&1:
            tmp[j]=1
    for k in range(n):
        if a[k]==0:
            continue
        for h in range(a[k]):
            hito=x[k][h][0]-1
            singi=x[k][h][1]
            if tmp[k]==1:
                if tmp[hito]!=singi:
                    break
        else:
            continue
        break
    else:
        ans=max(ans,sum(tmp))

print(ans)

Solution (Python):


N=int(input())
A=[[] for _ in [0]*N]
for i in range(N):
    a=int(input())
    for _ in [0]*a:
        A[i].append(tuple(map(int,input().split())))

res=0
for n in range(1<<(N)):
    check=[-1]+[(n>>j)&1 for j in range(N)]
    cnt=0
    j=0
    for j in range(N):
        if check[j+1]==1:
            cnt+=1
            
            for x,y in A[j]:
                if check[x] == 1-y:
                    check[0]=1
                if check[0]>0:
                    break
        if check[0]>0:
            break
    if check[0]>0:
        continue
    res=max(res,cnt)
print(res)

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




'''
a,b=[],[]
for i in range(n):
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''


n=int(input())

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

ma=0
for i in range(2**n):
    now=0
    flg=True
    e=[0]*n
    for j in range(n):
        if (i>>j)&1:
            now+=1
            e[j]=1

    for j in range(n):
        
        if (i>>j)&1:
            
            if e[j]==0:
                flg=False
                break
            elif not flg:
                break

            for k in range(a[j]):
                """if e[x[j][k][0]-1]==-1: 
                    if x[j][k][1] and
                    e[x[j][k][0]-1]=x[j][k][1]"""
                
                if (e[x[j][k][0]-1]==0 and x[j][k][1]==1) or (e[x[j][k][0]-1]==1 and x[j][k][1]==0):
                    flg=False
                    break

    if flg and ma<now:
        ma=now
        

print(ma)

Solution (Python):

"""
Created on Sun Sep 13 02:01:40 2020

@author: liang
"""

N = int(input())
A = list()
T = [list() for i in range(N)]


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

for i in range(2**N):
    
    persons = list()
    for j in range(N):
        if i>>j&1 == 1:
            persons.append(j)
    
    d = [False]*N
    for p in persons:
        d[p] = True 

    judged = [False]*N
    
    for num in range(N):
        
        f = False
        if d[num]:
            for t in T[num]:
                x, y = t[0], t[1]
                
                if y == 1 and d[x] != True:
                    f = True
                    break
                if y == 0 and d[x] != False:
                    f = True
                    break
        if f:
            break
    else:
        
        ans = max(ans, len(persons))
print(ans)

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N=intput()
A=[list() for _ in range(N)]
for i in range(N):
    a=intput()
    for _ in range(a):
        A[i].append(lint())
ans=0
for c in product('01',repeat=N):
    tmp=True
    for i in range(N):
        if c[i]=='1':
            for x,y in A[i]:
                if c[x-1]!=str(y):
                    tmp=False
                    break
        if not tmp:
            break
    if tmp:
        ans=max(ans,c.count('1'))
print(ans)

Solution (Python):
N = int(input())
confesses = [[-1 for _ in range(N)] for __ in range(N)]
for i in range(N):
  A = int(input())
  for __ in range(A):
    x, y = map(int, input().split())
    confesses[i][x-1] = y
answer = 0
for num in range(2**N):
  users = [0 for _ in range(N)]
  cnt = 0
  for i in range(N):
    if num>>i&1:
      users[i] = 1
      cnt += 1
  right = True
  for j, user in enumerate(users):
    if user == 1:
      for i, confess in enumerate(confesses[j]):
        if confess != -1 and users[i] != confess:
          right = False
          break
    if not right:
      break
  if right:
    answer = max(answer, cnt)
print(answer)

Solution (Python):
def judge(bit):
    global l
    for i in range(n):
        if (bit>>i)&1 == 0:
            continue
        for x,y in l[i]:
            if y==1 and (bit>>x)&1==0:
                return False
            if y==0 and (bit>>x)&1==1:
                return False
    return True

n = int(input())
l = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        l[i].append((x-1,y))
maxi = 0
for bit in range(2**n):
    if judge(bit):
        maxi = max(maxi,str(bin(bit)).count('1'))
print(maxi)

Solution (Python):
from collections import defaultdict,deque
n = int(input())
d = defaultdict(list)
for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        d[i].append((x-1,bool(y)))
        
maxi = 0
for i in range(2 ** n):
    honest = [-1]*n
    que = deque([])
    for j in range(n):
        if ((i >> j) & 1):
            que.append(n-1-j)
            honest[n-1-j] = True
    flag = True
    while que and flag:
        v = que.popleft()
        for x,y in d[v]:
            if honest[x] == -1:
                honest[x] = y
                if y:
                    que.append(x)
            elif honest[x] != y:
                flag = False
                break
    if flag:
        maxi = max(maxi,str(bin(i)).count('1'))
print(maxi)

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def ok(t, s):
    N = len(t)
    for i in range(N):
        if t[i]:
            for x, y in s[i]:
                if y == 1:
                    if not t[x]:
                        return False
                elif y == 0:
                    if t[x]:
                        return False

    return True


def solve():
    N = int(input())

    s = defaultdict(list)
    for i in range(N):
        A = int(input())
        for _ in range(A):
            X, Y = map(int, input().split())
            X -= 1
            s[i].append((X, Y))

    ans = 0
    for b in range(2 ** N):
        t = [0] * N
        num = 0
        for i in range(N):
            if (b >> i) & 1:
                t[i] = 1
                num += 1
        if ok(t, s):
            ans = max(ans, num)

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product

n = int(input())

d = {}
for i in range(n):
  a = int(input())
  for _ in range(a):
    x, y = map(int, input().split())
    if i + 1 not in d:
      d[i + 1] = []
    d[i + 1].append((x, y))

ret = 0
for x in product((0, 1), repeat=n):
  ok = True
  for i in range(n):
    if x[i] == 0 or i + 1 not in d:
      continue
    for p, tf in d[i + 1]:
      if x[p - 1] != tf:
        ok = False
        break
    if not ok:
      break
  if ok:
    ret = max(ret, sum(x))

print(ret)

Solution (Python):
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())
        x -= 1
        xy[i].append((x,y))
ans = 0
s = set()
t = set()
def true(s,t,j):
    if j not in t:
        s.add(j)
        return False
    return True
def false(s,t,j):
    if j not in s:
        t.add(j)
        return False
    return True
def chk(i):
    s = set()
    t = set()
    fl = False
    for j in range(N):
        if (i>>j)&1:
            fl |= true(s,t,j)
            for x,y in xy[j]:
                fl |= true(s,t,x) if y == 1 else false(s,t,x)
        else:
            fl |= false(s,t,j)
    return fl
ans = 0
for i in range(2**N):
    if chk(i):
        continue
    cnt = 0
    for j in range(N):
        if (i>>j)&1:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Solution (Python):
from itertools import product

n = int(input())

d = {}
for i in range(n):
  a = int(input())
  for _ in range(a):
    x, y = map(int, input().split())
    if i + 1 not in d:
      d[i + 1] = []
    d[i + 1].append((x, y))

ret = 0
for x in product((0, 1), repeat=n):
  tmp = [-1] * n
  ok = True
  for i in range(n):
    if x[i] == 1 and i + 1 in d:
      for y in d[i + 1]:
        if tmp[y[0] - 1] == -1:
          tmp[y[0] - 1] = y[1]
        elif tmp[y[0] - 1] != y[1]:
          ok = False
          break
    if not ok:
      break
  if ok and all(a == b or b == -1 for a, b in zip(x, tmp)):
    ret = max(ret, sum(x))

print(ret)

Solution (Python):
n = int(input())
statement = [[] 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:
            statement[i].append([x-1, True])
        if y == 0:
            statement[i].append([x-1, False])

cnt = 0
for bit in range(2**n):
    honest = []
    for i in range(n):
        if (bit >> i) & 1:
            honest.append(i)
    flag = True
    for j in range(len(statement)):
        if j in honest:
            for k in honest:
                if [j, False] in statement[k]:
                    flag = False
                    break
        else:
            for k in honest:
                if [j, True] in statement[k]:
                    flag = False
                    break
        
        if not flag:
            break  
    if flag:
        cnt = max(cnt, len(honest))
print(cnt)

Solution (Python):
from itertools import product

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

ans = 0
for bit in product([0, 1], repeat=n):
    for i, liar in enumerate(bit):
        if liar and any(bit[x - 1] != y for x, y in xy[i]):
            break
    else:
        ans = max(ans, sum(bit))
print(ans)

Solution (Python):
N = int(input())
A = [0 for n in range(N)]
XY = [0 for n in range(N)]
count_max = 0

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

for i in range(2 ** N):
  op = [0]*N
  for j in range(N):  
    if ((i >> j) & 1):
      op[N-1-j] = 1
      
  flag = True
  
  for k in range(len(op)):
    if op[k] == 1:
      for l in range(A[k]):
        if XY[k][l][1] != op[XY[k][l][0]-1]:
          flag = False
        
  if flag:
    if sum(op) > count_max:
      count_max = sum(op)

print(count_max)

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

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


ans = 0
for bit in range(1 << N):
    break_flag = 0
    for i in range(N):
        if (bit >> i) & 1:
            for j in range(len(syougen[i])):
                if ((bit>>(syougen[i][j][0]-1))&1) != syougen[i][j][1]:
                    break_flag = 1
                    break
            if break_flag == 1:
                break
        if i == N-1:
            ans = max(ans, bin(bit).count("1"))
print(ans)

Solution (Python):
import copy
N = int(input())
testimony = []
for n in range(N):
    A = int(input())
    testimony.append({})
    for a in range(A):
        x, y = map(int, input().split())
        testimony[n][x - 1] = y    

def judge(truthy):
    answer = True
    for i in range(len(truthy)):
        if truthy[i] == 1:
            for t in testimony[i].keys():
                if truthy[t] != testimony[i][t]:
                    answer = False
                    break
        if not answer:
            break
    
    return 0 if not answer else truthy.count(1)

def dfs(truthy, depth):
    if N == depth:
        return judge(truthy)
    truth = copy.copy(truthy)
    truth.append(1)
    t = dfs(truth, depth + 1)
    false = copy.copy(truthy)
    false.append(0)
    f = dfs(false, depth + 1)
    return max(t, f)

print(dfs([], 0))

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

answer = 0
for index in range(2 ** n):
    honests = [0 for _ in range(n)]
    for shift in range(n):
        if (index >> shift) & 1:
            honests[shift] = 1
    ok = True
    for idx1 in range(n):
        if honests[idx1]:
            for idx2 in range(n):
                if graph[idx1][idx2] == -1:
                    continue
                if graph[idx1][idx2] != honests[idx2]:
                    ok = False
    if ok:
        answer = max(answer, honests.count(1))

print(answer)

Solution (Python):
N = int(input())
A=[]
xy=[]
for i in range(N):
    a=int(input())
    A.append(a)
    X = [list(map(int, input().split())) for i in range(a)]
    xy.append(X)
mx=0

for i in range(2**N):
    Z=[0]*N
    flag=0
    for j in range(N):
        if ((i>>j)&1):
            Z[j]=1
    for k in range(N):
        for l in range(A[k]):
            if Z[k]==1:
                if Z[xy[k][l][0]-1]!=xy[k][l][1]:
                    flag=1
    if flag==0:
        mx=max(mx,Z.count(1))
print(mx)

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

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

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

    ans = 0
    for bit in range(1 << N):
        ok = True
        for i in range(N):
            if bit >> i & 1:
                for (x, y) in evdi[i]:
                    if y == 1 and not bit >> x & 1:
                        ok = False
                        break
                    if y == 0 and bit >> x & 1:
                        ok = False
                        break
        cnt = bin(bit).count("1")
        if ok:
            ans = max(cnt, ans)
    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):

def resolve():
    N = int(input())
    evdi = [[] for _ in range(N)]
    for i in range(N):
        cnt = int(input())
        for _ in range(cnt):
            x, y = map(int, input().split())
            x -= 1
            evdi[i].append((x, y))

    ans = 0
    for bit in range(1 << N):
        ok = True
        for i in range(N):
            if bit >> i & 1:
                for (x, y) in evdi[i]:
                    if y == 1 and not bit >> x & 1:
                        ok = False
                        break
                    if y == 0 and bit >> x & 1:
                        ok = False
                        break
        cnt = bin(bit).count("1")
        if ok:
            ans = max(cnt, ans)
    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):
n=int(input())
say=[]
for i  in range(n):
    qq=[]
    for i in range(int(input())):
        qq.append(list(map(int,input().split())))
    say.append(qq)
ans=0
for bit in range(1<<n):
    plate=0
    L=[(bit>>i)&1 for i in range(n)]
    for i in range(n):
        if L[i]==0:continue
        for l in say[i]:
            if  L[l[0]-1] != l[1]:
                plate=1;break
        if plate:break
    else:
        ans=max(ans,sum(L))
print(ans)

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=[0]*N
    xy=[]
    for i in range(N):
        A[i]=I()
        temp=[]
        for _ in range(A[i]):
            x,y=MI()
            x-=1
            temp.append((x,y))
        xy.append(temp)
        
    import itertools
    ans=0
    
    for ite in itertools.product([0,1], repeat=N):
        
        flag=1
        for i in range(N):
            if flag==0:
                break
            if ite[i]==1:
                for x,y in xy[i]:
                    if ite[x]!=y:
                        flag=0
                        break
        if flag:
            ans=max(ans,sum(ite))
            
    print(ans)
            

main()

Solution (Python):
n=int(input())
xy=[[[]] for _ in range(n)]
for i in range(n):
    a=int(input())
    xy[i]=[list(map(int,input().split())) for _ in range(a)]
ans=0
for i in range(2**n):
    tmp=[0]*n
    flag1=True
    for j in range(n):
        if (i>>j)&1:
            tmp[j]=1
    for k in range(n):
        flag2=True
        if tmp[k]==1:
            for x,y in xy[k]:
                if tmp[x-1]!=y:
                    flag1=False
                    flag2=False
                    break
        if not flag2:
            break
    if flag1:
        ans=max(ans,sum(tmp))
print(ans)

Solution (Python):
N = int(input())
XY_list = [[] for _ in range(N)]
for i in range(N):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        XY_list[i].append([person - 1, state])
ans = 0
for i in range(1 << N):
    bool = True
    for j in range(N):
        if (i >> j) & 1 == 1:
            for person, state in XY_list[j]:
                if (i >> person) & 1 != state:
                    bool = False
                    break

    if bool:
        ans = max(ans, bin(i)[2:].count("1"))
print(ans)

Solution (Python):
N=int(input())
numbers=[]
for _ in range(N):
    A=int(input())
    number=[]
    for _ in range(A):
        x,y=map(int,input().split())
        number.append([x,y])
    numbers.append(number)
answers=[]
for i in range(2**N):
    number=[]
    for j in range(N):
        if ((i>>j)&1):
            number.append(j+1)
    answers.append(number)
del answers[0]
ans=0
for answer in answers:
    kouho=[]
    num=0
    flag=0
    for a in answer:
        kouho+=numbers[a-1]
    for k in kouho:
        if k[1]==1 and k[0] not in answer:
            flag=1
            break
        elif k[1]==0 and k[0] in answer:
            flag=1
            break
    if flag==0:
        num=len(answer)
    ans=max(ans,num)
print(ans)

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

for i in range(N):
  A=int(input())
  testimony=[]
  for j in range(A):
    testimony.append(list(map(int,input().split())))
    testimony[-1][0]-=1
  testimonies.append(testimony)

ans=0
for i in range(2**N):
  isContradiction=False
  for j in range(N):
    if not i&1<<j:continue
    for x,y in testimonies[j]:
      if i&1<<x:x=1
      else:x=0
      if not x==y:
        isContradiction=True
        break
  if not isContradiction:
    ans=max(ans,bin(i).count("1"))
print(ans)

Solution (Python):
import itertools

def main():
    N = int(input())
    n_x_y = {}
    for n in range(N):
        A = int(input())
        x_y = {}
        for _ in range(A):
            x, y = map(int, input().split())
            x_y[x-1] = y
        n_x_y[n] = x_y

    ans = 0
    for flags in itertools.product([1, 0], repeat=N):
        sat = True
        for n, flag in enumerate(flags):
            if flag == 0:
                continue
            for x, y in n_x_y[n].items():
                if (y == 1 and flags[x] == 0) or (y == 0 and flags[x] == 1):
                    sat = False
                    break
            if sat is False:
                break
        if sat is True and sum(flags) > ans:
            ans = sum(flags)

    print(ans)


if __name__ == '__main__':
    main()