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-----
3
1
2 1
1
1 1
1
2 0

-----Sample Output-----
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.

Difficulty: EASY

Solutions:
from itertools import product
n = int(input())
li = list(product([1, 0], repeat=n))
A = [[]] * n
for i in range(n):
	a = int(input())
	A[i] = [list(map(int, input().split())) for _ in range(a)]
cnt = 0
for i in li:
	flg = False
	for (itr, val) in enumerate(i):
		if val == 1:
			if not all([i[x[0] - 1] == x[1] for x in A[itr]]):
				flg = True
				break
	if flg == False:
		cnt = max(cnt, sum(i))
print(cnt)


n = int(input())
g = [[-1 for j in range(n)] for i in range(n)]
for i in range(n):
	a = int(input())
	for _ in range(a):
		(x, y) = map(int, input().split())
		g[i][x - 1] = y
ans = 0
for s in range(2 ** n):
	ok = True
	for i in range(n):
		if s >> i & 1 == 1:
			for j in range(n):
				if g[i][j] == -1:
					continue
				if s >> j & 1 != g[i][j]:
					ok = False
	if ok:
		t = 0
		x = s
		while x > 0:
			t += x % 2
			x //= 2
		ans = max(ans, t)
print(ans)


n = int(input())
l = [[] for i in range(n)]
for i in range(n):
	a = int(input())
	for j in range(a):
		(x, y) = map(int, input().split())
		l[i].append([x - 1, y])
ans = 0
for i in range(2 ** n):
	z = str(format(i, '0' + str(n) + 'b'))
	f = 1
	for k in range(n):
		if f:
			if int(z[k]):
				for m in l[k]:
					if z[m[0]] != str(m[1]):
						f = 0
	if f:
		ans = max(ans, z.count('1'))
print(ans)


N = int(input())
A = [0] * N
x = [0] * N
y = [0] * N
tlist = [0] * N
honest = 0
for i in range(N):
	A[i] = int(input())
	x[i] = []
	y[i] = []
	for j in range(A[i]):
		(xt, yt) = list(map(int, input().split()))
		x[i].append(xt)
		y[i].append(yt)
for t in range(2 ** N):
	ns = '0' + str(N) + 'b'
	bi = format(t, ns)
	for i in range(N):
		tlist[i] = int(bi[-1 - i])
		tflag = True
	for i in range(N):
		for j in range(A[i]):
			if tlist[i] == 1:
				if tlist[x[i][j] - 1] != y[i][j]:
					tflag = False
					break
		if not tflag:
			break
	if tflag:
		honest = max(honest, sum(tlist))
print(honest)


from itertools import product
datas = []
num = 0
N = int(input())
for i in range(N):
	a = int(input())
	for j in range(a):
		(x, y) = map(int, input().split())
		datas.append((num, x - 1, y))
	num += 1
ans = 0
for i in product([0, 1], repeat=N):
	ok = True
	cnt = 0
	for j in datas:
		if i[j[0]] == 1 and i[j[1]] != j[-1]:
			ok = False
			break
	if ok:
		cnt = sum(i)
		ans = max(ans, cnt)
print(ans)


from itertools import product as pro
n = int(input())
a = []
xy = []
for i in range(n):
	a_i = int(input())
	a.append(a_i)
	xy.append([tuple(map(int, input().split())) for _ in range(a_i)])
ans = 0
for l in pro([0, 1], repeat=n):
	for (i, t) in enumerate(l):
		if t == 1:
			if not all((l[x - 1] == y for (x, y) in xy[i])):
				break
	else:
		ans = max(ans, sum(l))
print(ans)


n = int(input())
a = []
l = [0] * n
ans = 0
for i in range(n):
	a.append(int(input()))
	l[i] = [list(map(int, input().split())) for i in range(a[-1])]
for i in range(2 ** n):
	i = format(i, 'b').zfill(n)
	c = []
	for j in range(n):
		if i[j] == '1':
			c.append(j)
	for j in c:
		for k in l[j]:
			if k[1] == 1 and k[0] - 1 not in c:
				break
			elif k[1] == 0 and k[0] - 1 in c:
				break
		else:
			continue
		break
	else:
		ans = max(ans, len(c))
print(ans)


def main():
	import numpy as np
	N = int(input())
	testimony = np.zeros((N, N), dtype=np.int64)
	for i in range(N):
		A = int(input())
		INF = 10 ** 10
		for _ in range(A):
			(x, y) = list(map(int, input().split()))
			testimony[i, x - 1] += 1 if y else -INF
	ans = 0
	for bit in range(1 << N):
		honest = set()
		pick = np.zeros(N, dtype=np.int64)
		for i in range(N):
			if bit & 1 << i:
				honest.add(i)
				pick += testimony[i, :]
		flag = True
		for j in range(N):
			value = pick[j]
			if 0 or (j in honest and value < 0) or (j not in honest and value > 0) or (value < 0 and value % INF != 0):
				flag = False
				break
		if flag:
			ans = max(ans, len(honest))
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
List = [[] for _ in range(N)]
for i in range(N):
	A = int(input())
	List[i] = [list(map(int, input().split())) for _ in range(A)]
ans = 0
for j in range(2 ** N):
	x = 0
	for k in range(N):
		if j >> k & 1:
			for l in range(len(List[k])):
				if j >> List[k][l][0] - 1 & 1 != List[k][l][1]:
					break
			else:
				x += 1
				continue
			break
	else:
		if ans < x:
			ans = x
print(ans)


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

def F(i):
	cnt = 0
	B = [-1] * N
	r = 0
	for j in range(N):
		if i >> j & 1:
			r += 1
			if B[j] == 0:
				return 0
			B[j] = 1
			for (p, q) in A[j]:
				if q == 0:
					if B[p - 1] == 1:
						return 0
					B[p - 1] = 0
				else:
					if B[p - 1] == 0:
						return 0
					B[p - 1] = 1
			else:
				cnt += 1
		else:
			if B[j] == 1:
				return 0
			B[j] = 0
	if cnt == r:
		return cnt
ans = 0
for i in range(1 << N):
	ans = max(ans, F(i))
print(ans)


import itertools
n = int(input())
A = [[] for i in range(n)]
for i in range(n):
	r = int(input())
	for j in range(r):
		A[i].append(list(map(int, input().split())))
ans = 0
L = list(itertools.product([0, 1], repeat=n))
for i in L:
	T = []
	for (num, j) in enumerate(i):
		if j == 1:
			for k in A[num]:
				T.append(k)
	if all((i[j[0] - 1] == j[1] for j in T)):
		ans = max(ans, sum(i))
print(ans)


n = int(input())
L = []
ans = 0
for i in range(n):
	a = int(input())
	for j in range(a):
		(x, y) = list(map(int, input().split()))
		L.append((i, x - 1, y))
for i in range(1 << n):
	flg = True
	for (j, x, y) in L:
		if i >> j & 1 and i >> x & 1 != y:
			flg = False
			break
	if flg:
		ans = max(ans, sum((i >> j & 1 for j in range(n))))
print(ans)


import sys
import math
import itertools
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
input = sys.stdin.readline

def RD():
	return input().rstrip()

def F():
	return float(input().rstrip())

def I():
	return int(input().rstrip())

def MI():
	return map(int, input().split())

def MF():
	return map(float, input().split())

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

def TI():
	return tuple(map(int, input().split()))

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

def Init(H, W, num):
	return [[num for i in range(W)] for j in range(H)]

def main():
	N = I()
	D = [[[], []] for i in range(N)]
	for i in range(N):
		a = I()
		for j in range(a):
			(x, y) = MI()
			if y == 1:
				D[i][0].append(x - 1)
			else:
				D[i][1].append(x - 1)
	visit = [0] * N
	res = 0
	A = [0, 1]
	for i in itertools.product(A, repeat=N):
		ans = True
		for (index, j) in enumerate(i):
			if j == 0:
				continue
			else:
				for k in D[index][0]:
					if i[k] == 0:
						ans = False
						break
				for k in D[index][1]:
					if i[k] == 1:
						ans = False
						break
		if ans:
			res = max(res, sum(i))
	print(res)

def __starting_point():
	main()
__starting_point()


import itertools
n = int(input())
data = []
for x in range(n):
	for y in range(int(input())):
		(k, l) = map(int, input().split())
		data.append((x, k - 1, l))
ans = 0
for i in itertools.product([1, 0], repeat=n):
	s = True
	for g in data:
		if i[g[0]] == 1 and i[g[1]] != g[2]:
			s = False
			break
	if s:
		ans = max(ans, sum(i))
print(ans)


N = int(input())
xy = [[] for _ in range(N)]
for i in range(N):
	A = int(input())
	for _ in range(A):
		xy[i].append(list(map(int, input().split())))
lst = [[0 for j in range(N)] for k in range(2 ** N)]
for l in range(2 ** N):
	for m in range(N):
		if l >> m & 1:
			lst[l][m] = 1
ans = 0
for n in lst:
	flag = True
	for f in range(N):
		if n[f] == 1:
			for g in xy[f]:
				if n[g[0] - 1] != g[1]:
					flag = False
					break
		else:
			tmp = 0
			for g in xy[f]:
				if n[g[0] - 1] == g[1]:
					tmp += 1
			if tmp == len(n):
				flag = False
		if not flag:
			break
	if flag:
		ans = max(ans, n.count(1))
print(ans)


from itertools import product
N = int(input())
data = []
for i in range(N):
	for j in range(int(input())):
		(x, y) = map(int, input().split())
		data.append((i, x - 1, y))
ans = 0
for i in product([1, 0], repeat=N):
	s = True
	for k in data:
		if i[k[0]] == 1 and i[k[1]] != k[2]:
			s = False
			break
	if s:
		ans = max(ans, sum(i))
print(ans)


from itertools import product
n = int(input())
a = []
for _ in range(n):
	a_i = int(input())
	t = []
	for _ in range(a_i):
		t.append(tuple(map(int, input().split())))
	a.append(t)
ans = 0
for case in product(range(2), repeat=n):
	frag = False
	for i in range(n):
		if case[i] == 1:
			for (x, y) in a[i]:
				if case[x - 1] != y:
					frag = True
					break
		if frag:
			break
	if not frag:
		ans = max(ans, sum(case))
print(ans)


from itertools import product
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])])
ans = 0
for C in product([0, 1], repeat=N):
	if sum(C) <= ans:
		continue
	for (i, c) in enumerate(C):
		if c:
			for (x, y) in XY[i]:
				if C[x - 1] != y:
					break
			else:
				continue
			break
	else:
		ans = max(ans, sum(C))
print(ans)


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)


n = int(input())
L = []
for i in range(n):
	a = int(input())
	for j in range(a):
		(x, y) = map(int, input().split())
		L.append([i, x - 1, y])
ans = 0
import itertools
for i in itertools.product([1, 0], repeat=n):
	s = sum(list(i))
	for l in L:
		if i[l[0]] == 1 and i[l[1]] != l[2]:
			s = 0
			break
	ans = max(ans, s)
print(ans)


N = int(input())
T = [[] for _ in range(N)]
for i in range(N):
	n = int(input())
	for j in range(n):
		T[i].append(tuple(map(int, input().split())))
ans = 0
for i in range(2 ** N):
	(true, t, f) = (set(), set(), set())
	for j in range(N):
		if i >> j & 1:
			true.add(j + 1)
			for (a, b) in T[j]:
				if b:
					t.add(a)
				else:
					f.add(a)
	if t <= true and (not f & true):
		ans = max(ans, len(true))
print(ans)


N = int(input())
lst = [[] for i in range(N)]
for i in range(N):
	for j in range(int(input())):
		lst[i].append(list(map(int, input().split())))
ans = 0
for i in range(2 ** N):
	flag = True
	bin_lst = list(bin(i)[2:].zfill(N))
	for (idx, j) in enumerate(bin_lst):
		if j == '1':
			for (v, w) in lst[idx]:
				if bin_lst[v - 1] != str(w):
					flag = False
	if flag:
		ans = max(ans, bin_lst.count('1'))
print(ans)


n = int(input())
ans = 0
g = [[-1 for i in range(n)] for j in range(n)]
for i in range(n):
	a = int(input())
	for j in range(a):
		(x, y) = map(int, input().split())
		g[i][x - 1] = y
for i in range(2 ** n):
	ok = True
	for j in range(n):
		if i >> j & 1:
			for k in range(n):
				if g[j][k] == -1:
					continue
				if i >> k & 1 != g[j][k]:
					ok = False
	if ok:
		d = i
		t = str(bin(d)).count('1')
		ans = max(t, ans)
print(ans)


N = int(input())
XY = [[] for _ in range(N)]
for i in range(N):
	A = int(input())
	for j in range(A):
		XY[i].append(list(map(int, input().split())))
ans = 0
for k in range(2 ** N):
	hu = list(map(int, bin(k)[2:].zfill(N)))
	j = 0
	for i in range(len(XY)):
		if hu[i] == 1:
			for (x, y) in XY[i]:
				if hu[x - 1] != y:
					j = 1
	if j == 0:
		ans = max(ans, hu.count(1))
print(ans)


n = int(input())
l = []
for i in range(n):
	a = int(input())
	l_ = []
	for j in range(a):
		xy = list(map(int, input().split()))
		l_.append(xy)
	l.append(l_)
ans = 0
for i in range(2 ** n):
	table = [0] * n
	flag = False
	for j in range(n):
		if i >> j & 1:
			table[j] = 1
	for j in range(n):
		for k in l[j]:
			if k[1] != table[k[0] - 1] and table[j] == 1:
				flag = True
				break
				if flag:
					break
	if flag == True:
		continue
	ans = max(ans, table.count(1))
print(ans)


n = int(input())
(ans, a, l) = (0, [], [])
for i in range(n):
	a.append(int(input()))
	l.append([])
	for j in range(a[-1]):
		l[i].append(list(map(int, input().split())))
for i in range(2 ** n):
	(c, skip) = ([0] * n, False)
	for j in range(n):
		if i >> j & 1:
			c[j] = 1
	for j in range(n):
		if c[j] == 1:
			for k in range(a[j]):
				if c[l[j][k][0] - 1] != l[j][k][1]:
					skip = True
					break
		if skip:
			break
	else:
		ans = max(ans, sum(c))
print(ans)


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


import sys
input = sys.stdin.readline
n = int(input())
ll = []
for i in range(n):
	a = int(input())
	for _ in range(a):
		(x, y) = map(int, input().split())
		ll += [(i, x - 1, y)]
c = 0
for p in range(2 ** n):
	if all((p >> i & 1 < 1 or p >> x & 1 == y for (i, x, y) in ll)):
		c = max(c, sum((p >> i & 1 for i in range(n))))
print(c)


n = int(input())
A = []
for i in range(n):
	for _ in range(int(input())):
		(x, y) = map(int, input().split())
		A += [(i, x - 1, y)]
print(max((sum(map(int, bin(i)[2:])) for i in range(2 ** n) if all((i >> j & 1 < 1 or i >> x & 1 == y for (j, x, y) in A)))))


import itertools
N = int(input())
T = [[] for _ in range(N)]
for i in range(N):
	for _ in range(int(input())):
		(x, y) = map(int, input().split())
		T[i].append([x - 1, y])
ans = 0
for bit in list(itertools.product([0, 1], repeat=N)):
	ok = True
	for i in range(N):
		if bit[i]:
			for (x, y) in T[i]:
				if bit[x] != y:
					ok = False
	if ok:
		ans = max(ans, sum(bit))
print(ans)


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)


from sys import stdin, stdout
max_honest = 0
testomonies = []
state = []

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

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

def main():
	solve()

def __starting_point():
	main()
__starting_point()


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)


n = int(input())
a = []
for i in range(n):
	b = int(input())
	c = [[] for _ in range(n)]
	for j in range(b):
		(x, y) = map(int, input().split())
		c[x - 1] = y
	a.append(c)
ans = []
for i in range(2 ** n):
	tr = bin(i)[2:].zfill(n)
	cnt = 0
	for j in range(n):
		if tr[j] == '1':
			for k in range(n):
				if a[j][k] != [] and a[j][k] != int(tr[k]):
					break
			else:
				cnt += 1
	if sum(list(map(int, tr))) == cnt:
		ans.append(cnt)
print(max(ans))


n = int(input())
XYS = []
for _ in range(n):
	a = int(input())
	XY = [list(map(int, input().split())) for _ in range(a)]
	XYS.append(XY)
ans = 0
for i in range(2 ** n):
	tp = [-1] * n
	for j in range(n):
		tp[j] = 1 if i >> j & 1 else 0
	flag = True
	for j in range(n):
		if flag == False:
			break
		for (x, y) in XYS[j]:
			if tp[j] == 1:
				(x, y) = (x - 1, y)
				if tp[x] != y:
					flag = False
					break
	if flag:
		ans = max(ans, sum(tp))
print(ans)


N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
	for _ in range(int(input())):
		A[i].append(list(map(int, input().split())))
ans = []
for i in range(2 ** N):
	Bit = [1] * N
	for j in range(N):
		if i >> j & 1:
			Bit[j] = 0
	i = 0
	no = 0
	while i < N:
		if Bit[i] == 1:
			for (x, y) in A[i]:
				if Bit[x - 1] != y:
					no = 1
		i += 1
	if no:
		ans.append(0)
	else:
		ans.append(Bit.count(1))
print(max(ans))


import sys, itertools as it
input = sys.stdin.readline
n = int(input())
ll = []
for i in range(n):
	a = int(input())
	for _ in range(a):
		(x, y) = map(int, input().split())
		ll += [(i, x - 1, y)]
c = 0
for p in it.product([0, 1], repeat=n):
	b = 1
	for (i, x, y) in ll:
		if p[i] and p[x] != y:
			b = 0
			break
	if b:
		c = max(c, sum(p))
print(c)


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)


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

def is_valid(s):
	for i in range(n):
		if s[i] == 0:
			continue
		for (x, y) in a[i]:
			if s[x] != y:
				return False
	return True
ans = 0
for i in range(1 << n):
	s = [0] * n
	for j in range(n):
		if i >> j & 1:
			s[j] = 1
	if is_valid(s):
		ans = max(ans, sum(s))
print(ans)


N = int(input())
A = [[] for i in range(N)]
for i in range(N):
	for j in range(int(input())):
		A[i].append(list(map(int, input().split())))
flag = True
ans = []
for i in range(2 ** N):
	l = list(format(i, 'b').zfill(N))
	k = [int(s) for s in l]
	for j in range(N):
		if k[j] == 1:
			for l in range(len(A[j])):
				if A[j][l][1] != k[A[j][l][0] - 1]:
					flag = False
					break
	if flag == True:
		ans.append(k.count(1))
	else:
		flag = True
print(max(ans))


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


N = int(input())
mastar_list = []
for i in range(2 ** N):
	x = '{:0' + str(N) + 'b}'
	mastar_list.append(list(map(int, x.format(i))))
current = 1
ans = []
judge = [True for i in range(2 ** N)]
while current <= N:
	now = current - 1
	loop_num = int(input())
	for i in range(loop_num):
		(a, b) = list(map(int, input().split()))
		c = a - 1
		for (index, situation) in enumerate(mastar_list):
			if situation[now] == 1:
				if situation[c] == b:
					pass
				else:
					judge[index] = False
			else:
				pass
	current += 1
ans = []
for (index, content) in enumerate(judge):
	if content:
		ans.append(sum(mastar_list[index]))
print(max(ans))


n = int(input())
q = [['-'] * n for _ in range(n)]
for i in range(n):
	a = int(input())
	for j in range(a):
		(x, y) = map(int, input().split())
		q[i][x - 1] = False if y == 0 else True
ans = 0
for bit in range(1 << n):
	arr = [False] * n
	for i in range(n):
		if bit >> i & 1 == 1:
			arr[i] = True
	flag = True
	for i in range(n):
		if arr[i] == False:
			continue
		for j in range(n):
			if q[i][j] == '-':
				continue
			if q[i][j] != arr[j]:
				flag = False
				break
	if flag:
		ans = max(ans, arr.count(True))
print(ans)


import sys
from io import StringIO
import unittest
import itertools

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

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


N = int(input())
W = [[-1] * N for _ in range(N)]
for i in range(N):
	A = int(input())
	for j in range(A):
		(x, y) = [int(z) for z in input().split()]
		x -= 1
		W[i][x] = y
M = 0
for b in range(2 ** N):
	d = [0] * N
	for i in range(N):
		if b >> i & 1:
			d[i] = 1
	ok = True
	for i in range(N):
		if d[i] == 1:
			for j in range(N):
				if W[i][j] == -1:
					continue
				if W[i][j] != d[j]:
					ok = False
	if ok == True:
		M = max(M, sum(d))
print(M)


from itertools import product

def solve(bit):
	for (i, j) in enumerate(bit):
		if j == 1:
			for (x, y) in xy[i]:
				if bit[x - 1] != y:
					return 0
	return sum(bit)
n = int(input())
xy = [[] for i in range(n)]
for i in range(n):
	for j in range(int(input())):
		xy[i].append(list(map(int, input().split())))
ans = 0
for bit in product([0, 1], repeat=n):
	ans = max(ans, solve(bit))
print(ans)


import sys, itertools
input = sys.stdin.readline
n = int(input())
ll = []
for i in range(n):
	a = int(input())
	for j in range(a):
		(x, y) = map(int, input().split())
		ll.append([i, x - 1, y])
ans = 0
for p in itertools.product([1, 0], repeat=n):
	ok = 1
	for l in ll:
		if p[l[0]] == 1 and p[l[1]] != l[2]:
			ok = 0
			break
	if ok:
		ans = max(ans, sum(p))
print(ans)


from itertools import product
N = int(input())
B = list(product([1, 0], repeat=N))
L = []
for i in range(N):
	A = int(input())
	for j in range(A):
		(x, y) = map(int, input().split())
		L.append([x, y, i + 1])
ans = 0
for b in B:
	for l in L:
		if b[l[2] - 1] == 1 and l[1] != b[l[0] - 1]:
			break
	else:
		if ans < b.count(1):
			ans = b.count(1)
print(ans)


n = int(input())
word = []
for _ in range(n):
	a = int(input())
	l = [list(map(int, list(input().split()))) for _ in range(a)]
	word.append(l)
ans = 0
for i in range(2 ** n):
	flag = 0
	for j in range(n):
		if i >> j & 1 == 1 and flag == 0:
			for (k, v) in word[j]:
				if i >> k - 1 & 1 != v:
					flag = 1
					break
	if flag == 0:
		ans = max(ans, bin(i).count('1'))
print(ans)


n = int(input())
L = [[list(map(int, input().split())) for _ in range(int(input()))] for _ in range(n)]
a = 0
for i in range(1, 2 ** n):
	f = True
	for j in range(n):
		if i >> j & 1 == 0:
			continue
		for (x, y) in L[j]:
			if i >> x - 1 & 1 != y:
				f = False
				break
		if not f:
			break
	if f:
		a = max(a, bin(i)[2:].count('1'))
print(a)


n = int(input())
a = []
xy = [[] for i in range(n)]
for i in range(n):
	a.append(int(input()))
	for j in range(a[i]):
		xy[i].append(list(map(int, input().split())))
ans = 0
for i in range(2 ** n):
	tf = [False for j in range(n)]
	for j in range(n):
		if i >> j & 1:
			tf[j] = True
	flag = False
	for j in range(n):
		for k in range(a[j]):
			if tf[j]:
				if xy[j][k][1] != tf[xy[j][k][0] - 1]:
					flag = True
					break
		if flag:
			break
	else:
		ans = max(ans, tf.count(True))
print(ans)


n = int(input())
say = []
for i in range(n):
	a = int(input())
	for j in range(a):
		(x, y) = map(int, input().split())
		say.append([i, x - 1, y])
ans = 0
fm = '0' + str(n) + 'b'
for i in range(2 ** n):
	flag = True
	s = str(format(i, fm))
	for j in say:
		if s[j[0]] == '1' and int(s[j[1]]) + j[2] == 1:
			flag = False
			break
	if flag and ans < s.count('1'):
		ans = s.count('1')
print(ans)


import itertools
n = int(input())
b = []
for i in range(n):
	a = int(input())
	c = []
	for j in range(a):
		(x, y) = map(int, input().split())
		c.append([x, y])
	b.append(c)
g = []
for i in list(itertools.product(range(2), repeat=n)):
	flag = True
	for j in range(n):
		if i[j] == 0:
			continue
		for (x, y) in b[j]:
			if i[x - 1] != y:
				flag = False
				break
		if not flag:
			break
	if flag:
		g.append(sum(i))
print(max(g))


n = int(input())
a = [[list(map(int, input().split())) for _ in '_' * int(input())] for _ in '_' * n]
m = 0
for i in range(2 ** n):
	(*s,) = map(int, bin(i)[2:].zfill(n))
	f = 1
	for (j, t) in enumerate(a):
		if s[~j]:
			for (x, y) in t:
				f &= s[-x] == y
	m = max(m, sum(s) * f)
print(m)


n = int(input())
statement = [[] for _ in range(n)]
for i in range(n):
	A = int(input())
	for j in range(A):
		(x, y) = list(map(int, input().split()))
		if y == 1:
			statement[i].append([x - 1, True])
		if y == 0:
			statement[i].append([x - 1, False])
cnt = 0
for bit in range(2 ** n):
	honest = []
	for i in range(n):
		if bit >> i & 1:
			honest.append(i)
	flag = True
	for j in range(len(statement)):
		if j in honest:
			for k in honest:
				if [j, False] in statement[k]:
					flag = False
					break
		else:
			for k in honest:
				if [j, True] in statement[k]:
					flag = False
					break
		if not flag:
			break
	if flag:
		cnt = max(cnt, len(honest))
print(cnt)


import itertools
N = int(input())
dic = {}
cnt = 0
ok = []
for i in range(N):
	A = int(input())
	for j in range(A):
		(x, y) = (int(t) for t in input().split())
		dic[i, x] = y
for i in itertools.product([0, 1], repeat=N):
	for k in dic.keys():
		if i[k[0]] == 0:
			continue
		if dic[k] != i[k[1] - 1]:
			break
	else:
		ok += [i]
mm = 0
for i in ok:
	mm = max(mm, sum(i))
print(mm)


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


import itertools
N = int(input())
l = [[] for i in range(N)]
for i in range(N):
	a = int(input())
	for j in range(a):
		(x, y) = map(int, input().split())
		l[i].append((x - 1, y))
ans = 0
for t in itertools.product(range(2), repeat=N):
	miss = False
	for i in range(N):
		if t[i] == 0:
			continue
		for (x, y) in l[i]:
			if not t[x] == y:
				break
		else:
			continue
		break
	else:
		ans = max(ans, sum(t))
print(ans)


n = int(input())
statements = []
for i in range(n):
	a = int(input())
	astates = [list(map(int, input().split())) for _ in range(a)]
	statements.append(astates)
cnt = 0
for i in range(2 ** n):
	state = format(i, '0' + str(n) + 'b')
	pos = True
	for j in range(n):
		if state[j] == '1':
			for (x, y) in statements[j]:
				if not state[x - 1] == str(y):
					pos = False
					break
		if not pos:
			break
	if pos:
		cnt = max(cnt, state.count('1'))
print(cnt)


n = int(input())
a = []
x = []
for _ in range(n):
	A = int(input())
	X = [list(map(int, input().split())) for _ in range(A)]
	a.append(A)
	x.append(X)
ans = 0
for i in range(2 ** n):
	tmp = [0] * n
	for j in range(n):
		if i >> j & 1:
			tmp[j] = 1
	for k in range(n):
		for h in range(a[k]):
			hito = x[k][h][0] - 1
			singi = x[k][h][1]
			if tmp[k] == 1:
				if tmp[hito] != singi:
					break
		else:
			continue
		break
	else:
		ans = max(ans, sum(tmp))
print(ans)


N = int(input())
syougen = [[] for _ in range(N)]
for i in range(N):
	num = int(input())
	for j in range(num):
		(x, y) = map(int, input().split())
		syougen[i].append([x, y])
ans = 0
for bit in range(1 << N):
	break_flag = 0
	for i in range(N):
		if bit >> i & 1:
			for j in range(len(syougen[i])):
				if bit >> syougen[i][j][0] - 1 & 1 != syougen[i][j][1]:
					break_flag = 1
					break
			if break_flag == 1:
				break
		if i == N - 1:
			ans = max(ans, bin(bit).count('1'))
print(ans)


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


import sys
from itertools import chain
from itertools import product

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

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

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

def __starting_point():
	main()
__starting_point()


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)


def main():
	N = int(input())
	A = [[] for i in range(N)]
	for i in range(N):
		a = int(input())
		for j in range(a):
			(x, y) = [int(b) for b in input().split(' ')]
			A[i].append([x - 1, str(y)])
	cand = []
	for i in range(2 ** N):
		honest_flag = True
		bit = list(pad_zero(format(i, 'b'), N))
		honests = [int(p) for (p, q) in enumerate(bit) if q == '1']
		for honest in honests:
			w = A[honest]
			for k in range(len(w)):
				if w[k][1] != bit[w[k][0]]:
					honest_flag = False
		if honest_flag:
			cand.append(len(honests))
	print(max(cand))

def pad_zero(s, n):
	s = str(s)
	return ('0' * n + s)[-n:]
main()


n = int(input())
xy = [[[]] for _ in range(n)]
for i in range(n):
	a = int(input())
	xy[i] = [list(map(int, input().split())) for _ in range(a)]
ans = 0
for i in range(2 ** n):
	tmp = [0] * n
	flag1 = True
	for j in range(n):
		if i >> j & 1:
			tmp[j] = 1
	for k in range(n):
		flag2 = True
		if tmp[k] == 1:
			for (x, y) in xy[k]:
				if tmp[x - 1] != y:
					flag1 = False
					flag2 = False
					break
		if not flag2:
			break
	if flag1:
		ans = max(ans, sum(tmp))
print(ans)


from itertools import product
n = int(input())
data = {}
for p in range(1, n + 1):
	a = int(input())
	data[p] = [list(map(int, input().split())) for _ in range(a)]
ans = 0
for honest in product(range(2), repeat=n):
	for (p, hk) in enumerate(honest, 1):
		if hk == 1:
			if not all([honest[x - 1] == y for (x, y) in data[p]]):
				break
	else:
		ans = max(ans, sum(honest))
print(ans)


n = int(input())
a = []
for i in range(n):
	m = int(input())
	a.append(list((list(map(int, input().split())) for i in range(m))))
ans = 0
for i in range(2 ** n):
	r = 1
	ib = list(format(i, 'b').zfill(n))
	for j in range(n):
		if ib[j] == '1':
			for k in range(len(a[j])):
				if int(ib[a[j][k][0] - 1]) != a[j][k][1]:
					r = 0
	if r == 1:
		ans = max(ans, ib.count('1'))
print(ans)


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


n = int(input())
x = [[] for i in range(n)]
for i in range(n):
	a = int(input())
	for j in range(a):
		x[i].append(tuple(map(int, input().split())))
m = 0
for i in range(1, 2 ** n):
	c = bin(i)[2:]
	c = '0' * (n - len(c)) + c
	f = 1
	co = 0
	for j in range(n):
		if c[j] == '1':
			co += 1
			for (k, l) in x[j]:
				if int(c[k - 1]) != l:
					f = 0
					break
		if f == 0:
			break
	if f:
		m = max(m, co)
print(m)


n = int(input())
all_h_or_u = []
for i in range(n):
	x = int(input())
	h_or_u = []
	for j in range(x):
		h_or_u.append(list(map(int, input().split())))
	for k in range(x):
		h_or_u[k][0] -= 1
	all_h_or_u.append(h_or_u)
all_t_or_f = []
for a in range(2 ** n):
	t_or_f = []
	for b in range(len(bin(2 ** n)) - 3):
		if a >> b & 1:
			t_or_f.append(1)
		else:
			t_or_f.append(0)
	all_t_or_f.append(t_or_f)
max_cnt = 0
for c in all_t_or_f:
	cnt = 0
	for d in range(n):
		if c[d] == 1:
			for e in all_h_or_u[d]:
				if c[e[0]] != e[1]:
					cnt += 1
	if cnt == 0:
		max_cnt = max(max_cnt, sum(c))
print(max_cnt)


n = int(input())
syougen = []
for i in range(n):
	a = int(input())
	for _ in range(a):
		(x, y) = map(int, input().split())
		syougen.append([i, x - 1, y])
ans = 0
for bit in range(2 ** n):
	for s in syougen:
		if bit >> s[0] & 1 == 1:
			if bit >> s[1] & 1 != s[2]:
				break
	else:
		thisans = str(bin(bit)).count('1')
		ans = max(ans, thisans)
print(ans)


N = int(input())
state = []
for _ in range(N):
	A = int(input())
	for i in range(A):
		(x, y) = map(int, input().split())
		state.append([_, x - 1, y])
ans = 0
import itertools
for i in itertools.product([1, 0], repeat=N):
	tmp = sum(list(i))
	for j in state:
		if i[j[0]] == 1 and i[j[1]] != j[2]:
			tmp = 0
			break
	ans = max(ans, tmp)
print(ans)


n = int(input())
g = [[-1 for _ in range(15)] for _ in range(15)]
for i in range(n):
	a = int(input())
	for j in range(a):
		(x, y) = map(int, input().split())
		g[i][x - 1] = y
ans = 0
for bit in range(1 << n):
	honests = [0] * n
	for i in range(n):
		if bit & 1 << i:
			honests[i] = 1
	flg = True
	for i in range(n):
		if honests[i]:
			for j in range(n):
				if g[i][j] == -1:
					continue
				if g[i][j] != honests[j]:
					flg = False
	if flg:
		ans = max(ans, honests.count(1))
print(ans)


N = int(input())
arr = [[] for _ in range(N)]
for i in range(N):
	A = int(input())
	for a in range(A):
		(x, y) = map(int, input().split())
		arr[i].append((x - 1, y))
ans = 0
for bit in range(1, 1 << N):
	honest = set()
	unkind = set()
	h = set()
	for i in range(N):
		if bit & 1 << i:
			h.add(i)
			for (x, y) in arr[i]:
				if y:
					honest.add(x)
				else:
					unkind.add(x)
	if 0 == len(honest - h) and h.isdisjoint(unkind) and honest.isdisjoint(unkind):
		ans = max(len(h), ans)
print(ans)


n = int(input())
s = []
for i in range(n):
	a = int(input())
	s_i = []
	for j in range(a):
		(x, y) = map(int, input().split())
		s_i.append([x - 1, y])
	s.append(s_i)
ans = 0
for i in range(2 ** n):
	honest = [0] * n
	skip = False
	for j in range(n):
		if i >> j & 1:
			honest[j] = 1
	for j in range(n):
		if honest[j] == 1:
			for k in range(len(s[j])):
				if honest[s[j][k][0]] != s[j][k][1]:
					skip = True
					break
	if skip:
		continue
	ans = max(ans, sum(honest))
print(ans)


n = int(input())
xy = [[] for _ in range(n)]
for i in range(n):
	a = int(input())
	xy[i] = [[int(i) for i in input().split()] for _ in range(a)]
ans = 0
for i in range(2 ** n):
	lst = [0 for _ in range(n)]
	for j in range(n):
		if i >> j & 1:
			lst[j] = 1
	flag = True
	for j in range(n):
		if lst[j] == 1:
			for (x, y) in xy[j]:
				if lst[x - 1] != y:
					flag = False
					break
			else:
				continue
			break
	if flag:
		ans = max(ans, sum(lst))
print(ans)


import copy
N = int(input())
testimony = []
for n in range(N):
	A = int(input())
	testimony.append({})
	for a in range(A):
		(x, y) = map(int, input().split())
		testimony[n][x - 1] = y

def judge(truthy):
	answer = True
	for i in range(len(truthy)):
		if truthy[i] == 1:
			for t in testimony[i].keys():
				if truthy[t] != testimony[i][t]:
					answer = False
					break
		if not answer:
			break
	return 0 if not answer else truthy.count(1)

def dfs(truthy, depth):
	if N == depth:
		return judge(truthy)
	truth = copy.copy(truthy)
	truth.append(1)
	t = dfs(truth, depth + 1)
	false = copy.copy(truthy)
	false.append(0)
	f = dfs(false, depth + 1)
	return max(t, f)
print(dfs([], 0))


import itertools
n = int(input())
tes = [[] for _ in range(n)]
for i in range(n):
	a = int(input())
	for _ in range(a):
		(x, y) = list(map(int, input().split()))
		tes[i].append([x - 1, y])
ans = 0
for tf_s in itertools.product(list(range(2)), repeat=n):
	for i in range(n):
		if tf_s[i] == 0:
			continue
		for (x, y) in tes[i]:
			if tf_s[x] != y:
				break
		else:
			continue
		break
	else:
		ans = max(ans, tf_s.count(1))
print(ans)


N = int(input())
Alist = []
xylists = []
for i in range(N):
	A = int(input())
	Alist.append(A)
	xylist = []
	for j in range(A):
		xylist.append(tuple(map(int, input().split())))
	xylists.append(xylist)
ans = 0
for bit in range(1 << N):
	HOU = list(reversed(list(format(bit, 'b').zfill(N))))
	notans = False
	for i in range(N):
		if bit & 1 << i:
			for (x, y) in xylists[i]:
				if HOU[x - 1] != str(y):
					notans = True
					break
			else:
				continue
			break
		else:
			continue
		break
	if not notans:
		ans = max(ans, str(bin(bit)).count('1'))
print(ans)


N = int(input())
a = []
for i in range(N):
	A = int(input())
	B = []
	for i in range(A):
		b = list(map(int, input().split()))
		B.append(b)
	a.append(B)
ans = 0
for i in range(2 ** N):
	bi = list(str(bin(i)))
	bi = bi[2:]
	bi = [0] * (N - len(bi)) + bi
	bi = list(map(int, bi))
	p = 1
	for j in range(N):
		if bi[j] == 1:
			for k in range(len(a[j])):
				m = a[j][k][0]
				n = a[j][k][1]
				if bi[m - 1] != n:
					p = 0
					break
	if p == 1:
		ans = max(ans, sum(bi))
print(ans)


n = int(input())
ans = 0
al = []
xy = [[] for _ in range(n)]
for k in range(n):
	a = int(input())
	al.append(a)
	for l in range(a):
		(x, y) = list(map(int, input().split()))
		xy[k].append([x, y])
for i in range(2 ** n):
	kinds = [0] * n
	jud = 1
	for j in range(n):
		if i >> j & 1:
			kinds[j] = 1
	for k in range(n):
		if kinds[k] == 1:
			a = al[k]
			for l in range(a):
				x = xy[k][l][0]
				y = xy[k][l][1]
				if kinds[x - 1] != y:
					jud = 0
	if jud == 1:
		ans = max(ans, kinds.count(1))
print(ans)


def is_right(i):
	trueA = bin(i)[2:].zfill(N)
	for (ii, flag) in enumerate(trueA):
		if flag == '1':
			for (x, y) in A[ii]:
				if trueA[x] != str(y):
					return False
	return True
N = int(input())
A = []
for _ in range(N):
	a = int(input())
	tmpA = []
	for _ in range(a):
		(x, y) = map(int, input().split())
		tmpA.append([x - 1, y])
	A.append(tmpA)
ans = 0
for i in range(2 ** N):
	if is_right(i):
		ans = max(ans, bin(i).count('1'))
print(ans)


N = int(input())
XY = [[list(map(int, input().split())) for i in range(int(input()))] for j in range(N)]
ans = 0
for i in range(2 ** N):
	table = list(format(i, 'b').zfill(N)[::-1])
	f = 1
	for (j, l) in enumerate(XY):
		if table[j] == '1':
			for xy in l:
				x = xy[0] - 1
				y = xy[1]
				if table[x] != str(y):
					f = 0
					break
		if f == 0:
			break
	if f:
		ans = max(ans, table.count('1'))
print(ans)


n = int(input())
li = []
for i in range(n):
	a = int(input())
	subli = []
	for j in range(a):
		(x, y) = list(map(int, input().split()))
		subli.append([x, y])
	li.append(subli)
ans = 0
for i in range(2 ** n):
	tf = [False] * n
	out = False
	for j in range(n):
		if i >> j & 1:
			tf[j] = True
	for k in range(len(li)):
		if tf[k] == True:
			for l in li[k]:
				if not l[1] == tf[l[0] - 1]:
					out = True
	if not out:
		ans = max(ans, tf.count(True))
print(ans)


N = int(input())
A = []
X = []
Y = []
for _ in range(N):
	a = int(input())
	A.append(a)
	box_x = []
	box_y = []
	for _ in range(a):
		(x, y) = map(int, input().split())
		box_x.append(x)
		box_y.append(y)
	X.append(box_x)
	Y.append(box_y)
person = [2] * N
maxim = 0
for i in range(1 << N):
	c_person = person.copy()
	honest = 0
	for j in range(N):
		mask = 1 << j
		if mask & i != 0:
			c_person[j] = 1
		else:
			c_person[j] = 0
	for (k, l) in enumerate(c_person):
		if l == 1:
			for (m, n) in zip(X[k], Y[k]):
				if c_person[m - 1] != n:
					honest = 0
					break
			else:
				honest = sum(c_person)
				continue
			break
	maxim = max(maxim, honest)
print(maxim)


n = int(input())
evi = []
for _ in range(n):
	m = int(input())
	evi.append([list(map(int, input().split())) for _ in range(m)])
ans = 0
for i in range(1 << n):
	for j in range(n):
		if i >> j & 1 == 1:
			for (x, y) in evi[j]:
				if i >> x - 1 & 1 != y:
					break
			else:
				continue
			break
	else:
		ans = max(ans, bin(i).count('1'))
print(ans)


N = int(input())
xy_list = []
for _ in range(N):
	A = int(input())
	xy = []
	for _ in range(A):
		xy.append(list(map(int, input().split())))
	xy_list.append(xy)
ans = 0
for i in range(2 ** N):
	for (j, a_list) in enumerate(xy_list):
		if i >> j & 1 == 1:
			for (k, (x, y)) in enumerate(a_list):
				if i >> x - 1 & 1 != y:
					break
			else:
				continue
			break
	else:
		ans = max(ans, bin(i)[2:].count('1'))
print(ans)


from itertools import product
n = int(input())
d = {}
for i in range(n):
	a = int(input())
	for _ in range(a):
		(x, y) = map(int, input().split())
		if i + 1 not in d:
			d[i + 1] = []
		d[i + 1].append((x, y))
ret = 0
for x in product((0, 1), repeat=n):
	tmp = [-1] * n
	ok = True
	for i in range(n):
		if x[i] == 1 and i + 1 in d:
			for y in d[i + 1]:
				if tmp[y[0] - 1] == -1:
					tmp[y[0] - 1] = y[1]
				elif tmp[y[0] - 1] != y[1]:
					ok = False
					break
		if not ok:
			break
	if ok and all((a == b or b == -1 for (a, b) in zip(x, tmp))):
		ret = max(ret, sum(x))
print(ret)


N = int(input())
xy = [[] for _ in range(N)]
for i in range(N):
	a = int(input())
	for _ in range(a):
		(x, y) = map(int, input().split())
		x -= 1
		xy[i].append((x, y))
ans = 0
s = set()
t = set()

def true(s, t, j):
	if j not in t:
		s.add(j)
		return False
	return True

def false(s, t, j):
	if j not in s:
		t.add(j)
		return False
	return True

def chk(i):
	s = set()
	t = set()
	fl = False
	for j in range(N):
		if i >> j & 1:
			fl |= true(s, t, j)
			for (x, y) in xy[j]:
				fl |= true(s, t, x) if y == 1 else false(s, t, x)
		else:
			fl |= false(s, t, j)
	return fl
ans = 0
for i in range(2 ** N):
	if chk(i):
		continue
	cnt = 0
	for j in range(N):
		if i >> j & 1:
			cnt += 1
	ans = max(ans, cnt)
print(ans)


n = int(input())
g = [[[], []] for _ in range(n)]
for i in range(n):
	a = int(input())
	g[i] = [tuple(map(int, input().split())) for _ in range(a)]
ans = 0
for num in range(1 << n):
	p = [j for j in range(n) if num & 1 << j]
	fl = 0
	for v in p:
		for (x, y) in g[v]:
			if bool(num & 1 << x - 1) != y:
				fl = 1
				break
		if fl:
			break
	else:
		if ans < len(p):
			ans = len(p)
print(ans)


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

def check(a):
	for i in range(N):
		if a[i] == 0:
			continue
		for (x, y) in xy[i]:
			if a[x - 1] != y:
				return -1
	return a.count(1)
r = 0
for i in range(2 ** N):
	bstr = format(i, '0%db' % N)
	a = tuple(map(int, bstr))
	t = check(a)
	if t > r:
		r = t
print(r)


n = int(input())
words = []
for i in range(n):
	a = int(input())
	w = []
	for _ in range(a):
		(x, y) = map(int, input().split())
		w.append([x - 1, y])
	words.append(w)
ans = 0
for bit in range(1 << n):
	ok = True
	is_honest = [bit >> i & 1 for i in range(n)]
	for i in range(n):
		if not is_honest[i]:
			continue
		for (x, y) in words[i]:
			if is_honest[x] != y:
				ok = False
	if ok:
		ans = max(ans, sum(is_honest))
print(ans)


n = int(input())
a = []
l = []
for i in range(n):
	A = int(input())
	L = [list(map(int, input().split())) for _ in range(A)]
	a.append(A)
	l.append(L)
ans = 0
for i in range(2 ** n):
	b = [0] * n
	for j in range(n):
		if i >> j & 1:
			b[j] = 1
	for k in range(n):
		for h in range(a[k]):
			hito = l[k][h][0] - 1
			singi = l[k][h][1]
			if b[k] == 1 and b[hito] != singi:
				break
		else:
			continue
		break
	else:
		ans = max(ans, sum(b))
print(ans)


N = int(input())
XY = [[[]] for n in range(N + 1)]
for n in range(1, N + 1):
	a = int(input())
	XY[n] = [list(map(int, input().split())) for _ in range(a)]
maxH = 0
for mask_i in range(1 << N):
	H = [0] * (N + 1)
	for n in range(N):
		if mask_i >> n & 1:
			H[n + 1] = 1
	ok = True
	for n in range(1, N + 1):
		if H[n] == 1:
			for (x, y) in XY[n]:
				if H[x] != y:
					ok = False
					break
	if ok:
		maxH = max(maxH, sum(H))
print(maxH)


import sys
input = sys.stdin.readline
n = int(input())
(a, x) = ([], [])
for i in range(n):
	A = int(input())
	a.append(A)
	B = []
	for j in range(A):
		B.append(list(map(int, input().split())))
	x.append(B)
ma = 0
for i in range(2 ** n):
	now = 0
	flg = True
	e = [0] * n
	for j in range(n):
		if i >> j & 1:
			now += 1
			e[j] = 1
	for j in range(n):
		if i >> j & 1:
			if e[j] == 0:
				flg = False
				break
			elif not flg:
				break
			for k in range(a[j]):
				if e[x[j][k][0] - 1] == 0 and x[j][k][1] == 1 or (e[x[j][k][0] - 1] == 1 and x[j][k][1] == 0):
					flg = False
					break
	if flg and ma < now:
		ma = now
print(ma)


from itertools import *
N = int(input())
H = []
A = []
for i in range(N):
	for j in range(int(input())):
		(x, y) = map(int, input().split())
		H += [[i, x - 1, y]]
for P in product([0, 1], repeat=N):
	for h in H:
		if P[h[0]] == 1 and P[h[1]] != h[2]:
			break
	else:
		A += [sum(P)]
print(max(A))


n = int(input())
li = [[-1 for _ in range(n)] for _ in range(n)]
for i in range(n):
	a = int(input())
	for j in range(a):
		(x, y) = map(int, input().split())
		li[i][x - 1] = y
ans = 0
for i in range(2 ** n):
	s = 0
	t = [0] * n
	for j in range(n):
		if i >> j & 1:
			t[j] = 1
	is_contradict = 0
	for j in range(n):
		if t[j]:
			for k in range(n):
				if li[j][k] == -1:
					continue
				if li[j][k] != t[k]:
					is_contradict = 1
	if not is_contradict:
		ans = max(ans, sum(t))
print(ans)


n = int(input())
v = [[tuple(map(int, input().split())) for i in range(int(input()))] for i in range(n)]
ans = 0
for i in range(2 ** n):
	f = True
	a = 0
	for j in range(n):
		if i >> j & 1:
			if all((i >> x - 1 & 1 == y for (x, y) in v[j])):
				a += 1
			else:
				f = False
				break
	if f:
		ans = max(ans, a)
print(ans)


n = int(input())
a = [0 for _ in range(n)]
x = [[] for _ in range(n)]
y = [[] for _ in range(n)]
for i in range(n):
	a[i] = int(input())
	for _ in range(a[i]):
		(x_, y_) = list(map(int, input().split()))
		x_ -= 1
		x[i].append(x_)
		y[i].append(y_)
max_honest = 0
for i in range(2 ** n):
	s = []
	tmp = i
	for _ in range(n):
		s.append(tmp % 2)
		tmp //= 2
	s = list(reversed(s))
	honest = sum(s)
	ok = True
	for j in range(n):
		for k in range(a[j]):
			if s[j] == 1 and s[x[j][k]] != y[j][k]:
				ok = False
				break
		if not ok:
			break
	if ok:
		if max_honest <= honest:
			max_honest = honest
print(max_honest)


N = int(input())
A = [[] * N for _ in range(N)]
for i in range(N):
	a = int(input())
	for _ in range(a):
		(x, y) = [int(x) for x in input().split()]
		A[i].append([x - 1, y])
ans = 0
for i in range(1, 1 << N):
	B = format(i, f'0{N}b')[::-1]
	possible = True
	cnt = 0
	for j in range(N):
		if B[j] == '1':
			cnt += 1
			for v in A[j]:
				if v[1] != int(B[v[0]]):
					possible = False
					break
	if possible:
		ans = max(ans, cnt)
print(ans)


n = int(input())
a = []
for i in range(n):
	num = int(input())
	for j in range(num):
		(x, y) = map(int, input().split())
		a.append([i, x - 1, y])
m = 0
for i in range(1, 2 ** n):
	se = format(i, 'b').zfill(n)
	flg = True
	for j in a:
		if se[j[0]] == '1':
			if int(se[j[1]]) ^ j[2] == 1:
				flg = False
				break
	if flg is True:
		m = max([m, se.count('1')])
print(m)


N = int(input())
A = list()
T = [list() for i in range(N)]
for i in range(N):
	a = int(input())
	A.append(a)
	for a in range(a):
		(x, y) = list(map(int, input().split()))
		x -= 1
		T[i].append((x, y))
ans = 0
for i in range(2 ** N):
	persons = list()
	for j in range(N):
		if i >> j & 1 == 1:
			persons.append(j)
	d = [False] * N
	for p in persons:
		d[p] = True
	judged = [False] * N
	for num in range(N):
		f = False
		if d[num]:
			for t in T[num]:
				(x, y) = (t[0], t[1])
				if y == 1 and d[x] != True:
					f = True
					break
				if y == 0 and d[x] != False:
					f = True
					break
		if f:
			break
	else:
		ans = max(ans, len(persons))
print(ans)


N = int(input())
E = []
for n in range(N):
	A = int(input())
	for _ in range(A):
		(x, y) = list(map(int, input().split()))
		E.append((n, x - 1, y))
ans = 0
for k in range((1 << N) - 1, -1, -1):
	l = [k >> i & 1 for i in range(N)]
	OK = True
	for (e0, e1, e2) in E:
		if l[e0] == 1 and l[e1] != e2:
			OK = False
			break
	if OK:
		ans = max(ans, sum(l))
print(ans)


N = int(input())
S = [[-1] * N for _ in range(N)]
for i in range(N):
	A = int(input())
	for _ in range(A):
		(x, y) = map(int, input().split())
		S[i][x - 1] = y
ans = 0
for s in range(2 ** N):
	ok = True
	for i in range(N):
		if s >> i & 1 == 1:
			for j in range(N):
				if S[i][j] != -1 and s >> j & 1 != S[i][j]:
					ok = False
	if ok:
		ans = max(ans, bin(s).count('1'))
print(ans)


n = int(input())
graph = [[-1 for _ in range(n)] for _ in range(n)]
for i in range(n):
	a = int(input())
	for _ in range(a):
		(x, y) = map(int, input().split())
		graph[i][x - 1] = y
ans = 0
for p in range(2 ** n):
	q = p
	c = 0
	t = []
	l = 0
	while q:
		if q & 1:
			t.append(graph[c])
			l += 1
		q >>= 1
		c += 1
	flag = True
	for c in range(n):
		if p & 1:
			for s in t:
				if s[c] == 0:
					flag = False
		else:
			for s in t:
				if s[c] == 1:
					flag = False
		p >>= 1
	if flag:
		ans = max(ans, l)
print(ans)


n = int(input())
xy = [[] for _ in range(n)]
for i in range(n):
	for j in range(int(input())):
		xy[i].append(list(map(int, input().split())))
ans = 0
for i in range(1, 1 << n):
	syojiki = [(i & 1 << j != 0) + 0 for j in range(n)]
	flag = True
	for j in range(n):
		for (x, y) in xy[j]:
			if syojiki[x - 1] != y and syojiki[j] == 1:
				flag = False
	if flag:
		ans = max(ans, syojiki.count(1))
print(ans)


from itertools import product
n = int(input())
test = []
for i in range(n):
	a = int(input())
	test.append([list(map(int, input().split())) for i in range(a)])
ans = 0
for i in product(range(2), repeat=n):
	flag = True
	for j in range(n):
		if i[j] == 1:
			for s in test[j]:
				if i[s[0] - 1] != s[1]:
					flag = False
					break
	if flag == True:
		cnt = i.count(1)
		if cnt > ans:
			ans = cnt
print(ans)


import itertools
import sys
input = sys.stdin.readline
n = int(input())
data = []
for x in range(n):
	for y in range(int(input())):
		(k, l) = map(int, input().split())
		data.append((x, k - 1, l))
ans = 0
for i in itertools.product([1, 0], repeat=n):
	s = sum(list(i))
	for g in data:
		if i[g[0]] == 1 and i[g[1]] != g[2]:
			s = 0
			break
	ans = max(ans, s)
print(ans)


n = int(input())
a = []
for _ in range(n):
	m = int(input())
	a.append([list(map(int, input().split())) for _ in range(m)])
ans = 0
for i in range(2 ** n):
	for j in range(n):
		if i >> j & 1 == 1:
			for (k, l) in a[j]:
				if i >> k - 1 & 1 != l:
					break
			else:
				continue
			break
	else:
		ans = max(ans, bin(i).count('1'))
print(ans)


N = int(input())
T = []
ans = 0
for i in range(N):
	a = int(input())
	T.append([list(map(int, input().split())) for _ in range(a)])
for bit in range(1 << N):
	target = bin(bit)[2:].zfill(N)
	nk = 0
	for i in range(N):
		if target[i] == '1':
			if any((target[x - 1] != str(y) for (x, y) in T[i])):
				break
			else:
				nk += 1
	else:
		ans = max(ans, nk)
print(ans)


n = int(input())
g = [[-1 for j in range(n)] for i in range(n)]
for i in range(n):
	a = int(input())
	for _ in range(a):
		(x, y) = map(int, input().split())
		g[i][x - 1] = y
ans = 0
for s in range(2 ** n):
	ok = True
	for i in range(n):
		if s >> i & 1 == 1:
			for j in range(n):
				if g[i][j] != -1 and s >> j & 1 != g[i][j]:
					ok = False
	if ok:
		ans = max(ans, bin(s).count('1'))
print(ans)


n = int(input())
a = []
x = [[-1] * n for _ in range(n)]
y = [[-1] * n for _ in range(n)]
ans = 0
for i in range(n):
	a.append(int(input()))
	for j in range(a[-1]):
		(x[i][j], y[i][j]) = map(int, input().split())
for i in range(2 ** n):
	for j in range(n):
		if i >> j & 1:
			for k in range(a[j]):
				if not i >> x[j][k] - 1 & 1 == y[j][k]:
					break
			else:
				continue
			break
	else:
		ans = max(ans, sum([i >> j & 1 for j in range(n)]))
print(ans)


from itertools import product
n = int(input())
xy = []
for _ in range(n):
	a = int(input())
	tmp = []
	for j in range(a):
		(x, y) = [int(x) for x in input().split()]
		tmp.append((x, y))
	xy.append(tmp)
ans = 0
for ts in product([0, 1], repeat=n):
	for (i, t) in enumerate(ts):
		if t:
			if not all((ts[q - 1] == z for (q, z) in xy[i])):
				break
	else:
		ans = max(ans, sum(ts))
print(ans)


N = int(input())
testimony = []
for i in range(N):
	A = int(input())
	testimony.append([-1] * N)
	for i in range(A):
		(x, y) = map(int, input().split())
		testimony[-1][x - 1] = y
ans = 0
for i in range(2 ** N):
	total = 0
	tmplst = [0] * N
	for j in range(N):
		if i >> j & 1:
			tmplst[j] = 1
	ch = 0
	for j in range(N):
		if tmplst[j] == 1:
			for (a, b) in zip(testimony[j], tmplst):
				if a == 1 and b == 0 or (a == 0 and b == 1):
					ch = 1
					break
			if ch == 1:
				break
	if ch == 0:
		if ans < sum(tmplst):
			ans = sum(tmplst)
print(ans)


from itertools import product
n = int(input())
xy = []
for _ in range(n):
	a = int(input())
	tmp = [list(map(int, input().split())) for _ in range(a)]
	xy.append(tmp)
ans = 0
for bit in product([0, 1], repeat=n):
	for (i, liar) in enumerate(bit):
		if liar and any((bit[x - 1] != y for (x, y) in xy[i])):
			break
	else:
		ans = max(ans, sum(bit))
print(ans)


from itertools import product
N = int(input())
L = list(product([0, 1], repeat=N))
T = [[] for i in range(N)]
for i in range(N):
	A = int(input())
	for j in range(A):
		(x, y) = map(int, input().split())
		T[i].append((x, y))
ans = 0
for l in L:
	F = True
	for (i, k) in enumerate(l):
		if k == 1:
			for j in T[i]:
				if l[j[0] - 1] != j[1]:
					F = False
	if F:
		ans = max(ans, sum(l))
print(ans)


from itertools import product
n = int(input())
d = {}
for i in range(n):
	a = int(input())
	for _ in range(a):
		(x, y) = map(int, input().split())
		if i + 1 not in d:
			d[i + 1] = []
		d[i + 1].append((x, y))
ret = 0
for x in product((0, 1), repeat=n):
	ok = True
	for i in range(n):
		if x[i] == 0 or i + 1 not in d:
			continue
		for (p, tf) in d[i + 1]:
			if x[p - 1] != tf:
				ok = False
				break
		if not ok:
			break
	if ok:
		ret = max(ret, sum(x))
print(ret)


N = int(input())
syogen = []
for i in range(N):
	a = int(input())
	temp = [list(map(int, input().split())) for _ in range(a)]
	syogen.append([a, temp])
ans = 0
for h in range(2 ** N):
	flag = 0
	cnt = 0
	l = [0] * N
	for g in range(N):
		if h >> g & 1:
			l[g] = 1
	for gg in range(N):
		if l[gg] == 1:
			temp_ = syogen[gg]
			for n in range(temp_[0]):
				if l[temp_[1][n][0] - 1] == temp_[1][n][1]:
					continue
				else:
					flag = 1
					break
		if flag == 1:
			break
		elif flag == 0 and gg == N - 1:
			ans = max(ans, sum(l))
print(ans)


N = int(input())
T = []
for i in range(N):
	for _ in range(int(input())):
		(x, y) = map(int, input().split())
		T.append((i, x - 1, y))
ans = 0
for i in range(1 << N):
	is_kind = [i >> j & 1 for j in range(N)]
	if all((not is_kind[j] or is_kind[x] == y for (j, x, y) in T)):
		ans = max(ans, sum(is_kind))
print(ans)


import itertools
n = int(input())
s = [[] for i in range(n)]
for i in range(n):
	a = int(input())
	for j in range(a):
		(x, y) = [int(x) for x in input().split()]
		x -= 1
		s[i].append([x, y])
l = []
a = itertools.product(range(2), repeat=n)
for i in a:
	l.append(i)
ans = 0
for i in range(2 ** n):
	c = []
	for j in range(n):
		if l[i][j] == 1:
			for k in s[j]:
				if l[i][k[0]] != k[1]:
					c.append(False)
	if c == []:
		ans = max(ans, sum(l[i]))
print(ans)


import itertools
n = int(input())
la = []
for _ in range(n):
	d = int(input())
	for dd in range(d):
		(x, y) = map(int, input().split())
		la.append([_, x - 1, y])
ans = 0
for i in itertools.product([0, 1], repeat=n):
	s = sum(list(i))
	for l in la:
		if i[l[0]] == 1 and i[l[1]] != l[2]:
			break
	else:
		ans = max(ans, s)
print(ans)


n = int(input())
g = [[-1] * n for _ in range(n)]
for i in range(n):
	a = int(input())
	for _ in range(a):
		(x, y) = map(int, input().split())
		g[i][x - 1] = y
ans = 0
for m in range(2 ** n):
	f = 1
	for i in range(n):
		for j in range(n):
			if g[i][j] < 0:
				continue
			if 1 << i & m:
				if g[i][j] != int(1 << j & m > 0):
					f = 0
					break
	if f:
		ans = max(ans, bin(m).count('1'))
print(ans)


N = int(input())
X = []
for _ in range(N):
	a = int(input())
	X.append([[int(a) for a in input().split()] for __ in range(a)])

def chk(m):
	L = [m >> i & 1 for i in range(N)]
	for i in range(N):
		for (x, y) in X[i]:
			x -= 1
			if L[i] and L[x] != y:
				return 0
	return 1
ma = 0
for i in range(1 << N):
	if chk(i):
		ma = max(ma, bin(i).count('1'))
print(ma)


N = int(input())
L = [[-1] * N for _ in range(N)]
for i in range(N):
	A = int(input())
	for a in range(A):
		(x, y) = map(int, input().split())
		L[i][x - 1] = y
ans = 0
for b in range(2 ** N):
	ok = True
	for i in range(N):
		if b >> i & 1 == 1:
			l = L[i]
			for (j, x) in enumerate(l):
				if x != -1 and b >> j & 1 != x:
					ok = False
	if ok:
		ans = max(ans, bin(b).count('1'))
print(ans)


import sys, itertools as it
f = sys.stdin.readline
n = int(f())
ll = []
for i in range(n):
	a = int(f())
	for _ in range(a):
		(x, y) = map(int, f().split())
		ll += [(i, x - 1, y)]
c = 0
for p in it.product([0, 1], repeat=n):
	if all((p[i] < 1 or p[x] == y for (i, x, y) in ll)):
		c = max(c, sum(p))
print(c)


N = int(input())
A = []
xs = []
ys = []
X = []
Y = []
for i in range(N):
	a = int(input())
	A.append(a)
	for j in range(A[i]):
		(x, y) = map(int, input().split())
		xs.append(x)
		ys.append(y)
	X.append(xs)
	Y.append(ys)
	xs = []
	ys = []
B = []
ans = 0
count = 0
for i in range(2 ** N):
	B.append(format(i, 'b'))
for i in range(2 ** N):
	TF = ['0'] * N
	b = str(B[i])
	for j in range(len(b)):
		TF[-1 - j] = b[-1 - j]
	for j in range(N):
		if TF[j] == '1':
			for k in range(A[j]):
				if Y[j][k] == 1:
					if TF[X[j][k] - 1] == '1':
						continue
					else:
						count += 1
				if Y[j][k] == 0:
					if TF[X[j][k] - 1] == '0':
						continue
					else:
						count += 1
	if count <= 0:
		ans = max(ans, TF.count('1'))
	count = 0
print(ans)