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):

def main():
    import numpy as np

    N = int(input())
    testimony = np.zeros((N, N), dtype=np.int64)
    for i in range(N):
        A = int(input())
        INF = 10 ** 10
        for _ in range(A):
            x, y = map(int, input().split())
            testimony[i, x - 1] += 1 if y else -INF

    
    ans = 0
    for bit in range(1 << N):
        honest = set()
        pick = np.zeros(N, dtype=np.int64)
        for i in range(N):
            if bit & (1 << i):
                honest.add(i)
                pick += testimony[i, :]
        flag = True
        for j in range(N):
            value = pick[j]
            
            if (0
                    or (j in honest and value < 0)         
                    or (j not in honest and value > 0)     
                    or (value < 0 and value % INF != 0)):  
                flag = False
                break
        if flag:
            ans = max(ans, len(honest))
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
xy = [[] for _ in range(N)]

for i in range(N):
  A = int(input())
  for _ in range(A):
    xy[i].append(list(map(int, input().split())))
lst = [[0 for j in range(N)] for k in range(2**N)]

for l in range(2**N):
  for m in range(N):
    if (l >> m) & 1:
      lst[l][m] = 1

ans = 0
for n in lst:
  flag = True
  for f in range(N):
    if n[f] == 1:
      for g in xy[f]:
        if n[g[0]-1] != g[1]:
          flag = False
          break
    else:
      tmp = 0
      for g in xy[f]:
        if n[g[0]-1] == g[1]:
          tmp += 1
      if tmp == len(n):
        flag = False
    if not flag:
      break
  if flag:
    ans = max(ans, n.count(1))
print(ans)

Solution (Python):


N = int(input())

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

ans = 0
for i in range(1<<N):
    bit = [0] * N
    cnt = 0
    for j in range(N):
        div = 1 << j
        bit[j] = (i // div) % 2
        if bit[j] == 1:
            cnt += 1

    flag = True
    for j in range(N):
        if bit[j] == 0:
            continue
        for a in range(A[j]):
            x = data[j][a]
            if bit[x[0]-1] != x[1]:
                flag = False
                break
        if not flag:
            break
    
    if flag:
        ans = max(ans, cnt)

print(ans)

Solution (Python):
N = int(input())
testimony = [[-1]*N for i in range(N)]
count = 0
for i in range(N):
  A = int(input())
  for j in range(A):
    x,y = map(int,input().split())
    testimony[i][x-1]=y
for i in range(2**N):
  honest = [0]*N
  for j in range(N):
    if(i>>j)&1:
      honest[j]=1
  flag=True
  for j in range(N):
    if honest[j]==1:
      for k in range(N):
        if testimony[j][k]==-1:
          continue
        if testimony[j][k]!=honest[k]:
          flag=False
  if flag==True:
    count=max(count,honest.count(1))
print(count)

Solution (Python):
N = int(input())
testimo_ls = [ [] for i in range(N) ]
rst = 0
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split(' '))
        testimo_ls[i].append([x - 1, y])
for i in range(1 << N):
    honest_ls = []
    for j in range(N):
        if i >> j & 1:
            honest_ls.append(j)
    is_ok = True
    for s in honest_ls:
        for t in testimo_ls[s]:
            if t[0] in honest_ls and t[1] == 0:
                is_ok = False
                break
            if t[0] not in honest_ls and t[1] == 1:
                is_ok = False
                break
    if is_ok:
        rst = max(rst, len(honest_ls))
print(rst)

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
for bit_state in range(2**N):
  flag=True
  for i in range(N):
    if (bit_state>>i)&1:
      for x, y in XY[i]:
        if (bit_state >>x)&1 != y:
          flag=False
  if flag:
    ans=max(ans, bin(bit_state).count("1"))
    
print(ans)

Solution (Python):
N = int(input())
testimo_ls = [ [] for i in range(N) ]
rst = 0
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split(' '))
        testimo_ls[i].append([x - 1, y])
for i in range(1 << N):
    honest_ls = []
    for j in range(N):
        if i >> j & 1:
            honest_ls.append(j)
    is_ok = True
    for s in honest_ls:
        for t in testimo_ls[s]:
            if t[1] == 0 and t[0] in honest_ls:
                is_ok = False
                break
            if t[1] == 1 and t[0] not in honest_ls:
                is_ok = False
                break
    if is_ok:
        rst = max(rst, len(honest_ls))
print(rst)

Solution (Python):
from itertools import product

n = int(input())
info = {}
for p in range(n):
    a = int(input())
    L = []
    for _ in range(a):
        x,y = list(map(int, input().split()))
        x,y = x-1, y
        L.append((x,y))
    info[p] = L

ans = 0
for bit_pattern in product(range(2), repeat=n):
    for p,bit in enumerate(bit_pattern):
        if bit:
            if not all([bit_pattern[x] == y for x,y in info[p]]):
                break
    else:
        ans = max(ans, sum(bit_pattern))

print(ans)

Solution (Python):
from itertools import product

n = int(input())
data = {}
for p in range(1, n+1):
    a = int(input())
    
    data[p] = [list(map(int, input().split())) for _ in range(a)]
    

ans = 0
for honest in product(range(2), repeat=n):
    for p,hk in enumerate(honest, 1):
        if hk == 1:
            
            if not all([honest[x-1] == y for x,y in data[p]]):
                break
    else:
        ans = max(ans, sum(honest))

print(ans)

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

ans = 0
for i in range(2**n):
    s = bin(i)[2:].zfill(n)
    f = True
    for j,k in enumerate(a):
        for x,y in k:
            
            if s[x-1] != str(y) and s[j] == '1': f = False
    if f: ans = max(ans, s.count('1'))

print(ans)

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

l = []
aas = []

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

for i in range(2**n):
    flag_n = [1]*n
    for j in range(n):
        if ((i >> j)&1):
            flag_n[n-1-j] = 0
    cnt = 0
    for k in range(n):
        if flag_n[k] == 1:
            if all(l[k][m][1] == flag_n[l[k][m][0]-1] for m in range(aas[k])):
                cnt += 1
        if cnt == sum(flag_n):
            print(sum(flag_n))
            exit()

print(0)

Solution (Python):
n = int(input())
xy = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x_,y_ = map(int,input().split())
        xy[i].append((x_-1,y_))
ans = 0
for i in range(1,2**n):
    flag = 0
    for j in range(n):
        if i>>j&1:
            for x,y in xy[j]:
                if i>>x&1 != y:
                    flag = 1 
                    break
    if flag==0:
        ans = max(ans, bin(i)[2:].count("1"))
print(ans)

Solution (Python):
N = int(input())
testimo_ls = [ [] for i in range(N) ]
rst = 0
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split(' '))
        testimo_ls[i].append([x - 1, y])
for i in range(1 << N):
    honest_ls = []
    for j in range(N):
        if i >> j & 1:
            honest_ls.append(j)
    is_ok = True
    for s in honest_ls:
        for t in testimo_ls[s]:
            if t[0] not in honest_ls and t[1] == 1:
                is_ok = False
                break
            if t[0] in honest_ls and t[1] == 0:
                is_ok = False
                break
    if is_ok:
        rst = max(rst, len(honest_ls))
print(rst)

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

mastar_list = []
for i in range(2 ** N):
    x = "{:0" + str(N) + "b}"
    mastar_list.append(list(map(int,x.format(i))))


current = 1
ans = []
judge = [True for i in range(2 ** N)]
while current <= N:
    now = current -1
    loop_num = int(input())
    for i in range(loop_num):
        a,b = map(int,input().split())
        c = a - 1
        for index, situation in enumerate(mastar_list):
            if situation[now] == 1:
                if situation[c] == b:
                    pass
                else:
                    judge[index] = False
            else:
                pass
    current += 1

ans = []
for index, content in enumerate(judge):
    if content:
        ans.append(sum(mastar_list[index]))
        
print(max(ans))

Solution (Python):
from sys import stdin, stdout 

max_honest = 0
testomonies = []
state = []

def dfs(person):
    global max_honest
    if person >= len(state):
        correctState = True
        for p in range(len(state)):
            if state[p] == 1:
                for t in testomonies[p]:
                    x, y = t
                    if state[x] != y:
                        correctState = False
                        break
        if correctState:
            sum = 0
            for s in state:
                sum += s
            max_honest = max(max_honest, sum)
        return

    state[person] = 0
    dfs(person + 1)

    state[person] = 1 
    dfs(person + 1)
    

def solve():
    global state
    n = int(stdin.readline())
    for _ in range(n):
        a = int(stdin.readline())
        t = []
        for _ in range(a):
            x, y = [int(inp) for inp in stdin.readline().split()]
            t.append((x - 1,y))
        testomonies.append(t)
    
    state = [-1] * n
    dfs(0)
    print(max_honest)


def main():
    solve()


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin, stdout 

max_honest = 0
testomonies = []
state = []

def dfs(person):
    global max_honest
    if person >= len(state):
        correctState = True
        for p in range(len(state)):
            if state[p] == 1:
                for t in testomonies[p]:
                    x, y = t
                    if state[x] != y:
                        correctState = False
                        break
        if correctState:
            sum = 0
            for s in state:
                sum += s
            max_honest = max(max_honest, sum)
        return

    state[person] = 0
    dfs(person + 1)

    state[person] = 1 
    dfs(person + 1)
    

def solve():
    global state
    n = int(stdin.readline())
    for _ in range(n):
        a = int(stdin.readline())
        t = []
        for _ in range(a):
            x, y = [int(inp) for inp in stdin.readline().split()]
            t.append((x - 1,y))
        testomonies.append(t)
    
    state = [-1] * n
    dfs(0)
    print(max_honest)


def main():
    solve()


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin, stdout 

max_honest = 0
testomonies = []
state = []

def dfs(person):
    global max_honest
    if person >= len(state):
        correctState = True
        for p in range(len(state)):
            if state[p] == 1:
                for t in testomonies[p]:
                    x, y = t
                    if state[x] != y:
                        correctState = False
                        break
        if correctState:
            sum = 0
            for s in state:
                sum += s
            max_honest = max(max_honest, sum)
        return

    state[person] = 0
    dfs(person + 1)

    state[person] = 1 
    dfs(person + 1)
    

def solve():
    global state
    n = int(input())
    for _ in range(n):
        a = int(input())
        t = []
        for _ in range(a):
            x, y = [int(inp) for inp in input().split()]
            t.append((x - 1,y))
        testomonies.append(t)
    
    state = [-1] * n
    dfs(0)
    print(max_honest)


def main():
    solve()


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin, stdout 

max_honest = 0
testomonies = []
state = []

def dfs(person):
    global max_honest
    if person >= len(state):
        correctState = True
        for p in range(len(state)):
            if state[p] == 1:
                for t in testomonies[p]:
                    x, y = t
                    if state[x] != y:
                        correctState = False
                        break
        if correctState:
            sum = 0
            for s in state:
                sum += s
            max_honest = max(max_honest, sum)
        return

    state[person] = 0
    dfs(person + 1)

    state[person] = 1 
    dfs(person + 1)
    

def solve():
    global state
    n = int(input())
    for _ in range(n):
        a = int(input())
        t = []
        for _ in range(a):
            x, y = [int(inp) for inp in input().split()]
            t.append((x - 1,y))
        testomonies.append(t)
    
    state = [-1] * n
    dfs(0)
    print(max_honest)


def main():
    solve()


if __name__ == "__main__":
    main()

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





maximum = 0
import itertools
for Z in itertools.product(range(2), repeat=N):
  Z = list(Z)

  for i in range(N): 
    honest = Z[i] 
    for j,y in tests[i].items():
      if honest: 
        if Z[j] != y:

          break
    else:
      
      continue
    break 
  else:

    maximum = max(maximum, sum(Z))
print(maximum)

Solution (Python):
N = int(input())
testimo_ls = [ [] for i in range(N) ]
rst = 0
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split(' '))
        testimo_ls[i].append([x - 1, y])
for i in range(1 << N):
    honest_ls = []
    for j in range(N):
        if i >> j & 1:
            honest_ls.append(j)
    is_ok = True
    for s in honest_ls:
        for t in testimo_ls[s]:
            if t[0] in honest_ls and t[1] == 0:
                is_ok = False
            if t[0] not in honest_ls and t[1] == 1:
                is_ok = False
    if is_ok:
        rst = max(rst, len(honest_ls))
print(rst)

Solution (Python):
n=int(input())
p=2
from itertools import product
iterator=product(range(p),repeat=n)



L=[[] for i in range(n)]
for i in range(n):
    a=int(input())
    for _ in range(a):
        L[i].append(list(map(int,input().split())))
ans=0
for idxs in iterator:
    cnt_honest=0
    for i in range(n):
        cnt=0
        if idxs[i]==1:
            for j in L[i]:
                if idxs[j[0]-1]==j[1]:
                    cnt+=1
            if cnt==len(L[i]):
                cnt_honest+=1
    if cnt_honest==sum(idxs):
        ans=max(sum(idxs),ans)
print(ans)

Solution (Python):

N = int(input())
testimo_ls = [ [] for i in range(N) ]
rst = 0
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split(' '))
        testimo_ls[i].append([x - 1, y])
for i in range(1 << N):
    honest_ls = []
    for j in range(N):
        if i >> j & 1:
            honest_ls.append(j)
    is_ok = True
    for s in honest_ls:
        for t in testimo_ls[s]:
            if t[1] == 0 and t[0] in honest_ls:
                is_ok = False
                break
            if t[1] == 1 and not t[0] in honest_ls:
                is_ok = False
                break
    if is_ok:
        rst = max(rst, len(honest_ls))
print(rst)

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

ans = 0
for i in range(2**n):
    s = 0
    t = [0]*n
    for j in range(n):
        if i>>j & 1:
            t[j]=1
    is_contradict = 0
    for j in range(n):
        if t[j]:
            for k in range(n):
                if li[j][k]==-1:
                    continue
                if li[j][k] != t[k]:
                    is_contradict = 1
    if not is_contradict:
        ans = max(ans, sum(t))

print(ans)

Solution (Python):
n = int(input())
lista = []
xy = []
for i in range(n):
    a = int(input())
    lista.append(a)
    s = [list(map(int, input().split())) for _ in range(a)]
    xy.append(s)
ans = 0
for j in range(2**n):
    num = 0
    d = []
    for k in range(n):
        if((j >> k) & 1) == 1:
            d.append(1)
        else:
            d.append(0)
    c = 0
    for l in range(n):
        cnt = 0
        if d[l] == 1:
            if lista[l] != 0:
                for m in range(lista[l]):
                    if xy[l][m][1] == d[xy[l][m][0] - 1]:
                        cnt += 1
                        if cnt == lista[l]:
                            c += 1
                    else:
                        break
            else:
                c += 1
    if c == d.count(1):
        num = c
    ans = max(num, ans)
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):

import sys
def read(): return sys.stdin.readline() 
def fbit(i, j=-1): return format(i, 'b').zfill(j) 
def popcount(x): 
    x=x-((x>>1)&0x5555555555555555)
    x=(x&0x3333333333333333)+((x>>2)&0x3333333333333333)
    x=(x+(x>>4))&0x0f0f0f0f0f0f0f0f;x=x+(x>>8);x=x+(x>>16);x=x+(x>>32)
    return x&0x0000007f


def solv(N:int, A, x, y):
    ans = 0
    for bits in range(1<<N):
        ok = True
        count = 0
        for i in range(N):
            if not (bits & 1<<i): continue
            count+=1
            for j in range(A[i]):
                if (bits >> (int(x[i][j])-1) & 1) ^ int(y[i][j]): ok = False
        if ok: ans = max(ans, count);


    print(ans)
def main():
    N = int(read())
    A = []
    x = []
    y = []
    for i in range(N):
        A.append(int(read()))
        _x=[]
        _y=[]
        for j in range(A[-1]):
            [a,b] = list(read().rsplit())
            _x.append(a)
            _y.append(b)
        x.append(_x)
        y.append(_y)


    solv(N, A, x, y)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from io import StringIO
import unittest
import itertools

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    n=int(readline())
    dat = [[-1 for i in range(n)] for j in range(n)]
    for i in range(n):
        m=int(readline())
        for j in range(m):
            x,y=map(int, readline().rstrip().split())
            x-=1
            dat[i][x] = y
    
    ans=0
    for ptn in itertools.product([False,True], repeat=n):
        ok=True
        for i in range(n):
            if ptn[i]==False:
                continue
            for j in range(n):
                if dat[i][j] == -1:
                    continue
                if dat[i][j] == 1 and ptn[j]==False:
                    ok=False
                    break
                if dat[i][j] == 0 and ptn[j]==True:
                    ok=False
                    break
            if ok==False:
                break
        if ok==True:
            ans=max(ans,ptn.count(True))
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

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

ans = 0
for b in range(2**N):
    bit = bin(b)[2:].zfill(N)
    flg = True
    for i in range(N):
        if bit[i] == '0': continue
        for j in range(N):
            if A[i][j] == -1: continue
            if A[i][j] != int(bit[j]):
                flg = False
                break
        
        if not flg: break

    ans = max(bit.count('1'), ans) if flg else ans

print(ans)

Solution (Python):
n = int(input())
graph = [[-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())
        graph[i][x-1] = y

ans = 0
for p in range(2**n):
    q = p
    c = 0
    t = []
    l = 0
    while q:
        if q&1:
            t.append(graph[c])
            l += 1
        q >>= 1
        c += 1
    flag = True
    for c in range(n):
        if p&1:
            for s in t:
                if s[c] == 0:
                    flag = False
        else:
            for s in t:
                if s[c] == 1:
                    flag = False
        p >>= 1
    if flag:
        ans = max(ans, l)

print(ans)

Solution (Python):
n = int(input())
a = []
x = []
y = []
for i in range(n):
    ai = int(input())
    a.append(ai)
    xi = []
    yi = []
    for j in range(ai):
        xij, yij = map(int, input().split(' '))
        xi.append(xij)
        yi.append(yij)
    x.append(xi)
    y.append(yi)
ans = 0
for case in range(2**n):
    truth_t = 0  
    truth = 0    
    for i in range(n):  
        if (case>>i)&1:  
            truth_t+=1
            proof=0
            for j in range(a[i]):
                if ((case>>(x[i][j]-1))&1)==y[i][j]:
                    proof+=1
            if proof==a[i]:
                truth += 1
    if truth==truth_t:
        if ans<truth:
            ans = truth
print(ans)

Solution (Python):
N = int(input())
ls1 = []
for i in range(N):
    A = int(input())
    ls2 = []
    for i in range(A):
        x, y = map(int,input().split())
        ls2.append([x,y])
    ls1.append(ls2)
ans = 0
f = True
for i in range(2**N):
    for j in range(N):
        if (i>>j&1):
            f = True
            for k in ls1[j]:
                if (i >>(k[0] - 1) &1) == (k[1]&1):
                    continue
                else:
                    f = False
                    break
            if f == False:
                break
    if f:
        ans = max(ans,bin(i).count('1'))    
print(ans)

Solution (Python):
N = int(input())
ll = [] 
for i in range(N):
    l = [None]*N
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        l[x-1] = y
    ll.append(l)

ans = 0
for i in range(1, 2**N): 
    b = 1
    hon = [0]*N 
    for j in range(N):
        if i>>j&1:
            hon[j] = 1
    
    for k in range(N): 
        if hon[k]==1: 
            for h in range(len(ll[k])): 
                if ll[k][h]==None:
                    continue
                if hon[h]!=ll[k][h]:
                    b = 0
                
   
    if b:
        p = hon.count(1)
        ans = max(p, ans)
print(ans)

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

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

ans = 0
for state in range(1<<n):
    tmp = 0
    hh = []
    for mask in range(n):
        if (1<<mask)&state:
            hh.append(mask)
    flag = True
    for h in hh:
        for x,y in s[h]:
            if y == 1:
                if x not in hh:
                    flag = False
                    break
            else:
                if x in hh:
                    flag = False
                    break
        tmp += 1
    if flag:        
        ans = max(tmp, ans)
    
print(ans)

Solution (Python):
N = int(input())
A = []
XY = []
for i in range(N):
    a = int(input())
    A.append(a)
    xy = [list(map(int,input().split())) for j in range(a)]
    XY.append(xy)
ans = 0
for i in range(2**N):
    b = [i>>j&1 for j in range(N)]
    f = 0
    for j in range(N):
        if b[j] == 1:
            for k in range(A[j]):
                x = XY[j][k][0] -1
                y = XY[j][k][1]
                if b[x] != y:
                    f = 1
                    break
        if f:
            break
    else:
        ans = max(ans,b.count(1))
print(ans)

Solution (Python):
N = int(input())
A = []
XY = []
for i in range(N):
    a = int(input())
    A.append(a)
    xy = [list(map(int,input().split())) for j in range(a)]
    XY.append(xy)
ans = 0
for i in range(2**N):
    b = [i>>j&1 for j in range(N)]
    f = 0
    for j in range(N):
        if b[j] == 1:
            for k in range(A[j]):
                x = XY[j][k][0] -1
                y = XY[j][k][1]
                if b[x] != y:
                    f = 1
                    break
        if f:
            break
    else:
        ans = max(ans,b.count(1))
print(ans)

Solution (Python):
import sys



def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    testimonies = []
    for _ in range(n):
        a = input_int()
        testimony = []
        for _ in range(a):
            x, y = input_int_list()
            testimony.append([x, y])
        testimonies.append(testimony)
    
    ans = 0
    for i in range(2**n):
        sample = [None] * n
        for j in range(n):
            if i >> j & 1:
                sample[j] = 1
            else:
                sample[j] = 0
        sample = [None] + sample  
        
        is_possible = True
        for idx, testimony in enumerate(testimonies):
            if sample[idx + 1] == 1:
                for x, y in testimony:
                    if sample[x] == y:
                        continue
                    else:
                        is_possible = False
        
        if is_possible:
            ans = max(ans, sum(sample[1:]))
    print(ans)

    return


if __name__ == "__main__":
    main()

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

statements = []

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

    statements.append(astates)

cnt = 0
for i in range(2**n):
    state = format(i, "0"+str(n)+"b")

    pos = True
    for j in range(n):
        if state[j] == "1":
            for x, y in statements[j]:
                if not (state[x-1] == str(y)):
                    pos = False
                    break

        if not pos:
            break

    if pos:
        cnt = max(cnt, state.count("1"))

print(cnt)

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

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

ans = 0

for bit in range(2**n):
    
    for s in comment:
        if (bit>>s[0])&1 == 1:
            if (bit>>s[1])&1 != s[2]:
                break
    else:
        tmp = str(bin(bit)).count("1")
        ans=max(ans,tmp)
print(ans)

Solution (Python):

import sys
from itertools import chain
from itertools import product


def check(N, ptn, m_assert):
    for i in range(N):
        if ptn[i] == 1:
            for j in range(i + 1, N):
                if ptn[j] == 1:
                    if m_assert[i][j] == 0:
                        return False
                    if m_assert[j][i] == 0:
                        return False
                else:
                    if m_assert[i][j] == 1:
                        return False
        else:
            for j in range(i + 1, N):
                if ptn[j] == 1:
                    if m_assert[j][i] == 1:
                        return False
    return True


def solve(N, m_assert):
    ans = 0
    for ptn in product([1, 0], repeat=N):
        if check(N, ptn, m_assert):
            ans = max(sum(ptn), ans)
    return ans


def main():
    N = int(input())
    m_assert = [[-1] * N for _ in range(N)]
    for n in range(N):
        A = int(input())
        for a in range(A):
            x, y = map(int, input().split())
            m_assert[n][x - 1] = y
    answer = solve(N, m_assert)
    print(answer)


if __name__ == "__main__":
    main()

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

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

ans = 0

for bit in range(2**n):
    
    for s in syougen:
        if (bit>>s[0])&1 == 1:
            if (bit>>s[1])&1 != s[2]:
                break
    else:
        thisans = str(bin(bit)).count("1")
        ans=max(ans,thisans)
        
print(ans)

Solution (Python):
n = int(input())
L = []
ans = 0

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

for i in range(1<<n):
    flg = True
    for j, x, y in L:
        if i>>j & 1 and i>>x & 1 != y:
            flg = False
            break
    if flg:
        ans = max(ans, sum(i>>j & 1 for j in range(n)))

print(ans)

Solution (Python):
N = int(input())
testimo_ls = [ [] for i in range(N) ]
rst = 0
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split(' '))
        testimo_ls[i].append([x - 1, y])
for i in range(1 << N):
    honest_ls = []
    for j in range(N):
        if i >> j & 1:
            honest_ls.append(j)
    is_ok_cnt = 0
    is_ok = True
    for s in honest_ls:
        for t in testimo_ls[s]:
            if t[1] == 0 and t[0] in honest_ls:
                is_ok = False
                break
            if t[1] == 1 and t[0] not in honest_ls:
                is_ok = False
                break
    if is_ok:
        rst = max(rst, len(honest_ls))
print(rst)

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

hatsugen = [[] for _ in range(N)]

A = -1
while True:
  try:
  	s = input()
  except EOFError:
    break  
  a = tuple(map(int,s.rstrip().split()))
  
  if len(a) == 1:
    A += 1
  else:
    hatsugen[A].append(a)


ans = 0
for i in range(2**N):
  
  bit = i
  flag = [0]*N
  idx = 0
  while bit:
    if (bit&1):
      flag[idx] = 1
    bit >>= 1
    idx+=1
  
  flag2=0
  
  for i in range(N):
    if flag[i]:
      hatsu = hatsugen[i]
    else:
      continue
    for word in hatsu:
      
      if flag[word[0]-1] != word[1]:
        flag2 = 1
        
        break
    if flag2:
      break
  if flag2==0:
    ans = max(ans, sum(flag))

print(ans)