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 random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
import bisect
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy

N = int(input())
T = [None]*N
for i in range(N):
    Ai = int(input())
    T[i] = [-1]*N
    for j in range(Ai):
        xij, yij = map(int, input().split())
        dump(i, xij-1, yij)
        T[i][xij-1] = yij
dump(T)


def imply(p, q): return (not p) or q


ans = -1
for trusts in it.product([0, 1], repeat=N):
    dump(trusts)
    ok = True
    for i, trust in enumerate(trusts):
        if trust:
            for j, tij in enumerate(T[i]):
                ok = ok and imply(tij == 1, trusts[j]) and (
                    imply(tij == 0, not trusts[j]))
    if ok:
        ans = max([ans, len([i for i in trusts if i == 1])])
    dump(ans)
print(ans)

Solution (Python):
N = int(input())
a = [[] for i in range(N)]
ans = 0
for i in range(N):
    times = int(input())
    for j in range(times):
        a[i].append(tuple(map(int, input().split())))

for i in range(2 ** N):
    flag2 = False
    cnt = 0
    flag = [0] * N
    for j in range(N):
        if (i >> j) & 1:
            flag[j] = 1
    for k in range(N):
        if flag[k] == 1:
            for m in range(len(a[k])):
                x, y = a[k][m]
                if flag[x - 1] != y:
                    flag2 = True
                    break
        if flag2:
            break
        if k == N - 1:
            cnt = flag.count(1)

    ans = max(ans, cnt)
print(ans)

Solution (Python):
N = int(input())
info = [0]
for _ in range(N):
    A = int(input())
    tmp = []
    for i in range(A):
        x, y = map(int, input().split())
        tmp.append((x, y))
    info.append(tmp)

ans = 0
for i in range(2**N):
    i_bin = list(map(int, bin(i)[2:].zfill(N)))
    ok = 1
    for j in range(1, N+1):
        for x, y in info[j]:
            if i_bin[j-1] == 1:
                if i_bin[x-1] != y:
                    ok = 0
    if ok:
        ans = max(ans, sum(i_bin))
print(ans)

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

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

ans = 0
for b in range(2**N):
    bit = str(bin(b))[2:].zfill(N)
    p = list(map(int, bit))
    for i in range(N):
        if p[i] == 0:
            continue
        for x, y in xy[i]:
            if p[x-1] != y:
                break
        else:
            continue
        break
    else:
        ans = max(ans, p.count(1))

print(ans)

Solution (Python):
n = int(input())
Adj = [[-1]*n for _ in range(n)]

for i in range(n):
    ai = int(input())
    for j in range(ai):
        xij,yij = map(int, input().split( ))
        xij -= 1
        Adj[i][xij] = yij

ans = 0

bt = 1<<n

for b in range(bt):
    flag = True
    tmp = 0
    for i in range(n):
        for j in range(n):
            if Adj[i][j]>=0:
                if ((b>>i) &1) and (((Adj[i][j]==0) and ((b>>j) &1)) or ((Adj[i][j]==1) and (not (b>>j) &1))):
                    flag = False
                    break
        if not flag:
            break
    if flag:
        for t in range(n):
            tmp += (b>>t)&1
            
    ans = max(tmp, ans)
    
print(ans)

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

ans=0
for i in range(2**N):
    X=[0]
    I=i
    for j in range(N):
        X.append(I//(2**(N-1-j)))
        I%=(2**(N-1-j))
    
    F=1
    for k in range(1,N+1):
        
        if X[k]==1:
            for z in range(len(L[k])):
                a,b=L[k][z]
                
                if X[a]!=b:
                    F=0
                    break
        
    if F==1:
        if ans<sum(X):
            ans=sum(X)
    
print(ans)

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

ok = []
for i in range(2**N):
    v = [0] * (N+1)
    n = i
    for j in range(1, N+1):
        v[j] = n % 2
        n >>= 1
    for k, xys in enumerate(A):
        if v[k+1] == 1:
            for xy in xys:
                if xy[1] != v[xy[0]]:
                    break
            else:
                continue
            break
    else:
        ok.append(v)

ans = 0
for a in ok:
    ans = max(ans,sum(a))
print(ans)

Solution (Python):
def read_valus():
    return map(int, input().split())


def read_list():
    return list(read_valus())


def read_lists(N):
    return [read_list() for n in range(N)]


def f(T, n):
    N = len(T)
    b = format(n, "015b")[::-1][:N]
    
    for n, s in enumerate(b):
        if s == "1":
            for x, y in T[n]:
                if int(b[x]) != y:
                    return False
    return True


def main():
    N = int(input())
    T = [[] for n in range(N)]
    for n in range(N):
        A = int(input())
        for _ in range(A):
            x, y = read_valus()
            x -= 1
            T[n].append((x, y))

    res = 0
    for n in range(2 ** N - 1, -1, -1):
        bit_count = bin(n).count("1")
        if res >= bit_count:
            continue

        if f(T, n):
            res = max(res, bit_count)  

    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
statement = []
for _ in range(N):
    A = int(input())
    temp = {}
    for _ in range(A):
        x, y = map(int, input().split())
        temp[x-1] = y
    statement.append(temp)
ans = 0
for i in range(2**N):
    honest = []
    for j in range(N):
        if (i >> j) & 1: honest.append(j)
    for h in honest:
        contradiction = False
        for j, y in statement[h].items():
            if (y == 1 and j not in honest) or (y == 0 and j in honest): contradiction = True; break
        if contradiction: break
    else:
        ans = max(format(i, 'b').count('1'), ans)
print(ans)

Solution (Python):
n=int(input())
comments=[]
for i in range(n):
    num=int(input())
    comment=[]
    for j in range(num):
        comment.append(list(map(int,input().split(" "))))
    comments.append(comment)


ans=0
for i in range(2**n):
    judges=[[] for i in range(n)]
    condition=list(str(format(i,'b').zfill(n)))
    conflict=False
    
    for idx,j in enumerate(condition):
        person_num=idx
        if j=='1':
            for comment in comments[person_num]:
                judges[comment[0]-1].append(comment[1])
    for jdx,judge in enumerate(judges):
        if len(judge)==0:
            pass
        if judge.count(int(condition[jdx])) != len(judge):
            conflict=True
            break
    if not conflict:
        ans=condition.count('1')
    
print(ans)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    M = [[None] * (N) for _ in range(N)]

    for k, v in A.items():
        for x, y in v:
            M[k-1][x-1] = y

    for i in range(N, 0, -1):
        for m in combinations(range(N), r=i):
            sm = set(m)
            f = True
            for j in m:
                for k, v in enumerate(M[j]):
                    if v == 1 and k not in sm:
                        f = False
                        break
                    elif v == 0 and k in sm:
                        f = False
                        break
                if not f:
                    break

            if f:
                return i
    return 0


def main():
    N = read_int()
    A = {}
    for i in range(1, N+1):
        n = read_int()
        XY = [read_int_n() for _ in range(n)]
        A[i] = XY
    print(slv(N, A))


if __name__ == '__main__':
    main()

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

t = [[] for i in range(n)]
s = [[] for i 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 = []
xy = [[] for i in range(n)]
for i in range(n):
    ai = int(input())
    a.append(ai)
    for j in range(ai):
        xyi = list(map(int, input().split()))
        xy[i].append(xyi)
res = 0
for i in range(2 ** n):
    flag = [(1 if i & 2 ** b == 2 ** b else 0) for b in range(n)]
    outs = 0
    for j in range(n):
        if flag[j] == 1:
            for k in range(a[j]):
                x, y = xy[j][k]
                x -= 1
                if flag[x] != y:
                    outs = 1
                    break
    if outs == 0:
        res = max(sum(flag), res)

print(res)

Solution (Python):
n = int(input())
matrix = [[-1 for j in range(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())
    matrix[i][x - 1] = y

ans = 0
for i in range(2 ** n):
  str_i = format(i, "0" + str(n) + "b")
  flag = True
  for j in range(n):
    if str_i[j] == "1":
      for k in range(n):
        if matrix[j][k] >= 0 and matrix[j][k] != int(str_i[k]):
          flag = False
          break
  if flag:
    ans = max(ans, str_i.count('1'))

print(ans)

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

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

for i in range(n):
    messages = int(input())
    for _ in range(messages):
        talk[i].append(tuple(map(int, input().split())))

res = 0

for key in range(2 ** n):
    flag = True
    answer = [0 for i in range(n)]
    for i in range(n):
        if key & (1 << i) > 0:
            answer[i] = 1

    for i in range(n):
        if answer[i] == 0:
            continue
        for t in talk[i]:
            person = t[0] - 1
            if t[1] != answer[person]:
                flag = False
                break

    if flag:
        res = max(res, sum(answer))

print(res)

Solution (Python):
def honest_or_unkind_2(N: int, testimonies: dict)->int:
    ans = 0
    for i in range(1 << N):
        honest_num = 0
        for j in range(N):
            if i & (1 << j) == 0:
                continue
            honest_num += 1

            
            for k, is_honest in testimonies[j]:
                if bool(i & (1 << k)) != is_honest:
                    
                    break
            else:
                
                continue
            
            break
        else:
            
            ans = max(ans, honest_num)
        

    return ans


if __name__ == "__main__":
    N = int(input())
    testimonies = {}

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

    ans = honest_or_unkind_2(N, testimonies)
    print(ans)

Solution (Python):
def is_same_as_ptypes(j, ptypes):
  for x,y in A[j]:
    if ptypes[x] != str(y):
      return False
  return True  
  

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

ans = 0
for i in range(2**N):
  ptypes = bin(i)[2:].zfill(N)
  flag = True
  for j in range(len(ptypes)):
    if ptypes[j] == '0':continue
    if is_same_as_ptypes(j,ptypes) is False:
      flag = False
  if flag is True: ans = max(ptypes.count('1'), ans)
print(ans)

Solution (Python):
N = int(input())
XY_LIST = [[list(map(int, input().split())) for _ in range(int(input()))] for _ in range(N)]

def count_honest(i):
    l = [(i>>j)%2 for j in range(N)]
    for j in range(N):
        if (i>>j)%2 == 0:
            continue
        for x, y in XY_LIST[j]:
            x = x-1
            if l[x] == y:
                continue
            return 0
    return sum(l)

max_honest = 0
for i in range(1<<N):
    honest = count_honest(i)
    max_honest = max(max_honest, honest)

print(max_honest)

Solution (Python):
N=int(input())
matrix=[[-1 for _ in range(N+1)] for _ in range(N+1)]
for i in range(1, N+1):
    Ai=int(input())
    for j in range(Ai):
        x, y=map(int, input().split())
        matrix[i][x]=y
ans=0
for i in range(1, 2**N):
    honests=[]
    tmp=i
    j=1
    while tmp>0:
        if tmp%2==1:
            honests.append(j)
        tmp=tmp//2
        j+=1
    flag=True
    for j in honests:
        for k in range(1, N+1):
            if (matrix[j][k]==1 and k not in honests) or (matrix[j][k]==0 and k in honests):
                flag=False
                break
        if not flag:
            break
    if flag:
        ans=max(ans, len(honests))
print(ans)

Solution (Python):
N=int(input())
H=[[] for i in range(N+1)];H[0]=None 
U=[[] for i in range(N+1)];U[0]=None
for i in range(1,N+1):
    A=int(input())
    for j in range(A):
        x,y=map(int,input().split())
        if y==1:
            H[i].append(x)
        elif y==0:
            U[i].append(x)




ans=0
for k in range(1<<N):
    f=[None]
    f.extend([k>>i&1 for i in range(N)])
    
    m=sum(f[1:]) 
    if m<=ans:
        continue
    g=True 
    for i in range(1,N+1): 
        if not g:
            break
        if not f[i]: 
            continue
        for j in H[i]: 
            if not f[j]: 
                g=False
                break
        for j in U[i]: 
            if f[j]:
                g=False
                break
    if g:
        ans=m

print(ans)

Solution (Python):
from itertools import product
N=int(input())
XYs = []
for i in range(N):
    A = int(input())
    XYs.append([tuple(map(int, input().split())) for _ in range(A)])

n=0
for ts in product(*[[1, 0] for _ in range(N)]):
    for i, t in enumerate(ts):
        if t:
            if not all(ts[x-1] == y for x, y in XYs[i]):
                break
    else:
        n=max(n,sum(ts))
print(n)

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

A = [0]*n
x = []
y = []
for i in range(n):
    A[i] = int(input())
    xx = []
    yy = []
    for j in range(A[i]):
        xxx,yyy = map(int,input().split())
        xx.append(xxx)
        yy.append(yyy)
    x.append(xx)
    y.append(yy)


max = 0
B = (0,1)
false = 0
for i in itertools.product(B, repeat=n):
    for j in range(n):
        for k in range(A[j]):
            if i[j] == 1 and (i[x[j][k]-1] != y[j][k]):
                false = 1
                break
        if j == n-1:
            if max <= i.count(1) and not(false):
                max = i.count(1)
                ans = i
    false = 0


print(max)

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

ans=0
for i in range(2**n):
  flg=list(map(int,bin(i)[2:].zfill(n)))
  s=0
  for j in range(n):
    if flg[j]==1:
      for k in range(a[j]):
        if flg[xy[j][k][0]-1]!=xy[j][k][1]:
          s=1
  if s==0:
    ans=max(ans,sum(flg))
print(ans)

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

ans = 0
for i in range(2**n):
  TF = [ 1 & i >> j for j in range(n)]
  bool = True
  for j in range(n):
    if TF[j] == 1:
      for says in people[j]:
        if TF[says[0]-1] == says[1]:
          pass
        else:
          bool = False
          break
    else:
      pass

  if bool:
    ans = max(ans,TF.count(1))

print(ans)

Solution (Python):
import itertools
N = int(input())
ans = 0
A = []
aa = []
for n in range(N):
    a = int(input())
    aa.append(a)
    xy = [list(map(int,input().split())) for i in range(a)]
    A.append(xy)
for v in itertools.product([1,0], repeat = N):
    s = 1
    for i in range(N):
        if v[i] == 1:
            t = 1
            for j in range(aa[i]):
                if v[A[i][j][0]-1] != A[i][j][1]:
                    t = 0
                    break
            if t != 1:
                s = 0
                break
    if s == 1:
        break
print(v.count(1))

Solution (Python):
import sys
from itertools import product

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ps = [[] for i in range(n)]
    
    for i in range(n):
        a = II()
        for j in range(a):
            ps[i].append(LI())
    max_ = 0
    for c in product([0, 1], repeat=n):
        c = list(c)
        
        for i, p in enumerate(c):
            if p == 1:
                for opp in ps[i]:
                    
                    if c[opp[0] - 1] != opp[1]:
                        
                        break
                else:
                    continue
                break
        else:
            
            max_ = max(max_, sum(c))
    print(max_)

if __name__ == '__main__':
    main()

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


bit = 0
ans = 0
for X in range(2 ** n):
    
    flag = False
    count = 0
    for num in range(n):
        f = True
        if X & (2 ** num) >= 1:
            for x, y in xy[num]:
                t = 1 if X & 2 ** (x-1) >= 1 else 0
                if t != y:
                    f = False
                    break
            if f == False:
                count = 0
                break
            count += 1
    ans = max(count, ans)
print(ans)

Solution (Python):
N = int(input().strip())
datas = []
for _ in range(N):
    A = int(input().strip())
    datas.append([[int(str) for str in input().strip().split()] for _ in range(A)])

def judge(bit):
    true_man = [(bit & (1 << d)) >> d for d in range(N)]

    for i in range(N):
        if true_man[i]:
            for data in datas[i]:
                if true_man[data[0] - 1] != data[1]:
                    return 0

    return sum(true_man)

ans = 0
for bit in range(2 ** N):
    ans = max(ans, judge(bit))

print(ans)

Solution (Python):

import itertools
N = int(input())
coms = []
for n in range(N):
    A = int(input())
    com = []
    for a in range(A):
        tmp = list(map(int,input().split()))
        com.append(tmp)
    coms.append(com)

nums = [0, 1]
ans = 0
for pt in itertools.product(nums, repeat=N):
    flag = False
    
    if sum(pt) > ans:
        for idx in range(len(pt)):
            if pt[idx]==1:
                for com in coms[idx]:
                    if pt[com[0]-1] + com[1] == 1:
       
                        flag = True
        if not flag:
            ans = sum(pt)
            
    else:
        pass
        

print (ans)

Solution (Python):
def binp( n ):
    global N
    data = []
    for i in range(N):
        data.append( n % 2)
        n //= 2
    return data

def honest(pat):
    c = 0
    for p in pat:
        if p == 1:
            c+=1
    return c

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

ans = 0
for p in range(2**N):
    pat = binp(p)
    
    f = True
    for i in range(N):
        if pat[i] == 1:
            for x,y in Data[i]:
                
                if (y == 0 and pat[x-1] == 0) or (y == 1 and pat[x-1] == 1):
                    pass
                    
                else:
                    f = False
                    break
            if f == True:
                pass
            else:
                break
    if f :
        ans = max(ans,honest(pat))
print(ans)

Solution (Python):
n=int(input())
xy_list=[]
for i in range(n):
    a=int(input())
    xy=[]
    for _ in range(a):
        xy.append(list(map(int,input().split())))
    xy_list.append(xy)
ans=0
for i in range(2**n):
    i_2=format(i,"0"+str(n)+"b")
    flag=1
    for j in range(n):
        if i_2[j]=="1":
            for x,y in xy_list[j]:
                if i_2[x-1]!=str(y):
                    flag=0
    if flag==1: 
        ans=max(ans,i_2.count("1"))
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    all_remark = []
    for i in inputs:
        all_remark.append(list(map(string_to_int, i)))
    n = len(all_remark)
    max_pattern = 2**n

    max_shojiki = 0
    for p in range(max_pattern):
        bits = list(bin(p)[2:])
        bits = ['0' for i in range(n-len(bits))] + bits
        shojiki = 0
        for b in bits:
            if b == '1':
                shojiki += 1

        for i, remarks in enumerate(all_remark):
            is_possible = True
            if bits[i] == '1':
                for r in remarks:
                    target = r[0]
                    w = r[1]
                    if bits[target - 1] != str(w):
                        is_possible = False
                        break
                if is_possible is False:
                    break
        if is_possible and max_shojiki < shojiki:
            max_shojiki = shojiki
    return max_shojiki


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    N = int(input())
    arg = []
    for i in range(N):
        A = int(input())
        arg.append(inputs(A))
    ret = solve(arg)
    print(ret)

Solution (Python):

n = int(input())
al = []
lll = []
for _ in [0]*n:
  al.append(int(input()))
  ll = [list(map(int,input().split())) for _ in [0]*al[-1]]
  lll.append(ll)
  


katei = []
for i in range(2**n):
  l = []
  for j in range(n-1,-1,-1):
    if i>= 2**j:
      l.append(1)
      i -= 2**j
    else:
      l.append(0)
  katei.append(l)

ans = 0
for i in range(len(katei)):
  flag = True
  for j in range(n):
    if katei[i][j] == 1: 
      for l in lll[j]:
        if l[1] != katei[i][l[0]-1]:
          flag = False
  if flag:
    ans = max(sum(katei[i]),ans)

print(ans)

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

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

    ans = 0
    for i in range(1<<N):
        T = []
        F = []
        for j in range(N):
            if (i>>j) & 1:
                T.append(j)
            else:
                F.append(j)
        flag = False
        for t in T:
            for x, y in X[t]:
                if y == 1:
                    if x in F:
                        flag = True
                        break
                else:
                    if x in T:
                        flag = True
                        break
            if flag:
                break
        if not flag:
            ans = max(ans, len(T))

    print(ans)





if __name__ == "__main__":
    main()

Solution (Python):
from itertools import combinations

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




for k in reversed(range(N)): 
    
    comb = combinations(range(N),k+1)
    
    for pattern in comb: 
        l = [-1]*N
        b=1
        syogen = []
        for i in range(N):
            if i in pattern:
                l[i] = 1
            else:
                l[i] = 0

        
        
        for person in pattern:
            syogen = syogens[person]
            for s in syogen:
                
                target = s[0]
                value = s[1]
                if value != l[target-1]:
                    b = 0
        if b == 1:
            print(k+1)
            exit()

print(0)

Solution (Python):
import itertools
from collections import defaultdict

def ok_bit(bit):
    for i in range(N):
        if bit[i] == 0:
            continue
        for x, y in evidence_dict[i]:
            if y != bit[x-1]:
                return False
    return True



def solver():
    for bit in reversed(bit_list):
        if ok_bit(bit):
            return bit
    return [0]

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

L = [0, 1]
bit_list = list(itertools.product(L, repeat=N))


if __name__ == "__main__":
    ans_bit = solver()
    res = 0
    for b in ans_bit:
        if b==1:
            res+=1
    print(res)

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

ans = 0

for bit in range(1 << n):
    syojiki = []
    flag = True

    for i in range(n):
        
        if bit & (1 << i):
            syojiki.append(1)
        else:
            syojiki.append(0)

    for i in range(n):
        for j in b[i]:  
            if syojiki[i] and syojiki[j[0]] != j[1]:
                flag = False
    if flag:
        ans = max(ans, sum(syojiki))

print(ans)

Solution (Python):
import itertools
def main():
    N = int(input())
    d = {}
    for i in range(N):
        a = int(input())
        d[i] = []
        for _ in range(a):
            x, y = map(int, input().split())
            d[i].append((x-1,y))
    for i in range(N+1):
        for j in itertools.combinations(range(N), i):
            for k in range(N):
                a = 0
                if k not in j:
                    for x, y in d[k]:
                        if y == 0 and x not in j:
                            a += 1
                        if y == 1 and x in j:
                            a += 1
                if a > 0:
                    break
            else:
                return N - i
print(main())

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A=[0]*N
    x=[[] for _ in range(N)]
    y=[[] for _ in range(N)]
    for i in range(N):
        A[i]=int(input())
        x[i]=[0]*A[i]
        y[i]=[0]*A[i]
        for j in range(A[i]):
            X,Y=map(int,input().split())
            x[i][j],y[i][j]=X-1,Y
    ans=0
    for i in range(2**N):
        l=[-1]*N
        f=True
        for j in range(N):
            if (i >> j) & 0b1 == 1:
                if l[j] != 0:
                    l[j]=1
                    for k in range(A[j]):
                        if l[x[j][k]] == -1:
                            if y[j][k] == 1 and (i >> x[j][k]) & 0b1 == 1:
                                l[x[j][k]] = y[j][k]
                            elif y[j][k] == 0:
                                l[x[j][k]] = y[j][k]
                            else:
                                f=False
                                break
                        else:
                            if l[x[j][k]] != y[j][k]:
                                f=False
                                break
                    if f==False:
                        break
                else:
                    f=False
                    break
        if f==True:
            c=0
            for i in l:
                c+=1 if i==1 else 0
            ans=max(ans,c)
    print(ans)
                

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
people = [[] for _ in range(N)]
for i in range(N):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        x -= 1
        people[i].append([x, y])
ans = 0  
for mask in range(1 << N):  
    binary_status = []

    for i in range(N):
        binary_status.append((mask >> i) & 1)
    
    flag = True
    for i in range(len(binary_status)):
        if binary_status[i] == 0:
            continue
        for j in range(len(people[i])):
            
            
            

            if binary_status[people[i][j][0]] != people[i][j][1]:
                flag = False
    if flag:
        if sum(binary_status) > ans:
            ans = sum(binary_status)

print(ans)

Solution (Python):
N = int(input())
syougen = [[] for i in range(N)]
for i in range(N):
    a_tmp = int(input())
    for j in range(a_tmp):
        [x, y] = list(map(int,input().split()))
        syougen[i].append([x-1,y])
ans = 0
for i in range(2**N):
    data = [0]*N
    for j in range(N):
        if ((i >> j) & 1):
            data[j] = 1
    flag = True
    for k in range(N):
        if data[k] == 1:
            for l in range(len(syougen[k])):
                x = syougen[k][l][0]
                y = syougen[k][l][1]
                if data[x] != y:
                    flag = False
    if flag:
        ans = max(ans,sum(data))
print(ans)