Problem:
 Score : 300 points    Problem Statement There are N people numbered 1 to N . Each of them is either an honest person whose testimonies are always correct or an unkind person whose testimonies may be correct or not.  Person i gives A_i testimonies. The j -th testimony by Person i is represented by two integers x_{ij} and y_{ij} . If y_{ij} = 1 , the testimony says Person x_{ij} is honest; if y_{ij} = 0 , it says Person x_{ij} is unkind.  How many honest persons can be among those N people at most?      Constraints  All values in input are integers.  1 \leq N \leq 15  0 \leq A_i \leq N - 1  1 \leq x_{ij} \leq N  x_{ij} \neq i  x_{ij_1} \neq x_{ij_2} (j_1 \neq j_2)  y_{ij} = 0, 1         Input Input is given from Standard Input in the following format:  N  A_1  x_{11}  y_{11}  x_{12}  y_{12}  :  x_{1A_1}  y_{1A_1}  A_2  x_{21}  y_{21}  x_{22}  y_{22}  :  x_{2A_2}  y_{2A_2}  :  A_N  x_{N1}  y_{N1}  x_{N2}  y_{N2}  :  x_{NA_N}  y_{NA_N}       Output Print the maximum possible number of honest persons among the N people.        Sample Input 1 3
1
2 1
1
1 1
1
2 0      Sample Output 1 2  If Person 1 and Person 2 are honest and Person 3 is unkind, we have two honest persons without inconsistencies, which is the maximum possible number of honest persons.       Sample Input 2 3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0      Sample Output 2 0  Assuming that one or more of them are honest immediately leads to a contradiction.       Sample Input 3 2
1
2 0
1
1 0      Sample Output 3 1

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = []
for i in range(N):
	tmp = []
	n = INT()
	shougen = []
	for j in range(n):
		shougen = MAP()
		tmp.append(shougen)
	A.append(tmp)

cand = []
for i in range(2**N):
	shojiki = [0]*N
	for j in range(N):
		if (i>>j & 1):
			shojiki[N-j-1]=1
	cand.append(shojiki)


ans = []
for c in cand:
	list = [-1]*(N+1)
	success = True
	ones = [a for idx,a in enumerate(A) if c[idx]==1]
	for idx,a in enumerate(ones):
		for aa in a:
			if list[aa[0]] == -1:
				list[aa[0]] = aa[1]
			else:
				if list[aa[0]]!=aa[1]:
					success=False
	for k in range(len(c)):
		if c[k]==1 and list[k+1]==0:
			success = False
		if c[k]==0 and list[k+1]==1:
			success = False
	if success:
		
		ans.append(sum(c))
	

if ans:
	print(max(ans))
else:
	print(0)

Solution (Python):
import itertools
N = int(input())
A = [[] for i in range(N)]

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

for i in range(N):
    B = itertools.combinations(range(N), i)
    for b in B:
        state = [1] * N
        for bb in b:
            state[bb] = 0
        flag = True
        for j in range(N):
            if j in b:
                continue
            for (x, y) in A[j]:
                if state[x] != y:
                    flag = False
        if flag:
            print(N - i)
            exit()
print(0)

Solution (Python):
import sys
from itertools import combinations
input = sys.stdin.readline
N = int(input())
A = [i for i in range(N)]
XY = [[] for n in range(N)]

for n in range(N):
    A[n] = int(input().strip())
    for a in range(A[n]):
        x, y = [int(x) for x in input().strip().split()]
        XY[n].append((x, y))

ans = 0
def check(honests, A, XY, N):
    
    honest = [0] * N
    for h in honests:
        honest[h] = 1
    f = True
    for nn in range(N):
        if nn not in honests:
            continue
        
        xy = XY[nn][:]
        
        for x, y in xy:
            if x-1 in honests and y == 0:
                
                f = False
                break
            elif honest[x-1] != y:
                
                f = False
                break
        
        if not f:
            break
    else:
        return True
    return False

for n in range(N, 0, -1):
    for honests in combinations(range(N), n):
        if check(honests, A[:], XY[:], N):
            print(n)
            exit()
else:
    print(0)

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


res = 0
for i in range(1,2 ** N):
  i_bin = bin(i)[2:]
  i_bin = i_bin.zfill(N)
  p = [0] * N
  for j in range(N):
    p[j] = int(i_bin[j])
  isPossible = True
  for j in range(N):
    x = i_bin[j]
    if x == '1':
      for k, v in A[j].items():
        if p[k] != v:
          isPossible = False
          break
  if isPossible:
    res = max(res, sum(p))

print(res)

Solution (Python):
def sol():
    n=int(input())
    w=[[] for i in range(n)]
    for i in range(n):
        a=int(input())
        for j in range(a):
            x,y=map(int,input().split())
            w[i].append((x,y))
    
    ans=0
    for i in range(1<<n):
        x="0"*15+bin(i)[2:]
        x=x[-n:]
        f=1
        z=list(x)
        f=1
        for p,q in enumerate(w):
            
            
            if z[p]=='1':
                for r in q:
                    if (x[r[0]-1]=='1' and r[1]==1) or (x[r[0]-1]=='0' and r[1]==0):
                        pass
                    else:
                        f=0
        if f:
            ans=max(ans,z.count('1'))
    print(ans)

if __name__=="__main__":
    sol()

Solution (Python):
N = int(input())
lst = []
for i in range(N):
    a = int(input())
    xy = [[int(x) for x in input().split()] for _ in range(a)]
    lst.append(xy)
ans = 0
for i in range(1, 2**N):
    f = 1
    tmp = [i >> j & 1 for j in range(N)]
    cnt = sum(tmp)
    for i, yi in enumerate(tmp):
        if (yi == 0): continue
        if any([tmp[x-1] != y for x, y in lst[i]]):
            f = 0
            break
    if (f): ans = max(cnt, ans)
print(ans)

Solution (Python):
import itertools
import numpy as np
N = int(input())
sug=[]

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

  
bi = [1,0]
x = itertools.product(bi,repeat=N)
max_honest=0
for i in x:
  
  flag=True
  for idx in range(N):
    if i[idx]==1:
      for candidate in sug[idx]:
        if i[candidate[0]-1] != candidate[1]:
          flag=False
          break
      if not flag:
        continue
  if not flag:
    continue
  if max_honest<sum(i):
    max_honest=sum(i)
print(max_honest)

Solution (Python):
n=int(input())
a=[]
xy=[[] for i in range(n)]
ans=0 

for i in range(n):
    aa=int(input())
    a.append(aa)
    for j in range(aa):
        xx,yy=map(int,input().split())
        xy[i].append([xx-1,yy])


for i in range(pow(2,n)): 
    who=[0]*n 
    count=0
    syoujiki=0
    for j in range(n-1,-1,-1): 
        if (i>>j)&1:
            who[count]=1
            syoujiki+=1
        count+=1
    
    
    check=0
    for j in range(n):
        if who[j]==0: 
            continue
        num=a[j]
        for k in range(num):
            if who[xy[j][k][0]]!=xy[j][k][1]:
                check=1
                break
        if check==1:
            break
    if check==0 and syoujiki>ans:
        ans=syoujiki
print(ans)

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

xy_list=[]
a_list=[]
for i in range(n):
    a=int(input())
    a_list.append(a)
    xy=[]
    for j in range(a):
        xy.append(input().split(" "))

    xy_list.append(xy)

maxn=0
b=[0]*n
for i in range(2**n):
    b=str(format(i,'b').zfill(n))
    out=0
    for j in range(n):
        if b[j]=="0":continue
        for k in range(a_list[j]):
            x=int(xy_list[j][k][0])
            y=str(xy_list[j][k][1])

            if b[x-1]!=y:
                out=1
                break
        
        if out==1:
            break
    
    if out == 0:
        maxn=max(maxn,b.count("1"))

print(maxn)

Solution (Python):
n=int(input())
a_list_sum = []
for i in range(n):
    a_tmp=int(input())
    a_list_tmp=[list(map(int,input().split())) for _ in range(a_tmp)]
    a_list_sum_tmp=[]
    a_list_sum_tmp.append(a_tmp)
    a_list_sum_tmp.append(a_list_tmp)
    a_list_sum.append(a_list_sum_tmp)
    
import itertools
L = [0, 1] 
bit_list = list(itertools.product([0, 1], repeat=n))

for i in range(len(bit_list)):
    count = 0
    for j in range(len(a_list_sum)):
        if bit_list[i][j] == 1:

            for k in range(len(a_list_sum[j][1])):
                person_id = a_list_sum[j][1][k][0] - 1
                is_honest = a_list_sum[j][1][k][1]
                if bit_list[i][person_id] != is_honest:
                    count += 1
    if count == 0:
        ans = sum(bit_list[i])
print(ans)

Solution (Python):
N = int(input())
data = [0 for i in range(N+1)]
A = [[[int(j) for j in input().split()] for i in range(int(input()))] for k in range(N)]

count = 0



while data[-1] != 1:
    g = 0
    
    for i,j in enumerate(data):
        
        if j == 1:
            for k in A[i]:
                if k[1] != data[k[0]-1]:
                    g = 1
                    
    if g == 0:
        count = max(sum(data),count)
    data[0]+=1
    for i,j in enumerate(data):
        if j == 2:
            data[i],data[i+1]=0,data[i+1]+1
            
print(count)

Solution (Python):
n=int(input())
shogen=[]
a=[]
max=0


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

for i in range(2**n):
	shojiki=[]
	for l in reversed(range(n)):
		shojiki.append(i//(2**l))
		i=i%(2**l)
	ninzu=0
	kekka=1
	
	for j in range(n):
		if shojiki[j]==1:
			ninzu+=1
			for k in range(a[j]):
				
					
				
					
				if shojiki[shogen[j][k][0]-1]!=shogen[j][k][1]:
					kekka=0
					break
			if kekka==0:
				break
	if kekka==0:
		ninzu=0
	if ninzu>max:
		max=ninzu

print(max)

Solution (Python):
N = int(input())
xy = []
for i in range(N):
    t = []
    A = int(input())
    for l in range(A):
        t.append(list(map(int,input().split())))
    xy.append(t)
ans = 0
for i in range(2**N):
    p = []
    for l in range(N):
        if ((i >> l) & 1) == 1:
            p.append(1)
        else:
            p.append(0)
    c = 0
    if sum(p) > ans:
        for l in range(N):
            if p[l] != 0:
                for j in xy[l]:
                    if p[j[0] - 1] != j[1]:
                        c = 1
        if c == 0 and p != [1,1,1]:
            ans = sum(p)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(100000)
N = int(input().strip())
shogen = [[-1 for _ in range(N)] for j in range(N)]
for i in range(N):
    size = int(input().strip())
    for j in range(size):
        k, tf = map(int, input().strip().split())
        k -= 1
        shogen[i][k] = tf

def dfs(bp, k):
    if k == N:
        
        for i in range(N):
            if not bp[i]:
                continue
            for j in range(N):
                if shogen[i][j] == 1 and not(bp[j]):
                    return 0
                if shogen[i][j] == 0 and bp[j]:
                    return 0
        cnt = 0
        for i in range(N):
            if bp[i]:
                cnt += 1
        return cnt
    """
    
    mujun = False
    for j in range(N):
        if j == k:
            for l in range(N):s
                if shogen[k][l] == 0
        else:
            if shogen[j][k] == 0:
                mujun = True
                break

    """
    bp[k] = True
    tmp1 = dfs(bp, k + 1)
    bp[k] = False
    tmp2 = dfs(bp, k + 1)

    return max(tmp1, tmp2)

tmp_bp = [False] * N
ans = dfs(tmp_bp, 0)
print(ans)

Solution (Python):




def check_honest(bits):
    honest = [-1 for _ in range(n)]
    for j in range(n):
        if bits[j] == "1":
            if honest[j] == 0:
                return False
            honest[j] = 1
            for ans in all[j]:
                if honest[ans[0] - 1] == -1:
                    honest[ans[0] - 1] = int(ans[1])
                elif honest[ans[0] - 1] != int(ans[1]):
                    return False
        else:
            if honest[j] == 1:
                return False
            honest[j] = 0
    else:
        return True
    
    
n = int(input())

all = []
for _ in range(n):
    total_ans = int(input())
    answers = []
    for _ in range(total_ans):
        answers.append(list(map(int, input().split(" "))))
    all.append(answers)


for i in reversed(range(2 ** n)):
    bits = str(bin(i))[2:].zfill(n)
    if check_honest(bits):
        print(bits.count("1"))
        break
else:
    print("0")

Solution (Python):
import copy

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



tr = [[]]
for i in range(N):
    tr[0].append(-1)

    
for i in range(len(xy)):
    for j in xy[i]:
        this_tr = []
        for k in tr:
            if j[1] == 1:
                if k[j[0]-1] != 0 and k[i] != 0:
                    
                    this_k = copy.deepcopy(k)
                    this_k[j[0]-1] = 1
                    this_k[i] = 1
                    this_tr.append(this_k)
            else:
                if k[j[0]-1] != 1 and k[i] != 0:
                    
                    this_k = copy.deepcopy(k)
                    this_k[j[0]-1] = 0
                    this_k[i] = 1
                    this_tr.append(this_k)
            if k[i] != 1:
                
                this_k = copy.deepcopy(k)
                this_k[i] = 0
                this_tr.append(this_k)
        tr = copy.deepcopy(this_tr)
        
            

max_c = 0
for i in tr:
    count = 0
    for j in i:
        if j == 1 or j == -1:
            count += 1
    max_c = max(max_c ,count)
print(max_c)

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


ans = 0

for i in range(2 ** N):
    singi = [-1] * (N + 1)
    bin_ = bin(i)[2:].zfill(N)
    flag = True
    for j in range(1, N + 1):
        sin = int(bin_[j - 1])
        person = j
        num = A[j-1]
        questions = XY[j - 1]

        if sin == 0:
            continue

        if singi[j] == -1:
            singi[j] = sin
        else:
            if singi[j] != sin:
                flag = False

        for k in range(num):
            hito, honto = questions[k]
            if singi[hito] == -1:
                singi[hito] = honto
            else:
                if singi[hito] != honto:
                    flag = False

    if flag is True:
        singi = singi[1:]
        for b, s in zip(list(bin_), list(singi)):
            b = int(b)
            s = int(s)
            if (b == 1 and s == 0) or (b == 0 and s==1):
                flag = False
        if flag is True:
            ans = max(ans, singi.count(1))
print(ans)

Solution (Python):
def check_valid(flag):
    for i, m in mentions.items():
        if not (flag & (1 << i)):
            continue
        for j, honest in m.items():
            if honest and flag & (1 << j):
                continue
            if not honest and not (flag & (1 << j)):
                continue
            return False
    return True


n = int(input())
mentions = {}
for i in range(1, n + 1):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        if i not in mentions:
            mentions[i] = {x: y}
        else:
            mentions[i][x] = y
res = 0
for i in range(1, 1 << n + 1):
    if check_valid(i):
        temp = 0
        for j in range(1, n + 1):
            if i & (1 << j):
                temp += 1
            res = max(res, temp)
print(res)

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

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


import itertools
all_man = []
for x in itertools.product([0, 1], repeat=N):
    all_man.append(x)
    
ans = []
for man in all_man:
    flag = False
    for i, man_i in enumerate(man):
        if man_i == 0:
            continue
        else:
            
            for say_i in say[i]:
                x, y = say_i
                if man[x-1] != y:
                    
                    flag = True
    if flag:
        continue
    else:
        ans.append(man)
tmp = []
for i in ans:
    tmp.append(sum(i))
print(max(tmp))

Solution (Python):
N = int(input())
testi = {}
for i in range(N):
    T = []
    for a in range(int(input())):
        T.append(list(map(int, input().split())))
    testi[i+1] = T

ans = 0
for i in range(2**N):
    hypo = list(bin(i)[2:].zfill(N))
    num = hypo.count("1")
    for j, h in enumerate(hypo):
        if h == "1":
            for t in testi[j+1]:
                if hypo[t[0]-1] != str(t[1]):
                    break
            else:
                continue
            break
    else:
        if num > ans:
            ans = num

print(ans)

Solution (Python):
N = int(input())
A = [None]*N
says = [None]*N

def be_honset(man, honests):
    for i in range(N):
        
        if i+1 in honests:
            for j in range(A[i]):
                if says[i][j][1] == 0 and says[i][j][0] in honests:
                    return False 
                if says[i][j][1] == 1 and says[i][j][0] not in honests:
                    return False
                
    return True

for i in range(N):
    A[i] = int(input())
    say = []
    for j in range(A[i]):
        say.append([int(i) for i in input().split()])
    says[i] = say
    
max_num = 0

for i in range(1 << N):
    honests = []
    exist = True
    for j in range(N):
        if ((i>>j) & 1) == 1:
            honests.append(j+1)
    
    
    for h in honests:
        if not be_honset(h, honests): 
            exist = False
            break
        
    if not exist: continue
    num = len(honests)
    if num > max_num: max_num = num
    
print(max_num)

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

def res(n):
    t = []
    for i in range(15):
        if n%2 != 0:
            t.append(i)
        n = n // 2
    return t

def judge(t):
    r = [-1] * N
    while(len(t) > 0):
        c = t.pop(0)
        if r[c] == -1:
            r[c] = 1
        elif r[c] == 0:
            return False
        for x, y in l[c]:
            if r[x] > -1 and r[x] != y:
                return False
            elif r[x] == -1:
                r[x] = y
                if y == 1 and (x not in t):
                    t.append(x)
    return True

count = 0;
for num in range(2**N):
    o = res(num)
    if judge(o[:]):
        count = max(count, len(o))

print(count)

Solution (Python):
def tobin(num, pos):
    try:
        return int(format(num, 'b')[-(pos)])
    except:
        return 0

N = int(input())
shogens = {}
for person in range(1, N+1):
    Ai = int(input())
    inlist = []
    for i in range(Ai):
        x, y = map(int, input().split())
        inlist.append((x,y))
    shogens[person] = inlist

truth = [0]

for num in range(2**N):
    katei = []
    for pos in range(1, N+1):
        katei.append(tobin(num, pos))
    tf = True
    
    for person in range(1, N+1):
        if tf == False:
            break
        shogen = shogens[person]
        for tpl in shogen:
            if katei[person-1] == 1:
                if tpl[1] != katei[tpl[0]-1]:
                    tf = False
                    break
    if tf:
        truth.append(katei.count(1))
print(max(truth))

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

maxi = 0
for m in range(2**n):
  num = 0
  flg = False
  for i in range(n):
    if ((m >> i) & 1):
      num += 1
      for x, y in con[i]:
        if (((m >> x) ^ y) & 1):
          flg = True
          break
      if flg:
        break
  if not flg:
    maxi = max(num, maxi)
print(maxi)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    v = [[] for i in range(n)]
    for i in range(n):
        a = I()
        for j in range(a):
            x,y = LI()
            x -= 1
            v[i].append((x,y))
    m = 1<<n
    ans = 0
    for b in range(m):
        f = [1 if b&(1<<i) else 0 for i in range(n)]
        for i in range(n):
            for x,y in v[i]:
                if f[i]:
                    if f[x] != y:
                        break
            else:
                continue
            break
        else:
            na = sum(f)
            if ans < na:
                ans = na
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
import itertools

N = int(input())

speak_list = [] 
for i in range(N):
  speak_list.append([-1]*(N))

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


ori = [0,1]
Comb = list(itertools.product(ori, repeat=N))
ans = 0

for i in range(len(Comb)):
 tmp = list(Comb[i]) 
 
 
 X = []
 for i in range(N):
  X.append([-1]*(N))
 
 for i in range(N):
  if(tmp[i] == 1): 
   for j in range(N): 
    X[i][j] = speak_list[i][j]
  
 judge = 0 
 for i in range(N):
  for j in range(N):
    if(X[i][j] != -1): 
      if((X[i][j] == 1)and(tmp[j] == 0)): 
        judge = 1 
        break  
      if((X[i][j] == 0)and(tmp[j] == 1)): 
        judge = 1 
        break  
  
 
 if(judge == 0):
   ans = max(ans,sum(tmp))
   
    
print(ans)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
l = [None]*N
for i in range(N):
    k = int(input())
    tmp = [None]*k
    for j in range(k):
        tmp[j] = list(map(int,input().split(' ')))
    l[i] = tmp

M = 0
A = [2]*N
n = 2**N
for i in range(2**N):
    bin_num = bin(i)
    bin_str = str(bin_num)
    bin_str = bin_str[2:].zfill(N)
    k = list(bin_str)
    flag = False
    for j in range(N):
        s = k[j]
        if s=='1':
            correct = l[j]
            for num,opinion in correct:
                if k[num-1]!=str(opinion):
                    flag = True
                    break
            if flag:
                break
    if not flag:
        M = max(M,sum(list(map(int, bin_str))))
print(M)

Solution (Python):
N = int(input())
xy = []
for i in range(N):
    A = int(input())
    xy.append([[int(i) for i in input().split()] for _ in range(A)])
ans = 0
for n in range(2**N):
    b = bin(n)[2:].zfill(N)
    s = 0
    for i, bi in enumerate(b):
        if bi == '0':
            continue
        for x, y in xy[i]:
            if b[x-1] == str(y):
                pass
            else:
                break
        else:
            s += 1
            continue
        break
    else:
        ans = max(ans, s)
print(ans)

Solution (Python):
n=int(input())
xy = []
check = 0
for i in range(n):
    a = int(input())
    if a ==0:
        check+=1
    for j in range(a):
        x,y=map(int,input().split())
        xy.append([i+1,x,y])
        
ans = 0
for i in range(2**n):
    temp=check
    se=set()
    for idx,x,y in xy:
        if i>>(idx-1) & 1:
            if i>>(x-1) & 1:
                if y==1 and idx not in se:
                    temp+=1
                    se.add(idx)
                elif y==0:
                    break
            else:
                if y==0 and idx not in se:
                    temp+=1
                    se.add(idx)
                elif y==1:
                    break
    else:
        ans=max(ans,temp)
print(ans)

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

talk = []
for i in range(N):
        talk_num = int(input())
        tmp_talk = [list(map(int, input().split())) for j in range(talk_num)]
        talk.append(tmp_talk) 


ans = 0
for i in range(2 ** N):
        tmp = []
        flag = False
        for j in range(N):
                if ((i >> j) & 1):
                        tmp.append(1)
                else:
                        tmp.append(0)
        for k in range(len(tmp)):
                if tmp[k] == 0:
                        continue
                else:
                        for x in talk[k]:
                                
                                if x[1] != tmp[x[0] - 1]:
                                        flag = True
                                        break
                if flag:
                        break
        if flag == False:
                ans = max(ans, sum(tmp))             

print(ans)

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

ans = 0
honest = [0]*n
for i in range(2**n): 
    for j in range(n):
        if((i>>j)&1):
            honest[j] = 1
        else:
            honest[j] = 0
            
        f = True
        for k in range(n):
            for l in range(a[k]):
                if(honest[k]==1 and y[k][l]!=honest[x[k][l]]):
                    f = False
                    break
        if f:
            ans = max(ans,honest.count(1))

print(ans)

Solution (Python):

n = int(input())
dic = {}
for i in range(n):
    a = int(input())
    dic[i+1] = [a]
    for j in range(a):
        dic[i+1].append([int(k) for k in input().split()])


ls = []







ret = 2 ** n - 1

for i in range(ret,-1,-1):
    ls.append(format(i, '0'+str(len(format(ret,'b')))+'b'))

ls_3 = []
ok = 1
ans = 0
for i in range(len(ls)):
    for j in range(len(format(ret,'b'))):
         if ls[i][j] == '1':
            ls_3.append(j+1)
    
    for j in ls_3:
        for k in range(1,dic[j][0]+1):
            if dic[j][k][1] == 1 and dic[j][k][0] not in ls_3:
                ok = 0
            if dic[j][k][1] == 0 and dic[j][k][0] in ls_3:
                ok = 0
    if ok == 1:
        ans = ls[i].count('1')
        break
    ls_3 = []
    ok = 1

print(ans)

Solution (Python):
import collections
def main():

    N = int(input())
    dh = collections.defaultdict(set)
    dl = collections.defaultdict(set)
    for i in range(1, N+1):
        A = int(input())
        for _ in range(A):
            x, y = map(int, input().split())
            if y == 1:
                dh[i].add(x)
            else:
                dl[i].add(x)

    case = [[0], [1]]
    for _ in range(N-1):
        temp = []
        for lv in case:
            temp.append(lv + [0])
            temp.append(lv + [1])
        case = temp

    ans = 0
    for lv in case:
        h = set()
        l = set()
        
        
        for i in range(len(lv)):
            if lv[i] == 1:
                h.add(i+1)
                h |= dh[i+1]
                l |= dl[i+1]

        prevh = len(h)
        prevl = len(l)
        while  True:
            addh = set()
            addl = set()
            for i in h:
                addh |= dh[i]
                addl |= dl[i]
            h |= addh
            l |= addl
            if prevh == len(h) and prevl == len(l):
                break
            prevh = len(h)
            prevl = len(l)

        
        if len(h.intersection(l)) == 0:
            ans = max(ans, len(h))
    return ans



if __name__ == '__main__':
    print(main())

Solution (Python):
import itertools


num_person = int(input())

testimony = []
for i in range(0, num_person):
    honest = set()
    dishonest = set()
    num_test = int(input())
    for _ in range(0, num_test):
        target, test = map(int, input().split())
        target -= 1
        if test:
            honest.add(target)
        else:
            dishonest.add(target)
    testimony.append((honest, dishonest))

ans = [0]
for t in itertools.product((1, 0), repeat=num_person):
    honest = {i for i in range(0, num_person) if t[i]}
    dishonest = {i for i in range(0, num_person) if not t[i]}
    for i in range(0, num_person):
        if t[i]:
            honest.add(i)
            honest = honest.union(testimony[i][0])
            dishonest = dishonest.union(testimony[i][1])
    if honest.intersection(dishonest):
        continue
    else:
        ans.append(sum(t))

print(max(ans))
exit(0)

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

def main():
    N = int(input())
    
    mS = [[] for _ in [0,]*(N+1)]
    for i in range(N):
        Ai = int(input())
        for j in range(Ai):
            x, y = map(int, input().split())
            mS[i+1].append((x,y))

    
    
    
    

    res = 0
    
    M = 1<<N
    for m in range(M):
        vS = []
        vH = [-1]*(N+1)
        cnt = 0
        d = 0
        while m:
            if m&1:
                vS.extend(mS[d+1])
                vH[d+1] = 1
                cnt += 1
            d += 1
            m >>= 1
        
        ok_in_xy = True
        while vS:
            x,y = vS.pop()
            if vH[x] == -1:
                vH[x] = y
                if y:
                    vS.extend(mS[x])
            elif vH[x] != y:
                ok_in_xy = False
                break

        if ok_in_xy:
            res = max(res, cnt)

    print(res)


main()

Solution (Python):

N = int(input())
enter = []
A = [0] * N
for a in range(N):
    ai = int(input())
    tmp_enter = [list(map(int, input().split())) for _ in range(ai)]
    A[a] = ai
    enter.append(tmp_enter)

ans_list = [0]
for i in range(2 ** N):
    
    honest = []
    unkind = []
    flag = True
    for j in range(N):
        if (i >> j) & 1:
            honest.append(j)
        else:
            unkind.append(j)
    
    for h in honest:
        for k in range(A[h]):
            if enter[h][k][1] == 1:
                if (enter[h][k][0]-1) in unkind:
                    flag = False
                    break
            if enter[h][k][1] == 0:
                if (enter[h][k][0]-1) in honest:
                    flag = False
                    break
    if flag:
        ans_list.append(len(honest))
print(max(ans_list))

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


ans = 0
for i in range(1<<N):
  B = [0 for _ in range(N)]
  for j in range(N):
    if (i>>j)&1 == 1:
      B[j] = 1
  
  flag = True
  for j in range(N):
    if B[j] == 1:
      for x,y in A[j]:
        if (y == 1 and B[x-1] == 0) or (y == 0 and B[x-1] == 1):
          flag = False
          break
    if not flag:
      break
  if flag:
    ans = max(sum(B),ans)
print(ans)