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 sys

def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

N = int(input())
ys = [[-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())
        ys[i][x-1] = y


ans = 0
for b in range(1<<N):
    chk = [-1] * N      
    flg = True
    for i in range(N):
        if b>>i&1:
            if chk[i] == 0:
                flg = False
                break
            chk[i] = 1
            for j in range(N):
                if ys[i][j] == -1: continue
                if chk[j] != -1 and chk[j] != ys[i][j]:
                    flg = False
                    break
                chk[j] = ys[i][j]
        else:
            if chk[i] == 1:
                flg = False
                break
            chk[i] = 0
    if flg:
        ans = max(ans, sum(chk))    
print(ans)

Solution (Python):
n = int(input())
testimonies = []
for _ in range(n):
    a = int(input())
    testimony = [list(map(int, input().split()))  for _ in range(a)]
    testimonies.append(testimony)
    
ans = 0
for i in range(2 ** n):
    honesty = [0 for _ in range(n)]
    for j in range(n):
        if ((i >> j) & 1):
            honesty[j] = 1
    
    
    for j in range(n):
        contradiction = True
        if honesty[j]:
            
            for testimony in testimonies[j]:
                
                
                if honesty[testimony[0] - 1] == testimony[1]:
                    continue
                
                contradiction = False
                break
            
        if not contradiction:
            break
    
    if contradiction:
        ans = max(ans, honesty.count(1))
    

print(ans)

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

ans = 0
for i in range(2**n):
    flag = True
    for j in range(n):
        if (i >> j) & 1 == 0:
            continue
        for k in xy[j]:
            x, y = k[0], k[1]
            if not((1 & (i >> (x-1))) == y):
                flag = False
    if flag:
        ans = max(ans, bin(i).count("1"))
print(ans)

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

ans = 0

for i in range(2**N): 
  honest = 0
  ng = 0
  for j in range(N):  
    if ((i>>j)&1)==0:
      continue        
    else:
      for k in range(A[j]):
        taisho = xy[j][k][0] - 1
        if xy[j][k][1] != ((i>>taisho)&1):
          ng = 1
          break
    if ng == 1:
      break
    honest += 1
  if ans < honest and ng == 0:
    ans = honest      

print(ans)

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

ans = 0

for i in range(2**N): 
  honest = 0
  ng = 0
  for j in range(N):  
    if ((i>>j)&1)==0:
      continue        
    else:
      for k in range(A[j]):
        taisho = xy[j][k][0] - 1
        if xy[j][k][1] != ((i>>taisho)&1):
          ng = 1 
    honest += 1
  if ans < honest and ng == 0:
    ans = honest      

print(ans)

Solution (Python):
import itertools

N = int(input())
evidence = list()
for _ in range(N):
    A_k = int(input())
    A_dict = dict()
    for i in range(A_k):
        x, y = map(int, input().split())
        A_dict[x-1] = y
    evidence.append(A_dict)
    
A = [0, 1]
product = list(itertools.product(A, repeat=N))
count_max = 0
for evi in product:
    check = 0
    for i, e in enumerate(evi):
        if e == 1:
            for k, v in evidence[i].items():
                if evi[k] != v:
                    check = 1
                    break
    if check == 0:
        count = sum(evi)
        if count > count_max:
            count_max = count
print(count_max)

Solution (Python):






import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9 +7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


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





N = inputI()
l = []
for i in range(N):
  a = inputI()
  l.append(inputILL(a))

best = 0
for i in range(pow(2,N)):
  OKAY = True
  count = 0
  temp = i
  while temp:
    temp &= temp -1
    count += 1
  for n in range(N):
    if ((pow(2,n)&i )>> n) & 1:
      for statement in l[n]:
        if ((pow(2,statement[0]-1)&i)>>(statement[0]-1) ) != statement[1]:
          OKAY = False
  if OKAY == True:
    best = max(best,count)

print(best)

Solution (Python):
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = 0
n = int(input())
def to_num(m):
    outp = 0
    for i in range(n):
        outp += (m>>i)&1
    return outp

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

for bit in range(1<<n):
    is_good = 1
    for i in range(n):
        if is_good != 1:
            break
        
        if (bit>>i)&1:
            for j in range(len(ini[i])):
                if is_good != 1:
                    break
                if ini[i][j][1] == 1:
                    is_good = is_good & ((bit >> (ini[i][j][0]-1))&1)
                elif ini[i][j][1] == 0:
                    is_good = is_good & ~((bit >> (ini[i][j][0]-1))&1)

    if is_good:
        ans = max(ans, to_num(bit))
    
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline

N = int(input())
A = []
xy = []
ans = []
sm = 0

for _ in range(N):
    temp = int(input())
    A.append([temp, sm])
    sm += temp
    for _ in range(A[-1][0]):
        xy.append(list(map(int, input().split())))
for i in range(2**N):
    flag = True
    binary = bin(i)[2:]
    if len(binary) < N:
        binary = '0' * (N - len(binary)) + binary
    check = [0]*N
    for j, digit in enumerate(binary):
        if digit == '1':
            check[j] = 1
    for j, value in enumerate(check):
        if value == 1:
            for k in range(A[j][0]):
                x = xy[A[j][1]+k][0] - 1
                y = xy[A[j][1]+k][1]
                if check[x] != y:
                    flag = False
    if flag:
        ans.append(check.count(1))

print(max(ans))

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

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

    honest = [[None] * 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())
            honest[i][x-1] = True if y else False
    
    ans = 0
    for i in range(2**N):
        p = [False] * N
        tmp = 0
        for j in range(N):
            if i&1:
                p[j] = True
                tmp += 1
            i >>= 1
        
        
        
        ok = True
        for j in range(N):
            if not ok:
                break
            if p[j]:
                for k in range(N):
                    if (honest[j][k] == True and p[k] == False) or (honest[j][k] == False and p[k] == True):
                        ok = False
                        break
        
        if ok:
            ans = max(ans, tmp)
    
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def check(bag, mtx):
    shojiki = set()
    not_shojiki = set()
    for i in range(len(bag)):
        if bag[i] == 1:
            shojiki.add(i)
    shojiki_list = list(shojiki)
 
    while True:
        if shojiki_list == []:
            break
        i = shojiki_list.pop()
        for j in range(len(mtx[i])):
            if mtx[i][j] == 0 and j in shojiki:
                return False
            if mtx[i][j] == 1:
                if j in not_shojiki:
                    return False
                if j not in shojiki:
                    shojiki_list.append(j)
                    shojiki.add(j)
            if mtx[i][j] == 0:
                not_shojiki.add(j)
    return True
 
 
n = int(input())
 
mtx = [[-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())
        mtx[i][x-1] = y
 
ret = 0
 
for i in range(2 ** n):
    bag = []
    for j in range(n):
        if ((i >> j) & 1):
            bag.append(1)
        else:
            bag.append(0)
    if check(bag, mtx):
        if ret < sum(bag):
            ret = sum(bag)
 
print(ret)

Solution (Python):
n = int(input())
v = []
for i in range(n):
    ai = int(input())
    vi = []
    for j in range(ai):
        vi.append(list(map(int, input().split())))
    v.append(vi)

m = 0
for bit in range(2**n - 1, -1, -1):
    is_break = False
    for i in range(n):
        if not (bit & (1 << i)):
            continue
        for xij, yij in v[i]:
            if not (not (bit & (1 << xij - 1))) != yij:
                is_break = True
                break
        if is_break:
            break
    else:
        m = max(bin(bit).count('1'), m)

print(m)

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from itertools import combinations

def main():
    n = int(input().strip())
    G = [[-1] * n for _ in range(n)]
    
    for i in range(n):
        m = int(input().strip())
        for j in range(m):
            x, y = list(map(int, input().strip().split()))
            G[i][x-1] = y
    
    for i in reversed(range(n+1)):
        for c in combinations(range(n), i):
            
            cont = False
            
            for p in c:
                for j in range(n):
                    if G[p][j] == -1:
                        continue
                    if (G[p][j] == 1) != (j in c):
                        cont = True
                    
                    
                    
                    
                    
                    
                    
            if cont == False:
                print(i)
                return

if __name__ == '__main__':
    main()

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

humans = []

for i in range(n):
  human = []
  ai = int(input())
  for j in range(ai):
    x,y = map(int, input().split())
    human.append([x-1,y])
  humans.append(human)
num = 0
for i in range(pow(2, n)):
  k = i
  honest = []
  for j in range(n):
    x = pow(2,n-j-1)
    honest.append(1 - (k // x))
    k = k % x
  
  flg = True
  for j in range(n):
    if(honest[j]==0):
      continue
    for k in humans[j]:
      if(honest[k[0]] != k[1]):
        flg = False
        break
    if(not(flg)):
      break
        
  if(flg):
    num = sum(honest)
    break

print(num)

Solution (Python):











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

m = 0
for h in range(2**n - 1, -1, -1):
    is_break = False
    h = bin(h)[2:].zfill(n)
    for i, xi in enumerate(x):
        if h[i] == '0':
            continue
        for xij, yij in xi:
            if (int(h[xij - 1]) != yij):
                is_break = True
                break
        if is_break:
            break
    else:
        m = max(sum(map(int, list(h))), m)

print(m)

Solution (Python):
n = int(input())
x = []
for i in range(n):
    ai = int(input())
    xi = []
    for j in range(ai):
        xi.append(list(map(int, input().split())))
    x.append(xi)

m = 0
for h in range(2**n - 1, -1, -1):
    is_break = False
    h = bin(h)[2:].zfill(n)
    for i, xi in enumerate(x):
        if h[i] == '0':
            continue
        for xij, yij in xi:
            if (int(h[xij - 1]) != yij):
                is_break = True
                break
        if is_break:
            break
    else:
        m = max(sum(map(int, list(h))), m)

print(m)

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

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

result = 0
for i in range(1, 2**N):
    consistent = True
    for j in range(N):
        if (i >> j) & 1 == 0:
            continue
        for x, y in evidences[j]:
            if (i >> x) & 1 != y:
                consistent = False
                break
        if not consistent:
            break
    if consistent:
        result = max(result, bin(i)[2:].count('1'))
print (result)

Solution (Python):
n = int(input())
xy = []
for _ in range(n):
    a = int(input())
    xy.append([])
    for _ in range(a):
        xy[-1].append([int(i) for i in input().split()])
        xy[-1][-1][0] -= 1

ans = 0
for i in range(2 ** n):
    ok = True
    l = 0
    for j in range(n):
        if i & (2 ** j) == 0:
            continue
        l += 1
        for k in xy[j]:
            if (1 if i & (2 ** k[0]) != 0 else 0) != k[1]:
                ok = False
    
    if ok:
        ans = max(ans, l)
print(ans)

Solution (Python):

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


ans = 0
for i in range(1, 2 ** N + 1):
    honest = [0] * N
    for j in range(N):
        if int(format(i, 'b').zfill(N)[j]) == 1:
            honest[j] = 1

    is_correct = True
    for j in range(N):
        if honest[j] == 1:
            for k in range(N):
                if witness[j][k] == -1:
                    pass
                elif witness[j][k] != honest[k]:
                    is_correct = False
    if is_correct:
        ans = max(ans, sum(honest))

print(ans)

Solution (Python):

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


ans = 0
for i in range(1, 2 ** N + 1):
    honest = [0] * N
    for j in range(N):
        if int(format(i, 'b').zfill(N)[j]) == 1:
            honest[j] = 1

    is_correct = True
    for j in range(N):
        if honest[j] == 1:
            for k in range(N):
                if witness[j][k] == -1:
                    pass
                elif witness[j][k] != honest[k]:
                    is_correct = False
    if is_correct:
        ans = max(ans, sum(honest))

print(ans)

Solution (Python):

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


ans = 0
for i in range(1, 2 ** N + 1):
    honest = [0] * N
    for j in range(N):
        if int(str(format(i, 'b')).zfill(N)[j]) == 1:
            honest[j] = 1

    is_correct = True
    for j in range(N):
        if honest[j] == 1:
            for k in range(N):
                if witness[j][k] == -1:
                    pass
                elif witness[j][k] != honest[k]:
                    is_correct = False
    if is_correct:
        ans = max(ans, sum(honest))

print(ans)

Solution (Python):

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


ans = 0
for i in range(1, 2 ** N + 1):
    honest = [0] * N
    for j in range(N):
        if str(format(i, 'b')).zfill(N)[j] == "1":
            honest[j] = 1

    is_correct = True
    for j in range(N):
        if honest[j] == 1:
            for k in range(N):
                if witness[j][k] == -1:
                    pass
                elif witness[j][k] != honest[k]:
                    is_correct = False
    if is_correct:
        ans = max(ans, sum(honest))

print(ans)

Solution (Python):
n = int(input())
xy = []
for _ in range(n):
    xy.append([])
    a = int(input())
    for _ in range(a):
        xy[-1].append([int(i) for i in input().split()])
        xy[-1][-1][0]-=1

ma = 0

for i in range(2 ** n):
    ok = True
    a = 0
    for j in range(n):
        if (2 ** j) & i != 0:
            a += 1
            for k in xy[j]:
                if (1 if (2 ** k[0]) & i != 0 else 0) != k[1]:
                    ok = False
    if ok:
        ma = max(ma, a)
print(ma)

Solution (Python):

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

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

    
    ans = [0]
    for j in range(0,2**n):
        tmp = bin(j)
        tmp = str(int(tmp[2:])).zfill(n)
        
        
        
        
        break_on = 0
        for k in range(n):
            if tmp[k] == '1':
                
                if n_list[k][0] != [0]:
                    for h in n_list[k]:
                        
                        
                        
                        
                        if h[1] != int(tmp[h[0]]):
                            break_on = 1
                            break
                    if break_on == 1:
                        break
            if break_on == 1:
                break
            
            if tmp[k] == '0':
                continue
        
        if break_on == 0:
            
            
            ans.append(tmp.count('1'))
    
    
    print(max(ans))
    


            



if __name__ == '__main__':
    main()

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

res = 0

bin_a = ["{:015b}".format(a) for a in range(0, 2**n)]
bin_a = list(map(lambda x: [int(y) for y in list(x)], bin_a))


for x in bin_a:
    x.reverse()
    
    r = 0
    f = True
    tmp = [-1] * n
    for i in range(n):
        if x[i] == 1:
            
            for y in dat[i]:
                
                if y[1] == 0 and x[y[0]] == 0:
                    if tmp[y[0]] != 1:
                        tmp[y[0]] = 0
                        continue
                    f = False
                if y[1] == 1 and x[y[0]] == 1:
                    if tmp[y[0]] != 0:
                        tmp[y[0]] = 1
                        continue
                    f = False
                f = False
    if f:
        res = max(res, sum(x))
print(res)

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

res = 0

bin_a = ["{:015b}".format(a) for a in range(0, 2**n)]
bin_a = list(map(lambda x: [int(y) for y in list(x)], bin_a))


for x in bin_a:
    x.reverse()
    
    r = 0
    f = True
    tmp = [-1] * n
    for i in range(n):
        if x[i] == 1:
            
            for y in dat[i]:
                
                if y[1] == 0 and x[y[0]] == 0:
                    if tmp[y[0]] != 1:
                        tmp[y[0]] = 0
                        continue
                    f = False
                if y[1] == 1 and x[y[0]] == 1:
                    if tmp[y[0]] != 0:
                        tmp[y[0]] = 1
                        continue
                    f = False
                f = False
    if f:
        res = max(res, sum(x))
print(res)

Solution (Python):
n = int(input())
L = []
for i in range(n):
    L.append(2**i)
ans = 0
comment = [[] for i in range(n)]
num = []
for i in range(n):
    t = int(input())
    num.append(t)
    for j in range(t):
        a,b = map(int,input().split())
        comment[i].append([a-1,b])
for i in range(2**n):
    cur = i
    str = ''
    flag = True
    honest_num = 0
    for j in range(len(L)):
        temp = cur&L[j]
        if temp != 0:
            str = '1'+str
            honest_num += 1
        else:
            str = '0'+str
    for j in range(n):
        d = num[j]
        if str[j] == '1':
            for k in range(d):
                pick = comment[j][k]
                if (pick[1] == 0 and str[pick[0]] == '1') or (pick[1] == 1 and str[pick[0]] == '0'):
                    flag = False
                    break
        if not flag:
            break
    if flag:
        ans = max(ans,honest_num)
print(ans)

Solution (Python):

n=int(input())
a_li=[]
xy_li=[]
for i in range(n):
  a_li.append(int(input()))
  xy_li_i=[list(map(int,input().split())) for j in range(a_li[i])]
  xy_li.append(xy_li_i)
  
proof=[]  
for i in range(2**n):
  li=[0]*n
  for j in range(n):
    if (i>>j)&1==1:
      li[j]=1
  proof.append(li)

ans=0  
for i in proof:
  flag=True
  for j in range(n):
    if i[j]==1:
      for k in range(a_li[j]):
        x=xy_li[j][k][0]
        y=xy_li[j][k][1]
        if i[x-1]!=y:
          flag=False
          break
  if flag:
    count=(sum(i))
    if ans<=count:
      ans=count
    
print(ans)

Solution (Python):
import numpy as np
import sys
n = int(input())
q = []
def judge():
    state = True
    for i in range(n):
        if li[i] == 0:
            continue
        else:
            for j in range(len(q[i])):
                if li[q[i][j][0]] != q[i][j][1]:
                    return False
                else:
                    state = True
    if state == False:
        return False
    else:
        return True

for i in range(n):
    xy = []
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        xy.append([x-1,y])
    q.append(xy)
maxans = 0
for i in range(2**n):
    li = [0]*n
    ans = 0
    for j in range(n):
        if (i>>j)&1:
            li[n-j-1] = 1
    if judge() == True:
        ans = sum(li)
        maxans = max(maxans,ans)
    else:
        continue
print(maxans)

Solution (Python):

n = int(input())
ans = 0

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

for i in range(2 ** n):
    flg = True
    res = 0
    for j in range(n):
        if (i >> j) & 1:
            res += 1
            for k in range(len(pr[j])):
                x, y = pr[j][k]
                if ((i >> x) & 1 and y == 0) or (not((i >> x) & 1) and y == 1):
                    flg = False
                    break
    if flg:
        ans = max(ans, res)
        
print(ans)

Solution (Python):

"""
Created on Fri Mar 13 13:52:16 2020

@author: Kanaru Sato
"""

n = int(input())
a = []
proof = []

for i in range(n):
    a.append(int(input()))
    p = [list(map(int, input().split())) for j in range(a[-1])]
    proof.append(p)

honest = 0

for state in range(2**n):   
    flag = 0
    for j in range(n):
        if flag == 1:
            break
        if state&(0b1<<j):    
            for k in range(a[j]):
                proofee = proof[j][k][0]-1
                if bool(state&(0b1<<proofee)) != (proof[j][k][1]):   
                    flag = 1    
                    break
    if flag == 0:
        count = 0
        for i in range(n):
            count += (state>>i)&0b1
        if honest <= count:
            honest = count
print(honest)

Solution (Python):
def count_bit(target):
    result, tmp = 0, target
    while tmp > 0:
        result += tmp & 1
        tmp = tmp >> 1
    return result


N = int(input())
mask_list = []
a_list = []
for i in range(N):
    A = int(input())
    mask, a = 0, 0
    for j in range(A):
        x, y = map(lambda z: int(z), input().split())
        mask += (1 << (x - 1))
        a += (y << (x - 1))
    mask_list.append(mask)
    a_list.append(a)
count = 0
for i in range(1, 2 ** N):
    is_ok = True
    for j, (m, a) in enumerate(zip(mask_list, a_list)):
        if i & (1 << j) == 0:
            continue
        if (i & m) ^ a > 0:
            is_ok = False
            break
    if is_ok:
        bit_count = count_bit(i)
        if count < bit_count:
            count = bit_count
print(count)

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


ans = 0
for i in range(2**n):
    ok = True
    cnt = 0
    jdg = str(bin(i)[2:]).zfill(n)
    
    for j in range(n):
        if (i >> j) & 1: 
            
            for x, y in info[j]:
                if jdg[-x] != str(y):
                    ok = False
        if j == n-1:
            cnt = jdg.count('1')

    if ok and ans < cnt:
        ans = cnt

print(ans)

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


ans = 0
for i in range(1<<n):   
    flug = True
    honest_num = 0
    for j in range(n):  
        if i & (1<<j):      
            honest_num += 1
            for k in range(a[j]):   
                x = xy[j][k][0]
                y = xy[j][k][1]
                
                if (i>>(x-1)) & 1 != y: 
                    flug = False
                    
    
    if flug:
        if honest_num > ans:
            ans = honest_num
print(ans)

Solution (Python):
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

s = []
N = int(input())
A=[]
Rules=[]

def check():
    for i in range(len(Rules)):
        if s[i] != True:
            continue
        r = Rules[i]
        for rr in r:
            (x,y) = rr
            if y == 1:
                if s[x -1 ] == False:
                    return False
            else:
                if s[x-1] == True:
                    return False
            
    return True

for _ in range(N):
    a = ni()
    A.append(a)
    r = []
    for _ in range(a):
        rr = nl()
        r.append(rr)
    Rules.append(r)



l = 2 **N 
maxgood = 0
for i in range(1,l ):
    s=[]
    ix = i 
    good = 0
    for _ in range(N):
        if ix %2 != 0:
            good += 1
        s.append(ix%2 !=0 )
        ix = ix //2
    
    if good > maxgood:
        if check():
            maxgood = good
print(maxgood)

Solution (Python):
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

s = []
N = int(input())
A=[]
Rules=[]

def check():
    for i in range(len(Rules)):
        if s[i] != True:
            continue
        r = Rules[i]
        for rr in r:
            (x,y) = rr
            if y == 1:
                if s[x -1 ] == False:
                    return False
            else:
                if s[x-1] == True:
                    return False
            
    return True

for _ in range(N):
    a = ni()
    A.append(a)
    r = []
    for _ in range(a):
        rr = nl()
        r.append(rr)
    Rules.append(r)



l = 2 **N 
maxgood = 0
for i in range(1,l ):
    s=[]
    ix = i 
    good = 0
    for _ in range(N):
        if ix %2 != 0:
            good += 1
        s.append(ix%2 !=0 )
        ix = ix //2
    
    if good > maxgood:
        if check():
            maxgood = good
print(maxgood)