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):
from sys import stdin

N = int(stdin.readline().rstrip())
wit = [[] for _ in range(N)]
A = []

for i in range(N):
    A = int(stdin.readline().rstrip())
    for n in range(A):
        wit[i].append([int(x) for x in stdin.readline().rstrip().split()])

ans = 0

for i in range(2 ** N):
    s = bin(i)[2:].zfill(N)
    one_cnt = 0
    tmp = 0
    for j in range(N):
        if s[j] == '1':
            one_cnt += 1
            cnt = 0
            for k in wit[j]:
                if k[1] == 1:
                    if s[k[0] - 1] == '1':
                        cnt += 1
                elif k[1] == 0:
                    if s[k[0] - 1] == '0':
                        cnt += 1
            if cnt == len(wit[j]):
                tmp += 1
    if tmp == one_cnt:
        ans = max(ans, one_cnt)

print(ans)

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


for i in range(2**n-1, -1, -1):
  
  num = format(i, '0%db' % n)
  
  flag = False
  for j in range(n):
    
    if int(num[j]) == 1:
      for k in range(a[j]):
        
        if int(num[xy[j][k][0]-1]) != xy[j][k][1]:
          flag = True
          break
      if flag:
        break
  if not flag:
    cnt = 0
    for l in range(n):
      if int(num[l]):
        cnt += 1
    break
print(cnt)

Solution (Python):
from itertools import product
def trueCheck(i,x):
    for j in range(1,N+1):
        if B[i][j]==1:
            if x[j-1]==0:
                return 1
        elif B[i][j]==0:
            if x[j-1]==1:
                return 1
    return 0
N = int(input())
A = [0]
B = {i:[-1 for _ in range(N+1)] for i in range(1,N+1)}
for i in range(1,N+1):
    A.append(int(input()))
    for _ in range(A[-1]):
        x,y = map(int,input().split())
        B[i][x] = y
cmax = 0
for z in product([0,1],repeat=N):
    flag = 0
    for i in range(1,N+1):
        if z[i-1]==1:
            flag = trueCheck(i,z)            
        if flag==1:break
    if flag==0:
        cmax = max(cmax,sum(z))
print(cmax)

Solution (Python):

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


def dfs(i,honest):
    if i==N:
        
        for h in honest:
            for j in range(a[h-1]):
                
                if s[h-1][j][1] == 1:
                    if s[h-1][j][0] not in honest:
                        return 0
                else:
                    if s[h-1][j][0] in honest:
                        return 0
        return len(honest)
    return max([dfs(i+1, honest+[i+1]),dfs(i+1, honest)])

print(dfs(0,[]))

Solution (Python):
def read():
    N = int(input().strip())
    A = []
    X = []
    Y = []
    for i in range(N):
        
        a = int(input().strip())
        A.append(a)
        x = [-1 for i in range(a)]
        y = [-1 for i in range(a)]
        for i in range(a):
            x[i], y[i] = list(map(int, input().strip().split()))
            x[i] -= 1
        X.append(x)
        Y.append(y)
    return N, A, X, Y

def is_honest(ptn, x):
    return (ptn >> x) & 1

def count_honest(ptn, N):
    count = 0
    for i in range(N):
        if is_honest(ptn, i):
            count += 1
    return count

def check_ptn(ptn, N, A, X, Y):
    count = 0
    for i in range(N):
        if is_honest(ptn, i) == 1:
            for x, y in zip(X[i], Y[i]):
                if is_honest(ptn, x) != y:
                    return False
    return True


def solve(N, A, X, Y):
    ptns = 1 << N
    max_honest = 0
    for ptn in range(ptns):
        if check_ptn(ptn, N, A, X, Y):
            n_honest = count_honest(ptn, N)
            if n_honest > max_honest:
                max_honest = n_honest
    return max_honest

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

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

L=[]
for i in range(N):
    L.append([2]*N)

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

max=0

for i in range(2**N):
    b=list(map(int,list(bin(i))[2:]))
    b=[0]*(N-len(b))+b
    s=0

    for j in range(N):
        for k in range(N):
            if b[j]==1 and b[k]==1:
                if L[j][k]==0 or L[k][j]==0:
                    s=1
            if b[j]==1 and b[k]==0:
                if L[j][k]==1:
                    s=1

    if s==0:
        max=sum(b)

print(max)

Solution (Python):

n = int(input())

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

result = 0
for i in range(2**n):
    katei = []
    is_out = 0
    ninzu = 0
    for j in range(n):
        if int(i / (2**(j))) % 2:
            katei.append(1)
            ninzu += 1
        else:
            katei.append(0)
    if ninzu <= result:
        continue
    for j in range(n):
        if katei[j] == 1:
            for gen in syogen[j]:
                if katei[gen[0]-1] != gen[1]:
                    is_out = 1
    if is_out == 0:
        result = ninzu

print(result)

Solution (Python):
n = int(input())
hf = [[None] for i in range(n)]

for i in range(n):
    tmp = []
    for j in range(int(input())):
        tmp.append(list(map(int, input().split())))
    hf[i] = tmp
ans = 0
for i in range(2 ** n):
    f = 0
    b = bin(i)[2:].zfill(n)
    for j in range(n):
        if b[j] == "0":
            continue
        else:
            for x, y in hf[j]:
                if b[x - 1] != str(y):
                    f = 1
    if f == 0:
        ans = max(ans, b.count("1"))
print(ans)

Solution (Python):
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista

def wszystkie_mozliwosci(N):
    if N==0:
        return [[]]
    poprzedni = wszystkie_mozliwosci(N-1)
    wynik = []
    for przyp in poprzedni:
        wynik.append(przyp + [False])
        wynik.append(przyp + [True])
    return wynik

def C():
    N = wczytaj_liste()[0]
    zeznania = []
    odp = 0
    for i in range(N):
        A = wczytaj_liste()[0]
        zeznania.append([])
        for j in range(A):
            x, y = wczytaj_liste()
            zeznania[-1].append((x-1,y))
    
    for czy_szczery in wszystkie_mozliwosci(N):
        dasie = True
        for i in range(N):
            if czy_szczery[i]:
                for x,y in zeznania[i]: 
                    if y == 1 and not czy_szczery[x]:
                        dasie = False
                    if y == 0 and czy_szczery[x]:
                        dasie = False
        if dasie:
            ile_szczerych = sum(czy_szczery)
            if ile_szczerych > odp:
                odp = ile_szczerych

    print(odp)
C()

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

import collections
i2unkinds = collections.defaultdict(set)
i2honest = collections.defaultdict(set)
for i in range(N):
  A = int(input())
  for _ in range(A):
    x, y = map(int, input().split())
    if (y == 0):
      i2unkinds[i].add(x - 1)
    else:
      i2honest[i].add(x - 1)



ans = 0
def recursive(i, says, honest, unkinds):
  if i == N:
    if not (honest & unkinds) and not (honest ^ says) and says:
      global ans
      ans = max(ans, len(honest))
  else:
    recursive(i + 1, says | {i}, honest | {i} | i2honest[i], unkinds | i2unkinds[i])
    recursive(i + 1, says, honest, unkinds)

recursive(0, set(), set(), set())
print(ans)

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

def check(bit,P):
  con = False
  T = [-1]*N
  for i in range(N):
    if bit[i] == '1':
      for j in range(N):
        if P[i][j] == 1:
          if bit[j] == '0':
            return True        
        elif P[i][j] == 0:
          if bit[j] == '1':
            return True
  return False
          

cnt = 0
for i in range(2**N):
  bit = bin(i)[2:].zfill(N)
  if not check(bit,P):
    cnt = max(cnt,bit.count('1'))
    

    
print(cnt)

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())
    x -= 1
    xy[i] += [[x, y]]
result = 0
for i in range(2**n):
  dic = {i:-1 for i in range(n)}
  flag = True 
  ans = 0
  for j in range(n):
    if (i>>j)&1:
      if dic[j] != -1 and dic[j] != 1:
        flag = False
        break
      dic[j] = 1
      for x, y in xy[j]:
        if dic[x] == -1:
          dic[x] = y 
        elif dic[x] != -1 and dic[x] != y:
          flag = False
          break
      if flag:
        ans += 1
    else:
      if dic[j] != -1 and dic[j] == 1:
        flag = False
        break
      dic[j] = 0
      """
      for x, y in xy[j]:
        if dic[x] == -1:
          dic[x] = 1-y 
        elif dic[x] != -1 and dic[x] == y:
          flag = False
          break
      """

  if flag:
    result = max(result, ans)

print(result)

Solution (Python):
import itertools


def bit(n, m):
    bit_list = list(itertools.product([i for i in range(m)], repeat=n))
    return bit_list

N = int(input())

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

bits = bit(N, 2)
res = 0
for ptr in bits:
    flag = True
    result = [0 for _ in range(N)]

    for i in range(N):
        if ptr[i] == 1:
            result[i] = 1 
        else:
            result[i] = -1 

    for i in range(N):
        if ptr[i] == 1:
            for j in range(len(A[i])):
                if A[i][j][1] == 0:
                    if result[A[i][j][0] - 1] == 1:
                        flag = False
                        break
                else:
                    if result[A[i][j][0] - 1] == -1:
                        flag = False
                        break
        else:
            if result[i] == 1:
                break
            result[i] = -1

        if flag == False:
            break

    if flag:
        tmp = 0
        for i in range(N):
            if result[i] == 1:
                tmp += 1

        res = max(res, tmp)

print(res)

Solution (Python):
n = int(input())
data = [[]for i in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        data[i].append(list(map(int, input().split())))
max_honest = 0
def bfs(honest):
    if len(honest) == n:
        global max_honest
        for i in range(len(data)):
            if honest[i] == 1:
                for j in data[i]:
                    target, istrue = j
                    if (honest[target-1] == 1 and istrue == 0) or (honest[target-1] == 0 and istrue == 1):
                        return
            else:
                continue
        max_honest = max(max_honest, honest.count(1))
    else:
        bfs(honest + [0])
        bfs(honest + [1])
bfs([])
print(max_honest)

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

t = []

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

ans = 0

for i in range(1 << N):
    ok = 1
    for j in range(N):
        if 1 << j & i:
            for a_t in t[j]:
                if 1 << (a_t[0]-1) & i:
                    if a_t[1] != 1:
                        ok = 0
                        break
                else:
                    if a_t[1] != 0:
                        ok = 0
                        break
        if ok == 0:
            break
    if ok:
        if ans < sum(list(map(int, list(bin(i)[2:])))):
            ans = sum(list(map(int, list(bin(i)[2:]))))

print(ans)

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

from itertools import product

ans = 0
for i in product((0,1),repeat=n):
    for j,k in enumerate(i):
        if k==0:
            continue
        else:
            if all(map(lambda x:i[x[0]-1]==x[1],lis[j])):
                continue
            else:
                break
    else:
        ans = max(ans,sum(i))
print(ans)

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

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

def possible(honest):
    
    for i in range(n):
        if honest[i] == '0':
            continue
        for j in range(len(stm[i])):
            
            
            if stm[i][j][1] == 1 and honest[stm[i][j][0]-1] == '0':
                return False
            elif stm[i][j][1] == 0 and honest[stm[i][j][0]-1] == '1':
                return False
    return True

            

for i in range(n):
    a = int(input())
    for _ in range(a):
        x,y = map(int, input().split())
        stm[i].append([x,y])
   
count = 0
for k in range(2**n):
    hon = list(bin(k)[2:])
    hon = ['0']*(n-len(hon)) + hon
    if possible(hon):
        count = max(count, sum([int(x) for x in hon]))
print(count)

Solution (Python):
from itertools import product
n = int(input())
xys = []
for _ in range(n):
    a = int(input())
    tmp = []
    for _ in range(a):
        x, y = map(int, input().split())
        tmp.append((x-1, y))
    xys.append(tmp)

ans = 0
for people in product(range(2), repeat=n):
    isOK = True

    for i in range(n):
        if not people[i]:
            continue
        for x, y in xys[i]:
            if people[x] != y:
                isOK = False
                break

        if not isOK:
            break

    if isOK:
        ans = max(ans, sum(people))

print(ans)

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

ans = 0
for i in range(2**N):
    temp_ans = 0
    network = [0] * N
    for j in range(N):
        if (i >> j) & 1:
            temp_ans += 1
            network[j] = 1
    for hito in range(N):
        flg = False
        if network[hito] == 1:
            for x, y in xys[hito]:
                if network[x - 1] != y:
                    flg = True
                    break
            if flg:
                break
    else:
        
        ans = max(ans, temp_ans)
print(ans)

Solution (Python):
N = int(input())
info = [[] for _ in range(N)]
people = [-1] * N
for i in range(N):
    A = int(input())
    if A == 0:
        info[i].append([0])
    for j in range(A):
        x , y = map(int,input().split())
        info[i].append([A , x - 1 , y])

ans = 0

for i in range(2 ** N):
    cnt = 0
    Flag = True
    
    for j in range(N):
        if i >> j & 1:
            cnt += 1
            people[j] = 1
        else:
            people[j] = 0
    for j in range(N):
        
        if i >> j & 1:
            info_num = info[j][0][0]
            for k in range(info_num):
                judge = info[j][k][2]
                origin = people[info[j][k][1]]
                if judge != origin:
                    Flag = False
                    break
        if not Flag:
            break
    if Flag:
        if ans < cnt:
            ans = cnt
print(ans)

Solution (Python):
N=int(input())
s=[[-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())
        s[i][x-1]=y
from itertools import product
r=0
for t in product((0,1),repeat=N):
    f=1
    for i in range(N):
        for j in range(N):
            if not ((t[i]==1 and s[i][j] in (t[j],-1)) or t[i]==0):
                f=0
    if f==1:
        r=max(r,sum(t))
print(r)

Solution (Python):
N = int(input())
T = [[] for k in range(N)]
for p in range(N):
    A = int(input())
    for k in range(A):
        x, y = map(int,input().split())
        T[p].append([x-1,y])

ans = 0
for k in range(2**N):
    t = []
    f = []
    for d in range(N):
        if (k>>d)&1 == 1:
            t.append(d)
        else:
            f.append(d)
    flag = 1
    for p in range(N):
        if p in t:
            for e in T[p]:
                if e[1] == 1 and e[0] in f:
                    flag = 0
                    break
                elif e[1] == 0 and e[0] in t:
                    flag = 0
                    break
    if flag == 1:
        ans = max(ans,len(t))
print(ans)

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

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


for i in reversed(range(2**n)):
    bi = format(i, 'b').zfill(n)
    flag = True
    for j, data in enumerate(lst):
        if bi[j] == '0':
            continue
        for x, y in data:
            if int(bi[x - 1]) != y:
                flag = False
                break
        
        if not flag:
            break

    if flag:
        break

if flag:
    print(bi.count('1'))
else:
    print(0)

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

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

ans = 0
l = []
for i in range(2**N):
  l.append([(i >> j) & 1 for j in range(N)])
  
for a in l:
  for i in range(N):
    if a[i] == 0:
      continue
    
    for b in v[i]:
      if a[b[0]-1] != b[1]:
        break
    else:
      continue
    break
  else:
    ans = max(ans, sum(a))
      
print(ans)

Solution (Python):
from itertools import combinations

N = int(input())
xyss = [[tuple(map(int, input().split())) for _ in range(int(input()))] for _ in range(N)]

def check(mask):
    m = [None] * N
    for i, xys in enumerate(xyss):
        if i in mask:
            continue
        for x, y in xys:
            x -= 1
            if m[x] != None and m[x] != y:
                
                return False
            elif  y == 1 and x in mask or y == 0 and x not in mask:
                
                return False
            else:
                m[x] = y
    return True

for i in range(N + 1):
    for k in combinations(range(N), i):
        mask = set(k)
        if check(mask):
            print(N - i)
            break
    else:
        continue
    break

Solution (Python):
N = int(input())
dic = []
ls = [[] for i in range(N)]
for i in range(N):
  a = int(input())
  dic += [a]
  for j in range(a):
    x, y = map(int, input().split())
    ls[i] += [(x-1,y)]
ans = 0
for i in range(2**N):
  inf = []
  m = 0
  for j in range(N):
    if i%2==0:
      inf += [1]
      m += 1
    else:
      inf += [0]
    i >>= 1
  flag = False
  for j in range(N):
    if inf[j]==0:
      continue
    for h in range(dic[j]):
      x, y = ls[j][h]
      if inf[x]!=y:
        flag = True
        break
    if flag:
      break
  else:
    if ans<m:
      ans = m
print(ans)

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

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

count = 0
for i in range(2 ** N):
    YorN = [0] * N
    for j in range(N):
        if ((i >> j) & 1):
            YorN[N - 1 - j] = 1
        True_people = []
    for j in range(N):
        if YorN[j] == 1:
            True_people.append(answer[j])
    flag = True
    for ans in True_people:
        for k in ans:
            if YorN[k[0]-1] != k[1]:
                flag = False
    if flag == True:
        if count <= sum(YorN):
            count = sum(YorN)

print(count)

Solution (Python):
import sys
from collections import deque
readline = sys.stdin.readline


N = int(readline())
A = []
X, Y = [], []
for i in range(N):
    a = int(readline())
    A.append(a)
    x, y = [], []
    for j in range(a):
        _x, _y = map(int, readline().split())
        x.append(_x - 1), y.append(_y)
    X.append(x)
    Y.append(y)

M = 2 ** N
count = 0
for code in range(M - 1, -1, -1):
    contra = False
    for i in range(N):
        if ((code >> i) & 1) == 1:
            x, y = X[i], Y[i]
            for j in range(len(x)):
                if y[j] != ((code >> x[j]) & 1):
                    contra = True
                    break
            if contra:
                break
    if not contra:
        _count = 0
        for i in range(N):
            _count += ((code >> i) & 1)
        count = max(count, _count)

print(count)

Solution (Python):
LOCAL = True   and False


def dprint(*args):
  if LOCAL:
    print(*args)


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


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

anses = []

for x in range(2 ** n):
  flag = True
  cnt = 0
  dprint('x', x)
  for i in range(n):
    if x & (1 << i) != 0:
      dprint('i', i)
      cnt += 1
      for j in range(a[i]):
        dprint(int(x & (1 << (xy[i][j][0] - 1)) != 0) != xy[i][j][1])
        if int(x & (1 << (xy[i][j][0] - 1)) != 0) != xy[i][j][1]:
          flag = False
  if flag:
    anses.append(cnt)

dprint(anses)
print(max(anses))

Solution (Python):
N = int(input())
l = [[] for i in range(N)]
for i in range(N):
    A = int(input())
    l[i] = [0 for j in range(A)]
    for j in range(A):
        x, y = map(int, input().split())
        l[i][j] = [x, y]
ans = 0
for i in range(2**N):
    cnt = 0
    flag = True
    for j in range(N):
        if (i >> j) & 1:
            cnt += 1
            for k in range(len(l[j])):
                if (i >> (l[j][k][0] - 1)) & 1 == l[j][k][1]:
                    pass
                else:
                    flag = False
                    break
    if flag:
        ans = max(ans, cnt)
    cnt = 0
print(ans)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()


on = []

Ma = 0

for i in range(n):
    kkk = []
    p = onem()
    for j in range(p):
        kkk.append(l())
    on.append(kkk)
for i in range(2**n):
    ppp = '{:015b}'.format(i)
    ppp = list(ppp[15-n:])
    ppp.reverse()
    su = 0
    for r in range(n):
        if ppp[r] == "1":
            su += 1
    f = False
    for j in range(n):
        if ppp[j] == "1":
            for k in range(len(on[j])):
                a,b = on[j][k]
                a -= 1
                if b ^ int(ppp[a]):
                    f = True
                    break
    if not f:
        Ma = max(Ma,su)
print(Ma)

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

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

ans = 0

for i in range(2**N):
	c = Base_10_to_n(i,2).rjust(N,"0")
	c = list(map(int, c))
	cnt = [-1] * N
	cond = True
	for j in range(N):
		if c[j] == 1:
			for kind in t[j][1]:
				if cnt[kind-1] == 0:
					cond = False
				cnt[kind-1] = 1
			for unk in t[j][0]:
				if cnt[unk-1] == 1:
					cond = False
				cnt[unk-1] = 0
	if cond:
		for k in range(N):
			if cnt[k] != -1:
				cond = (cnt[k] == c[k])
				if cond == False:
					break
	if cond:
		ans = sum(c)

print(ans)

Solution (Python):

def main():
    n = int(input())
    bs = []
    xyss = []
    ans = 0
    for _ in range(n):
        bs.append(int(input()))
        xys = [[int(i) for i in input().split()] for __ in range(bs[-1])]
        xs = set(x-1 for x, y in xys if y == 1)
        ys = set(x-1 for x, y in xys if y == 0)
        
        xyss.append((xs, ys))
    
    for i in range(2**n):
        
        f = True
        for j in range(n):
            if i & (1 << j) > 0:
                xs, ys = xyss[j]
                for x in xs:
                    if (~i) & (1<<x) > 0:
                        f = False
                        
                        
                for y in ys:
                    if i & (1<<y) > 0:
                        f = False
                        
                        
            
            
        
        if f:
            ans = max(ans, sum(1 for c in "{0:b}".format(i) if c == '1'))
    print(ans)

main()

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


ans =0
for i in range(2**n):
    flag = True
    for j in range(n):
        if (1<<j) & i:
            for k in ls[j]:
                if bool(((1<<(k[0]-1)) & i)) != bool(k[1]):
                    flag = False

    if flag:
        count = 0
        for j in range(n):
            if (1<<j) & i:
                count += 1
        ans = max(ans, count)

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10000000)

from bisect import *
from collections import *
from heapq import *
import functools
import itertools
import math
INF = float('inf')
MOD = 10**9+7

N = int(input())
As = [None] * N
ts = [[] for i in range(N)]
for i in range(N):
    As[i] = int(input())
    for j in range(As[i]):
        x, y = map(int, input().split())
        ts[i].append((x-1, y))
ans = 0
for ps in itertools.product([0, 1], repeat = N):
    
    qs = [None] * N
    flg = 1
    for i in range(N):
        if qs[i] != None and qs[i] != ps[i]:
            flg = 0
            break
        qs[i] = ps[i]
        if ps[i]:
            for j in range(As[i]):
                x, y = ts[i][j]
                if qs[x] == None:
                    qs[x] = y
                elif qs[x] != y:
                    flg = 0
                    break
        if flg == 0:
            break
    if flg:
        ans = max(ans, sum(ps))
print(ans)

Solution (Python):
n = int(input())
xys = []
for i in range(n):
    a = int(input())
    xys.append([list(map(int, input().split())) for _ in range(a)])
ret = 0
for b in range(1 << n):
    ok = True
    c = 0
    for i in range(n):
        if (b >> i) & 1 != 0:
            c += 1
            for x, y in xys[i]:
                if y != (b >> (x - 1)) & 1:
                    ok = False
    if ok:
        ret = max(ret, c)
print(ret)

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines





def main():
	n=int(input())
	
	li=[[] for i in range(n)]
	for i in range(n):
		a=int(input())
		for j in range(a):
			x,y=map(int,input().split())
			li[i].append((x-1,y))
	
	ans=0
	
	for i in reversed(range(1<<n)):
		aa=[0]*n
		f=1
		for j in range(n):
			if (i>>j)&1==1:
				aa[j]=1
				
		for k in range(n):
			if aa[k]==1:
				for x,y in li[k]:
					if aa[x]!=y:
						f=0
		if f==1:
			ans=max(ans,str(bin(i)).count("1"))
	
	print(ans)
	
	
	
	
	
	
if __name__ == "__main__":
	main()

Solution (Python):
import sys
import math
from itertools import permutations
from itertools import combinations


sys.setrecursionlimit(10**7)
N = int(input())
xys = []
for _ in range(N):
    A = int(input())
    xy = [list(map(int, input().split())) for _ in range(A)]
    xys.append(xy)


ok = [0] * N
maxv = 0
for i in range(2**N):
    flg = 1
    chk = [i>>n & 1 for n in range(N)]
    for ii, xy in enumerate(xys):
        if chk[ii] == 0:
            continue
        for xyi in xy:
            x = xyi[0]
            y = xyi[1]

            if chk[x-1] != y:
                flg = 0
                break
        if flg == 0:
            break
    if flg == 1:
        sumchk = sum(chk)
        if maxv < sumchk:
            maxv = sumchk

print(maxv)

Solution (Python):
import copy
shogen = {}
N = int(input())
for i in range(N):
    Ax = int(input())
    current_shogen = {}
    for j in range(Ax):
        x, y = list(map(int, input().split()))
        current_shogen[x-1] = y
    shogen[i] = current_shogen

def return_total(index, is_liar, hito_list):
    if not is_liar:
        if hito_list[index] is not None and hito_list[index] != 1:
            return 0
        hito_list[index] = 1
        current_shogen = shogen[index]
        for x,y in current_shogen.items():
            if hito_list[x] is not None:
                if hito_list[x] != y:
                    """mujun"""
                    return 0
            else:
                hito_list[x] = y
    else:
        if hito_list[index] is not None and hito_list[index] != 0:
            return 0
        hito_list[index] = 0
    if index == N-1:
        
        return sum(hito_list)
    else:
        return max(return_total(index+1, False, copy.deepcopy(hito_list)), return_total(index+1, True, copy.deepcopy(hito_list)))

print(max(return_total(0, False, [None for i in range(N)]), return_total(0, True, [None for i in range(N)])))

Solution (Python):
n = int(input())
test_list = [[[int(i) for i in input().split()] for j in range(int(input()))] for k in range(n)]

man_list = [[int(j) for j in bin(i)[2:].zfill(n)] for i in range(2**n)]

ans = 0
bad = 0

for man in man_list:
  for j in range(n):
    if man[j] == 1:
      for k in test_list[j]:
        x = k[0] - 1
        y = k[1]
        if man[x] != y:
          bad = 1
          break
    if bad == 1:
      bad = 0
      break
  else:
    ans = max(ans, sum(man))

print(ans)