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):
N = int(input())
A = []
L = []
for i in range(N):
  a = int(input())
  A.append(a)
  tmp = []
  for i in range(a):
    tmp.append(list(map(int, input().split())))
  L.append(tmp)

ans = 0
for i in range(1, 2**N):
  tmp = [-1] * N
  flag = True
  d = []
  for j in range(N):
    if (i>>j) & 1:
      if tmp[j] == 0:
        flag = False
        break
      tmp[j] = 1
      l = L[j]
      for k in range(len(L[j])):
        p, t = l[k][0], l[k][1]
        if tmp[p-1] < 0:
          tmp[p-1] = t
        elif tmp[p-1] != t:
          flag = False
          break
      if flag == False:
        break
    else:
      d.append(j)
  for m in range(len(d)):
    n = d[m]
    if tmp[n] == 1:
      flag = False
      break
  if flag:
    ans = max(ans, tmp.count(1))
print(ans)

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    
    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

N = int(input())

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

ans = 0
for i in range(0,2**N):
    flag = 1
    for j in range(N):
        if ((i >> j) & 1):
            for xx in x[j]:
                if xx[1] == 1:
                    if not ((i >> xx[0]) & 1):
                        flag = 0
                        break
                else:
                    if ((i >> xx[0]) & 1):
                        flag = 0
                        break

        if flag == 0:
            break

    if flag == 0:
        continue
    else:
        ans = max(ans, popcount(i))

print(ans)

Solution (Python):
def main():
    N = int(input())
    A_lst = [0] * N
    xy_lst = [[]] * N
    ans = 0

    for i in range(N):  
        A = int(input())
        A_lst[i] = A
        xy_lst[i] = [[]] * A

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

    for i in range(2 ** N):  
        honest_unkind = [0] * N
        flag = True

        for j in range(N):  
            if (i >> j) & 1 == 1:
                honest_unkind[j] = 1  

        for j in range(N):  
            if flag == False:
                break

            for k in range(A_lst[j]):  
                if honest_unkind[j] == 1:  
                    if xy_lst[j][k][1] == 0 and honest_unkind[xy_lst[j][k][0] - 1] == 1:
                        flag = False  
                        break
                    if xy_lst[j][k][1] == 1 and honest_unkind[xy_lst[j][k][0] - 1] == 0:
                        flag = False
                        break
                
                
                
                
                
                
                

        if flag == True:  
            cnt = sum(honest_unkind)
            if cnt > ans:
                ans = cnt

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
ev=[]
for i in range(n):
    a=int(input())
    ev.append([list(map(int,input().split())) for _ in range(a)])
ans=0
for i in range(2**n):
    bit=(bin(i)[2:].zfill(n))
    flag=1
    for j in range(n):
        if bit[j]=="0":
            continue
        for e in ev[j]:
            if int(bit[e[0]-1])!=e[1]:
                flag=0
    if flag:
        ans=max(ans,bit.count("1"))
print(ans)

Solution (Python):
def popcount(x):
    x = (x & 0x5555555555555555) + (x >> 1  & 0x5555555555555555)
    x = (x & 0x3333333333333333) + (x >> 2  & 0x3333333333333333)
    x = (x & 0x0f0f0f0f0f0f0f0f) + (x >> 4  & 0x0f0f0f0f0f0f0f0f)
    x = (x & 0x00ff00ff00ff00ff) + (x >> 8  & 0x00ff00ff00ff00ff)
    x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff)
    x = (x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff)
    return x
n = int(input())

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

ans = 0
for bits in range(1, 1<<n):
    possible = True
    for i in range(n):
        if not bits >> i & 1:
            continue
        for x, y in testimonies[i]:
            if bits >> x & 1 != y: 
                possible = False
                break
        if not possible:
            break
    if possible:
        ans = max(ans, popcount(bits))
print(ans)

Solution (Python):
import sys;      from decimal import Decimal
import math;     from itertools import combinations, product
import bisect;   from collections import Counter, deque, defaultdict


MOD = 10 ** 6 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

def Main():
    n = read_int()
    testimony = [[] for _ in range(n)]
    ans = 0

    for i in range(n):
        for _ in range(read_int()):
            x, y = read_ints()
            testimony[i].append((x-1, y))
    
    for bit in range(1 << n):
        flag = True
        for i in range(n):
            if (bit >> i) & 1:
                for x, y in testimony[i]:
                    if (bit >> x) & 1 != y:
                        flag = False
                        break
                else:
                    continue
                break
        
        if flag:
            ans = max(ans, bin(bit).count('1'))
    
    print(ans)


if __name__ ==  '__main__':
    Main()

Solution (Python):
n = int(input())
A = []
X = []

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


ans = 0

for i in range(2**n):
    flg = True
    honest = [0]*n
    count = 0
    for j in range(n):
        if ((i >> j) & 1):
            honest[j] = 1
    
    for k in range(n):
        for l in range(0,len(X[k]),2):
            
            if honest[X[k][l]-1] != X[k][l+1] and honest[k] == 1:
                
                flg = False

    if flg:
        count = sum(honest)
        
        ans = max(ans, count)



print(ans)

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

ans = 0
for i in range(2 ** N):
    for (j,x,y) in A:
        if i & 1 << j:
            if y == 1:
                if not i & (1 << x):
                    break
            else:
                if i & (1 << x):
                    break
    else:
        ans = max(ans, sum([1 for x in bin(i) if x == '1']))
print(ans)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ans = 0
info = [[] for _ in range(n)]
for i in range(n):
    a = I()
    for _ in range(a):
        x, y = LI()
        info[i].append((x-1, y))

for i in range(1, 1 << n):
    ret = 0
    for j in range(n):
        if i >> j & 1:
            ret += 1
            for x, y in info[j]:
                if y == 0 and i >> x & 1:
                    break
                elif y == 1 and not i >> x & 1: 
                    break
            else:
                continue
            break
    else:
        ans = max(ans, ret)
print(ans)

Solution (Python):
N = int(input())
L = []
for _ in range(N):
  L.append([list(map(int, input().split())) for _ in range(int(input()))])
for ls in L:
  for l in ls:
    l[0] -= 1
M = 0
for i in range(1<<N):
  A, Normal = [], True
  for j in range(N):
    if (i>>j)&1:
      A.append(j)
  for a in A:
    for l in L[a]:
      if l[0] in A and l[1]==0:
        Normal = False
      if l[1]==1 and l[0] not in A:
        Normal = False
  if Normal:
    M = max(M, len(A))
print(M)

Solution (Python):
N=int(input())
D=[{} for _ in range(N+1)]

for i in range(1,N+1):
    A=int(input())
    for k in range(A):
        p,x=map(int,input().split())
        D[i][p]=x

Max=0
for x in range(2**N):
    y=x

    B=["*"]*(N+1)
    for i in range(N):
        B[i+1]=y%2
        y>>=1

    Flag=True
    for i in range(1,N+1):
        if B[i]==1:
            for k in D[i]:
                Flag&=(B[k]==D[i][k])

    if Flag:
        Max=max(Max,B.count(1))

print(Max)

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

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

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

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

Solution (Python):
N = int(input())
d = {}
for i in range(N):
    d[i] = {}

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


max_i = 0
for i in range(2 ** N):
    tmp = [-1 for i in range(N)]
    counter = 0
    flag = 0
    for j in range(N):
        if ((i >> j) & 1):
            counter += 1
            tmp[j] = 1
        else:
            tmp[j] = 0
    for j in range(N):
        if ((i >> j) & 1):
            for key in d[j].keys():
                if tmp[key] != d[j][key]:
                    flag = 1

        if flag == 1:
            break
    if flag == 0 and max_i < counter:
        max_i = counter
print(max_i)

Solution (Python):
N = int(input())
 
testimony = [[] for _ in range(N)]
 
for i in range(N):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        testimony[i].append([person-1, state])
        
honest = 0
for i in range(2**N):
    flag = 0
    for j in range(N):
        if (i>>j)&1 == 1: 
            for x,y in testimony[j]:
                if (i>>x)&1 != y: 
                    flag = 1
                    break
    if flag == 0:  
        honest = max(honest, bin(i)[2:].count('1'))  
print(honest)

Solution (Python):
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
N = int(input())
 
testimony = [[] for _ in range(N)]
 
for i in range(N):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        testimony[i].append([person-1, state])
        
honest = 0
for i in range(1, 2**N):
    flag = 0
    for j in range(N):
        if (i>>j)&1 == 1: 
            for x,y in testimony[j]:
                if (i>>x)&1 != y: 
                    flag = 1
                    break
    if flag == 0:  
        honest = max(honest, bin(i)[2:].count('1'))  
print(honest)

Solution (Python):
import numpy as np
import itertools

N = int(input())
info = []
for i in range(N):
    A = int(input())
    for _ in range(A):
        x,y = map(int,input().split())
        info.append((i,x-1,y))
        
A = np.array(list(itertools.product([0,1],repeat=N)),np.bool)
for i,x,y in info:
    bl = (~A[:,i]) | (A[:,x] == bool(y))
    A = A[bl]
 
answer = A.sum(axis = 1).max()
print(answer)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def count(zerone):
    one = 0
    cnt = 0
    for i in range(N):
        flag = True
        if zerone[i] == 1:
            one += 1
            for j in range(len(A[i])):
                if A[i][j][1] != zerone[A[i][j][0]-1]:
                    flag = False
                    break
        if flag:
            cnt += 1
    if cnt == N:
        return one
    else:
        return 0


def dfs(bits):
    if len(bits) == N:
        return count(bits)
    res = 0
    for i in range(2):
        bits.append(i)
        res = max(res, dfs(bits))
        bits.pop()
    return res


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

ans = dfs([])
print(ans)

Solution (Python):
N = int(input())
XYList = []
for i in range(N):
    A = int(input())
    XY = []
    for j in range(A):
        XY.append(list(map(int, input().split())))
    XYList.append(XY)
maxSum = 0
for i in range(2**N):
    sum = 0
    for j in range(N):
        if i >> j & 1:
            honest = True
            for XY in XYList[j]:
                if ((i >> (XY[0]-1)) & 1) != XY[1]:
                    honest = False
                    break
            if honest:
                sum += 1
            else:
                sum = 0
                break
    if maxSum < sum:
        maxSum = sum
print(maxSum)

Solution (Python):

import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()

    statements = []
    for _ in range(N):
        a = II()
        statement = []
        for _ in range(a):
            hatugen = LI()
            statement.append(hatugen)
        statements.append(statement)

    ans = 0
    for i in range(2**N):
        flag = True
        i_str = format(i, f"0{N}b")
        for n in range(N):
            if i_str[n] == '0':
                continue

            for statement in statements[n]:
                target = statement[0]
                seisitu = statement[1]

                if i_str[target - 1] != str(seisitu):
                    flag = False

        if flag:
            tmp = 0
            for n in range(N):
                tmp += int(i_str[n])

            ans = max(ans, tmp)

    print(ans)


main()

Solution (Python):
n = int(input())
ls = [0]*n
param_list = [0]*2**n
for i in range(2**n):
    l = [False]*n
    for id_r, row in enumerate(ls):
        if i & (2 ** id_r) >0:
            l[id_r] = True
    param_list[i] = l 


for i in range(n):
    A = int(input())
    for k in range(A):
        a,b = map(int, input().split())
        b = (1==b)
        new_param =[]
        for d in param_list:
            if d[i]:
                if d[a-1] == b:
                    new_param.append(d)
                    pass
                else:
                    
                    pass
            else:
                new_param.append(d)
                
                    
                    
                
                    
                    
                    
            
        param_list = new_param
        
            
ans = 0    
for d in param_list:
    ans = max(ans, d.count(True))
print(ans)

Solution (Python):
from itertools import product

N = int(input())
A = [None] * N
lst = [[] for _ in range(N)]
for i in range(N):
    A[i] = int(input())
    lst[i] = [list(map(int, input().split())) for _ in range(A[i])]

bit_lst = list(product(range(2), repeat=N)) 

ans = 0
for bit in bit_lst:
    f = True 
    for a in range(N):
        
        if f:
            for b in range(A[a]):
                
                if bit[a] == 1:
                    
                    if lst[a][b][1] != bit[lst[a][b][0]-1]:
                        
                        f = False
                        break
                else:
                    
                    break
    if f:
        ans = max(ans, sum(bit))
print(ans)

Solution (Python):
def main():
    N = int(input())
    comment = []

    for i in range(1, N + 1):
        A = int(input())
        for j in range(1, A + 1):
            c = [i]
            c.extend(list(map(int, input().split())))
            comment.append(c)

    ans = 0
    for i in range(1, 2**N):
        flg = True
        for h, t, c in comment:
            
            if i & (1 << h - 1):
                
                if ((i >> t - 1) & 0b1) ^ c:
                    flg = False
                    break
        
        if flg:
            tmp = 0
            for j in range(N):
                if i & (1 << j):
                    tmp += 1
            
            ans = max(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()

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

statements=[]
honests=[0]
for i in range(N):
  statement=[]
  A=int(input())
  for j in range(A):
    x,y=map(int,input().split(' '))
    statement.append([x-1,y]) 
  statements.append(statement)


ans=0

for honest in range(1<<N):
  flag=True
  for j in range(N):
    statement=statements[j]
    for x,y in statement:
      if (honest&(1<<j))>>j ==1:
        flag*=((honest&(1<<x))>>x ==y)


    
  if flag==True:
    honests.append(honest)

n_honests=[]
for honest in honests:
  n_honest=0
  for i in range(N):
    n_honest+=(honest&(1<<i))>>i
  n_honests.append(n_honest)

print(max(n_honests))

Solution (Python):
n = int(input())
ls = [[] for _ in range(n)]
di = []
for p in range(n):
    a = int(input())
    ls[p] = [list(map(int,input().split())) for _ in range(a)]
for i in range(2**n):
    new = []
    for j in range(n):
        if (i>>j)&1:
            new.append(j)
    di.append(new)
flag = True
mx = 0
for l in di:
    flag = True
    for k in l:
        for s in ls[k]:
            a,b = s[0],s[1]
            if ((a-1 not in l)and (b == 1)) or ((a-1 in l) and (b == 0)):
                flag = False
                break
        if flag == False:
            break
    if flag == True:
        if len(l) > mx:
            mx = len(l)     
print(mx)

Solution (Python):
n = int(input())
all = 1<<n
statement = []
for i in range(n):
    A = int(input())
    statement.append([])
    for j in range(A):
        x, y = map(int, input().split())
        statement[i].append([x-1, y])
ans = 0
for i in range(all):
    ok = True
    num = 0
    for j in range(n):
        if i & 1<<j:
            num += 1
            for s in statement[j]:
                if (i & 1<<s[0]) != (s[1]<<s[0]):
                    ok = False
    if ok:
        ans = max(ans, num)
print(ans)

Solution (Python):
import sys
N = int(input())
P = [[] for _ in range(N)]
for i in range(N):
    a = int(input())
    for _ in range(a):
        x, y = map(int, sys.stdin.readline().split())
        P[i].append((x - 1, y))

ans = 0
for pattern in range(1 << N):
    ok = True
    count = 0
    for i in range(N):
        if pattern & (1 << i):
            count += 1
            for x, y in P[i]:
                if y == 1:
                    if not pattern & (1 << x):
                        ok = False
                        break
                else:
                    if pattern & (1 << x):
                        ok = False
                        break
        if not ok:
            break
    if ok:
        ans = max(ans, count)
print(ans)

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

a_list = []
person_list = []
syogen_list = []
ans = 0

for i in range(0, n):
    w = []
    v = []
    a = int(input())
    for j in range(0, a):
        x,y = map(int,input().split())
        w.append(x)
        v.append(y)
    person_list.append(w)
    syogen_list.append(v)



for bit in range(1 << n):
    break_flag = 0
    bit_1_cnt = 0
    for i in range(n):
        if break_flag:
            break
        if (bit >> i) & 1: 
            for j in range(len(syogen_list[i])):
                if syogen_list[i][j] != ((bit>>(person_list[i][j]-1))&1): 
                    break_flag = 1
                    break
            bit_1_cnt += 1
        if break_flag==0 and i==n-1:
            ans = max(ans, bit_1_cnt)
print(ans)

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

a_list = []
person_list = []
syogen_list = []
ans = 0

for i in range(0, n):
    w = []
    v = []
    a = int(input())
    for j in range(0, a):
        x,y = map(int,input().split())
        w.append(x)
        v.append(y)
    person_list.append(w)
    syogen_list.append(v)



for bit in range(1 << n):
    break_flag = 0
    bit_1_cnt = 0
    for i in range(n):
        if break_flag:
            break
        if (bit >> i) & 1: 
            for j in range(len(syogen_list[i])):
                if syogen_list[i][j] != ((bit>>(person_list[i][j]-1))&1): 
                    break_flag = 1
                    break
            bit_1_cnt += 1


        if break_flag==0 and i==n-1:
            ans = max(ans, bit_1_cnt)
            
print(ans)

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

a_list = []
person_list = []
syogen_list = []
ans = 0

for i in range(0, n):
    w = []
    v = []
    a = int(input())
    for j in range(0, a):
        x,y = map(int,input().split())
        w.append(x)
        v.append(y)
    person_list.append(w)
    syogen_list.append(v)



for bit in range(1 << n):
    break_flag = 0
    bit_1_cnt = 0
    for i in range(n):
        
        if break_flag:
            break
        if (bit >> i) & 1: 
            for j in range(len(syogen_list[i])):
                if syogen_list[i][j] != ((bit>>(person_list[i][j]-1))&1): 
                    break_flag = 1
                    
                    break


        if break_flag==0 and i==n-1:
            
            ans = max(ans, bin(bit).count("1"))
print(ans)

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

a_list = []
person_list = []
syogen_list = []
ans = 0

for i in range(0, n):
    w = []
    v = []
    a = int(input())
    for j in range(0, a):
        x,y = map(int,input().split())
        w.append(x)
        v.append(y)
    person_list.append(w)
    syogen_list.append(v)



for bit in range(1 << n):
    break_flag = 0
    bit_1_cnt = 0
    for i in range(n):
        
        if break_flag:
            break
        if (bit >> i) & 1: 
            for j in range(len(syogen_list[i])):
                if syogen_list[i][j] != ((bit>>(person_list[i][j]-1))&1): 
                    break_flag = 1
                    
                    break








        if break_flag==0 and i==n-1:
            
            ans = max(ans, bin(bit).count("1"))
            
            
print(ans)

Solution (Python):
N = int(input())
XY = []
for _ in range(N):
    A = int(input())
    xy = []
    for _ in range(A):
        x, y = map(int, input().split())
        x -= 1
        xy.append((x, y))
    XY.append(xy)
ans = 0
for s in range(1<<N):
    for i in range(N):
        if s>>i&1:
            for x, y in XY[i]:
                if s>>x&1 != y:
                    break
            else:
                continue
            break
    else:
        ans = max(ans, bin(s).count("1"))
print(ans)

Solution (Python):
import itertools



N = int(input())
AAA = [[] for i in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        AAA[i].append([int(k) for k in input().split()])


for ifkind in itertools.product([1,0],repeat=N):
    consistent = True
    for i,A in enumerate(AAA):
        if ifkind[i]==1:
            for x,y in A:
                x=x-1
                if ifkind[x]!=y:
                    consistent = False
    if consistent==True:
        print(sum(ifkind))
        break

Solution (Python):
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter



input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  
    fac = [0] * SIZE  
    finv = [0] * SIZE  
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    
    
    
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    
    return X.flatten().tolist()[0]

class TwoDimGrid:
    
    def __init__(self, h, w, wall="
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        
        
        
        
        

def judge(id, sho, n):
    hito = [0]
    for i in range(n):
        if id % 2 == 1:
            hito.append(1)
        else:
            hito.append(0)
        id //= 2

    for i, h in enumerate(hito):
        if i == 0:
            continue
        if h == 1:
            for x, y in sho[i-1]:
                if hito[x] != y:
                    return -1

    return sum(hito)


def solve():
    n = getN()

    sho = []
    for i in range(n):
        a = getN()
        tmp = []
        for j in range(a):
            tmp.append(getList())
        sho.append(tmp)

    ans = -1
    for i in range(1<<n):
        ans = max(ans, judge(i, sho, n))

    print(ans)


def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    
    solve()

Solution (Python):
N=int(input())
ans=0
speech_l=[[] for _ in range(N)]
for i in range(N):
    tmp=int(input())
    for j in range(tmp):
        speech_l[i].append(list(map(int,input().split())))
for i in range(2**N):
    sw=0
    l=[1]*N
    tmp=N
    for j in range(N):
        if ((i >> j)&1):
            tmp-=1
            l[j]=0
    for j in range(N):
        if l[j] == 1:
            for k in speech_l[j]:
                if l[k[0]-1] != k[1]:
                    sw=1
    if sw==0:
        ans=max(ans,tmp)
print(ans)

Solution (Python):
def solve():
    
    N = int(input())  
    A = []
    x = []
    y = []
    i = 0
    for i in range(N):
        A.append(int(input()))
        x.append([])
        y.append([])
        for j in range(A[i]):
            x_temp, y_temp = list(map(int, input().split()))
            x[i].append(x_temp)
            y[i].append(y_temp)
    
    
    honest_num = 0
    honest_num_new = 0
    for b in range(2**N):
        consistent = True
        case = format(b, '0'+str(N)+'b')
        
        i = 0
        for i in range(N): 
            for z in zip(x[i], y[i]): 
                if case[i] == "1":
                    if case[z[0]-1] != str(z[1]):
                        consistent = False
        if consistent:
            
            honest_num_new = case.count("1")
        
        honest_num = max(honest_num, honest_num_new)
    print(honest_num)



if __name__ == "__main__":
    solve()

Solution (Python):
n=int(input())
sy=[[-1]*n for _ in range(n)]
ans=[0]
for j in range(n):
  for i in range(int(input())):
    x,y=map(int,input().split())
    sy[j][x-1]=y
for i in range(2**n):
  c=[]
  for j in range(n):
    c.append((i>>j)&1)  
  d=0  
  for i in range(n):
    if c[i]==1:
      for j in range(n):
        if sy[i][j]==-1:
          continue
        elif sy[i][j]==c[j]:
          continue
        else:
          d+=1
          break
    else:
      continue
  if d==0:
    ans.append(sum(c))
print(max(ans))

Solution (Python):
import numpy as np

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

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

for i in range(2**N):

    
    tf=[0]*N
    for j in range(N):
        if (i>>j)&1:
            tf[j]=1

    
    marubatu = 1
    for j in range(N):
        
        if tf[j]==0:
            continue

        
        for k in range(len(xy[j])):
            if tf[xy[j][k][0]-1]!=xy[j][k][1]:
                marubatu = 0
                break

    if marubatu == 1:
        ans=max(ans,sum(tf))

print(ans)