AtCoder Beginner Contest 147 - HonestOrUnkind2

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

Starter code:

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)


ans = 0
shogen = []
n = int(input())
for _ in range(n):
	t = []
	a = int(input())
	for __ in range(a):
		h = list(map(int, input().split()))
		t.append(h)
	shogen.append(t)
for i in range(2 ** n):
	flag = True
	for j in range(n):
		if not flag:
			break
		if i >> j & 1:
			for h in shogen[j]:
				if i >> h[0] - 1 & 1 != h[1]:
					flag = False
	if flag:
		mnt = bin(i).count('1')
		ans = max(ans, mnt)
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())
a = []
x = []
y = []
for i in range(n):
	ai = int(input())
	a.append(ai)
	xi = []
	yi = []
	for j in range(ai):
		(xij, yij) = list(map(int, input().split(' ')))
		xi.append(xij)
		yi.append(yij)
	x.append(xi)
	y.append(yi)
ans = 0
for case in range(2 ** n):
	truth_t = 0
	truth = 0
	for i in range(n):
		if case >> i & 1:
			truth_t += 1
			proof = 0
			for j in range(a[i]):
				if case >> x[i][j] - 1 & 1 == y[i][j]:
					proof += 1
			if proof == a[i]:
				truth += 1
	if truth == truth_t:
		if ans < truth:
			ans = truth
print(ans)


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)


from itertools import combinations
n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
for i in r:
	for _ in range(int(input())):
		(x, y) = map(int, input().split())
		a[i][y].add(x - 1)
fail = lambda x: not all((a[i][1] < x and a[i][0].isdisjoint(x) for i in x))
while all(map(fail, map(set, combinations(r, n)))):
	n -= 1
print(n)


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)


N = int(input())
say = []
for _ in range(N):
	A = int(input())
	t = []
	for __ in range(A):
		s = list(map(int, input().split()))
		t.append(s)
	say.append(t)
ans = 0
for i in range(2 ** N):
	flag = True
	for j in range(N):
		if not flag:
			break
		if i >> j & 1:
			for s in say[j]:
				if i >> s[0] - 1 & 1 != s[1]:
					flag = False
	if flag:
		mount = bin(i).count('1')
		ans = max(ans, mount)
print(ans)


n = int(input())
a = []
d = []
for i in range(n):
	c = []
	b = int(input())
	d.append(b)
	for j in range(b):
		c.append(list(map(int, input().split())))
	a.append(c)
count = 0
for i in range(2 ** n):
	x = [0] * n
	pre = 0
	for j in range(n):
		if i >> j & 1:
			x[n - 1 - j] = 1
			for l in range(d[j]):
				if i >> a[j][l][0] - 1 & 1 != a[j][l][1]:
					pre += 1
	if pre != 0:
		count = count
	else:
		count = max(count, x.count(1))
print(count)


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


N = int(input())
xy = [[] for i in range(N)]
for i in range(N):
	A = int(input())
	for j in range(A):
		(x, y) = map(int, input().split())
		xy[i].append([x, y])
ans = 0
for i in range(2 ** N):
	b = format(i, '0' + str(N) + 'b')
	t = 0
	f = 0
	for j in range(N):
		if b[j] == '1':
			t += 1
			for k in xy[j]:
				if str(k[1]) != b[k[0] - 1]:
					f = 1
					break
	if f == 0:
		ans = max(ans, t)
print(ans)


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


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


n = int(input())

class People:

	def __init__(self):
		self.type = None
peoples = [People() for i in range(n + 1)]

def change_10to2(i):
	ans = format(i, '#0' + str(n + 3) + 'b')[2:]
	return ans

def set_people_type(binary_list, peoples):
	for (i, people) in enumerate(peoples):
		if i != 0:
			people.type = binary_list[i]

def get_statement():
	shougen = {}
	for i in range(1, n + 1):
		ai = int(input())
		ans = []
		for j in range(ai):
			kumi = [int(k) for k in input().split()]
			ans.append(kumi)
		shougen[str(i)] = ans
	return shougen
shougens = get_statement()

def shougen_dicide(peoples, shougens):
	for i in range(1, n + 1):
		shougen = shougens[str(i)]
		for shou in shougen:
			(people, type) = shou
			people = int(people)
			type = str(type)
			if peoples[i].type == '1':
				if peoples[people].type != type:
					return False
	return True
ans = 0
for i in range(2 ** n):
	binary_list = change_10to2(i)
	set_people_type(binary_list, peoples)
	if shougen_dicide(peoples, shougens):
		ans = max(ans, binary_list.count('1'))
print(ans)


N = int(input())
xy = [[] for i in range(N)]
for i in range(N):
	for j in range(int(input())):
		(x, y) = map(int, input().split())
		xy[i].append([x - 1, y])
m = 0
for i in range(2 ** N):
	f = True
	for j in range(N):
		if i >> j & 1 == 0:
			continue
		for k in xy[j]:
			if i >> k[0] & 1 != k[1]:
				f = False
				break
		if f == False:
			break
	if f == True:
		c = 0
		while i > 0:
			c += i & 1
			i >>= 1
		m = max(m, c)
print(m)


N = int(input())
shougen = [[] for _ in range(N)]
for k in range(N):
	A = int(input())
	for j in range(A):
		(x, y) = list(map(int, input().split()))
		x -= 1
		shougen[k].append((x, y))
ans = 0
bit = 2 ** N - 1
while bit:
	person = [-1 for _ in range(N)]
	b = bit
	count = 0
	while count < N:
		person[count] = b & 1
		b >>= 1
		count += 1
	flag = True
	for k in range(N):
		if person[k] == 1:
			for (x, y) in shougen[k]:
				if person[x] != y:
					flag = False
					break
			else:
				continue
			break
	if flag:
		ans = max(ans, sum(person))
	bit -= 1
print(ans)


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


import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):

	def assertIO(self, input, output):
		(stdout, stdin) = (sys.stdout, sys.stdin)
		(sys.stdout, sys.stdin) = (StringIO(), StringIO(input))
		resolve()
		sys.stdout.seek(0)
		out = sys.stdout.read()[:-1]
		(sys.stdout, sys.stdin) = (stdout, stdin)
		self.assertEqual(out, output)

	def test_入力例_1(self):
		input = '3\n1\n2 1\n1\n1 1\n1\n2 0'
		output = '2'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '3\n2\n2 1\n3 0\n2\n3 1\n1 0\n2\n1 1\n2 0'
		output = '0'
		self.assertIO(input, output)

	def test_入力例_3(self):
		input = '2\n1\n2 0\n1\n1 0'
		output = '1'
		self.assertIO(input, output)

def resolve():
	N = int(input())
	C = []
	for i in range(N):
		a = int(input())
		C.append([list(map(int, input().split())) for j in range(a)])
	ans = 0
	for bit in range(1 << N):
		t = 0
		for i in range(N):
			if bit & 1 << i:
				for c in C[i]:
					if bit & 1 << c[0] - 1 != (1 << c[0] - 1) * c[1]:
						break
				else:
					t += 1
		if t == bin(bit).count('1'):
			ans = max(ans, t)
	print(ans)

def __starting_point():
	resolve()
__starting_point()


n = int(input())
x = [] * n
y = [] * n
for i in range(n):
	A = [] * n
	B = [] * n
	for j in range(int(input())):
		(a, b) = map(int, input().split())
		(A.append(a - 1), B.append(b))
	x.append(A)
	y.append(B)
ans = 0
for bit in range(2 ** n):
	T = [bit >> i & 1 for i in range(n)]
	cnt = 0
	f = 1
	for i in range(n):
		if bit >> i & 1:
			cnt += 1
			for p in range(len(x[i])):
				if T[x[i][p]] != y[i][p]:
					f = 0
					break
	if f > 0:
		ans = max(ans, cnt)
print(ans)


def HonestOrUnkind2():
	n = int(input())
	lang = [[-1] * n for _ in range(n)]
	ans = 0
	for i in range(n):
		a = int(input())
		for _ in range(a):
			(x, y) = list(map(int, input().split()))
			lang[i][x - 1] = y
	for i in range(2 ** n):
		status = [0 for _ in range(n)]
		for j in range(n):
			if i >> j & 1:
				status[j] = 1
		ans0 = True
		for j in range(n):
			if status[j] == 1:
				for k in range(n):
					if lang[j][k] == -1:
						continue
					if lang[j][k] != status[k]:
						ans0 = False
		if ans0:
			ans = max(ans, status.count(1))
	print(ans)

def __starting_point():
	HonestOrUnkind2()
__starting_point()


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


N = int(input())
XY = [[list(map(int, input().split())) for _ in range(int(input()))] for _ in range(N)]
res = 0
for k in range(1 << N):
	bits = [k >> i & 1 for i in range(N)]
	flag = True
	for i in range(N):
		if k >> i & 1 == 0:
			continue
		for (x, y) in XY[i]:
			if bits[x - 1] == y:
				continue
			flag = False
	if flag:
		res = max(res, sum(bits))
print(res)


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


def cnt_honest(bit):
	for i in range(n):
		if bit[i] == '1':
			for (x, y) in hf[i]:
				if bit[x - 1] != str(y):
					return 0
	return bit.count('1')
n = int(input())
hf = [[] for i in range(n)]
for i in range(n):
	for j in range(int(input())):
		hf[i].append(list(map(int, input().split())))
ans = 0
for i in range(2 ** n):
	ans = max(ans, cnt_honest(format(i, 'b').zfill(n)))
print(ans)


N = int(input())
evidence = [[] for _ in range(N)]
for i in range(N):
	a = int(input())
	for _ in range(a):
		(x, y) = map(int, input().split())
		evidence[i].append([x - 1, y])
ans = 0
for i in range(2 ** N):
	flag = 0
	for j in range(N):
		if i >> j & 1:
			for (x, y) in evidence[j]:
				if i >> x & 1 != y:
					flag = 1
					break
	if flag == 0:
		ans = max(ans, bin(i)[2:].count('1'))
print(ans)


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


def resolve():
	N = int(input())
	evdi = [[] for _ in range(N)]
	for i in range(N):
		cnt = int(input())
		for _ in range(cnt):
			(x, y) = list(map(int, input().split()))
			x -= 1
			evdi[i].append((x, y))
	ans = 0
	for bit in range(1 << N):
		ok = True
		for i in range(N):
			if bit >> i & 1:
				for (x, y) in evdi[i]:
					if y == 1 and (not bit >> x & 1):
						ok = False
						break
					if y == 0 and bit >> x & 1:
						ok = False
						break
		cnt = bin(bit).count('1')
		if ok:
			ans = max(cnt, ans)
	print(ans)

def __starting_point():
	resolve()
__starting_point()


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


n = int(input())
m = []
a = [[] for i in range(n)]
for i in range(n):
	tmp = int(input())
	m.append(tmp)
	for j in range(tmp):
		a[i].append(list(map(int, input().split())))
ans = 0
for i in range(2 ** n):
	cnt = 0
	for j in range(n):
		flg = True
		if i >> j & 1:
			cnt += 1
			for k in range(m[j]):
				kj = i >> a[j][k][0] - 1 & 1
				if a[j][k][1] != kj:
					flg = False
					break
			if not flg:
				break
	if flg:
		ans = max(ans, cnt)
print(ans)


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:]
	z = [int(i) for i in x[-n:]]
	f = 1
	for (p, q) in enumerate(w):
		if z[p] == 1:
			for r in q:
				if z[r[0] - 1] != r[1]:
					f = 0
	if f:
		ans = max(ans, z.count(1))
print(ans)


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


n = int(input())
xy = [[] for i in range(n)]
for i in range(n):
	a = int(input())
	for j in range(a):
		(x, y) = map(int, input().split())
		xy[i].append((x, y))
ans = 0
for i in range(2 ** n):
	isOk = True
	res = []
	cnt = 0
	for j in range(n):
		x = i >> j & 1
		res.append(x)
	for j in range(n):
		x = i >> j & 1
		if x:
			cnt += 1
			for v in xy[j]:
				(x, y) = v
				x -= 1
				if res[x] != y:
					isOk = False
	if isOk:
		ans = max(ans, cnt)
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())
info = {}
for p in range(n):
	a = int(input())
	L = []
	for _ in range(a):
		(x, y) = list(map(int, input().split()))
		(x, y) = (x - 1, y)
		L.append((x, y))
	info[p] = L
ans = 0
for bit_pattern in product(range(2), repeat=n):
	for (p, bit) in enumerate(bit_pattern):
		if bit:
			if not all([bit_pattern[x] == y for (x, y) in info[p]]):
				break
	else:
		ans = max(ans, sum(bit_pattern))
print(ans)


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)


import sys
n = int(input())
lst = []
for _ in range(n):
	a = int(sys.stdin.readline())
	lst.append([[int(i) for i in sys.stdin.readline().split()] for _ in range(a)])
m = 0
for i in range(2 ** n):
	a = True
	d = 0
	for j in range(n):
		if i >> j & 1:
			d += 1
			for (x, y) in lst[j]:
				if i >> x - 1 & 1 != y:
					a = False
					break
	if a:
		m = max(m, d)
print(m)


n = int(input())
arr = []
for _ in range(n):
	k = int(input())
	tmp = [list(map(int, input().split())) for _ in range(k)]
	arr.append(tmp)
ans = 0
for i in range(2 ** n):
	tmp = format(i, 'b')
	if len(tmp) < n:
		tmp = '0' * (n - len(tmp)) + tmp
	flag = True
	for i in range(n):
		c = int(tmp[i])
		if c == 0:
			continue
		for (a, b) in arr[i]:
			if int(tmp[a - 1]) != b:
				flag = False
				break
	if flag == True:
		ans = max(ans, tmp.count('1'))
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)


N = int(input())
hatsugen = [[] for _ in range(N)]
A = -1
while True:
	try:
		s = input()
	except EOFError:
		break
	a = tuple(map(int, s.rstrip().split()))
	if len(a) == 1:
		A += 1
	else:
		hatsugen[A].append(a)
ans = 0
for i in range(2 ** N):
	bit = i
	flag = [0] * N
	idx = 0
	while bit:
		if bit & 1:
			flag[idx] = 1
		bit >>= 1
		idx += 1
	flag2 = 0
	for i in range(N):
		if flag[i]:
			hatsu = hatsugen[i]
		else:
			continue
		for word in hatsu:
			if flag[word[0] - 1] != word[1]:
				flag2 = 1
				break
		if flag2:
			break
	if flag2 == 0:
		ans = max(ans, sum(flag))
print(ans)


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)


from itertools import product
N = int(input())
XYs = []
for i in range(N):
	A = int(input())
	XYs.append([tuple(map(int, input().split())) for _ in range(A)])
n = 0
for ts in product([1, 0], repeat=N):
	for (i, t) in enumerate(ts):
		if t:
			if not all((ts[x - 1] == y for (x, y) in XYs[i])):
				break
	else:
		n = max(n, sum(ts))
print(n)


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


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)


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


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


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)


from itertools import *
I = input
n = int(I())
c = 0
z = []
for i in range(n):
	for j in range(int(I())):
		z += [[i] + list(map(int, I().split()))]
for j in product([0, 1], repeat=n):
	if all((j[i] == 0 or j[x - 1] - y == 0 for (i, x, y) in z)):
		c = max(c, sum(j))
print(c)


i = input
n = int(i())
a = eval('[i().split()for _ in"_"*int(i())],' * n)
print(max((all((int(y) == i >> int(x) - 1 & 1 for (j, t) in enumerate(a) if i >> j & 1 for (x, y) in t)) * bin(i).count('1') for i in range(2 ** n))))


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)


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

def exists(state):
	ret = 0
	for i in range(N):
		if 1 << i & state == 0:
			continue
		ret += 1
		for (x, y) in A[i]:
			if (state & 1 << x - 1 > 0) != (y > 0):
				return 0
	return ret
ans = 0
for state in range(1 << N):
	ans = max(ans, exists(state))
print(ans)


N = int(input())
T = []
for i in range(N):
	A = int(input())
	for j in range(A):
		(x, y) = map(int, input().split())
		T.append([i, x - 1, y == 1])
ans = 0
for i in range(1 << N):
	h = []
	for j in range(N):
		if i & 1 << j:
			h.append(j)
	for (j, x, y) in T:
		if j in h:
			if not (x in h) == y:
				break
	else:
		ans = max(ans, len(h))
print(ans)


from itertools import combinations, count
n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
for i in r:
	for _ in range(int(input())):
		(x, y) = map(int, input().split())
		a[i][y].add(x - 1)
r = next((i for i in count(n, -1) for x in combinations(r, i) if all((a[j][0].isdisjoint(x) and a[j][1].issubset(x) for j in x))))
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 i in range(n):
	a = int(input())
	l.append([tuple(map(int, input().split())) for _ in range(a)])
cnt = 0
for i in range(1 << n):
	Flag = True
	for j in range(n):
		if i >> j & 1:
			for (x, y) in l[j]:
				if i >> x - 1 & 1 != y:
					Flag = False
					break
	if Flag:
		cnt = max(cnt, sum(map(int, bin(i)[2:])))
print(cnt)


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


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())
testimonies = []
for i in range(N):
	A = int(input())
	testimony = []
	for j in range(A):
		testimony.append(list(map(int, input().split())))
		testimony[-1][0] -= 1
	testimonies.append(testimony)
ans = 0
for i in range(2 ** N):
	isContradiction = False
	for j in range(N):
		if not i & 1 << j:
			continue
		for (x, y) in testimonies[j]:
			if i & 1 << x:
				x = 1
			else:
				x = 0
			if not x == y:
				isContradiction = True
				break
	if not isContradiction:
		ans = max(ans, bin(i).count('1'))
print(ans)


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())
X = []
Y = []
for _ in range(N):
	a = int(input())
	tmp = []
	for _ in range(a):
		tmp.append(list(map(int, input().split())))
	X.append(a)
	Y.append(tmp)
ans = 0
for bit in range(2 ** N):
	flag = True
	for i in range(N):
		if bit >> i & 1:
			for (x, y) in Y[i]:
				flag &= bit >> x - 1 & 1 == y
	if flag:
		ans = max(ans, bin(bit).count('1'))
print(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())
xys = [[tuple(map(int, input().split())) for j in range(int(input()))] for i in range(n)]
C = set()
for i in range(2 ** n):
	flag = True
	for j in range(n):
		if i >> j & 1:
			flag &= all((i >> x - 1 & 1 == y for (x, y) in xys[j]))
	if flag:
		C.add(i)
print(max([sum([int(bit == '1') for bit in str(bin(c))]) for c in C]))


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())
g = [[0, 0] for _ in range(n)]
for i in range(n):
	a = int(input())
	for _ in range(a):
		(x, y) = map(int, input().split())
		g[i][y] |= 1 << x - 1
ans = 0
for num in range(1 << n):
	p = [g[j] for j in range(n) if num & 1 << j]
	fl = 0
	if all((num & y == y and (not num & x) for (x, y) in p)):
		if ans < len(p):
			ans = len(p)
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())
p = [[] for _ in range(n)]
for i in range(n):
	a = int(input())
	for j in range(a):
		p[i].append(list(map(int, input().split())))
ans = 0
for i in range(2 ** n):
	a = [i >> j & 1 for j in range(n - 1, -1, -1)]
	flag = 1
	for k in range(n):
		if a[k] * flag == 1:
			for l in p[k]:
				if a[l[0] - 1] != l[1]:
					flag = 0
	ans = max(ans, flag * sum(a))
print(ans)


from itertools import product
N = int(input())
memo = []
for i in range(N):
	a = int(input())
	l = []
	for _ in range(a):
		(x, y) = map(int, input().split())
		l.append((x - 1, y == 1))
	memo.append(l)

def check(p):
	return all((p[x] == y for (i, l) in enumerate(memo) for (x, y) in l if p[i]))
m = max((sum(p) for p in product((True, False), repeat=N) if check(p)))
print(m)


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


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


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())
X = [0] * N
for i in range(N):
	X[i] = [list(map(int, input().split())) for _ in range(int(input()))]
print(max(['{:03b}'.format(i).count('1') for i in range(2 ** N) if all([i >> j & 1 and all([y[1] == i >> y[0] - 1 & 1 for y in X[j]]) for j in range(N) if i >> j & 1])]))


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())
lst = []
ans = 0
for i in range(n):
	a = int(input())
	lst.append([list(map(int, input().split())) for _ in range(a)])
for k in range(2 ** n):
	target = bin(k)[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 lst[i])):
				break
			else:
				nk += 1
	else:
		ans = max(ans, nk)
print(ans)


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())
a = []
h = []
for _ in range(n):
	x = int(input())
	h.append([tuple(map(int, input().split())) for _ in range(x)])
	a.append(x)
ans = 0
for i in range(2 ** n):
	f = 1
	for j in range(n):
		if i >> j & 1:
			for k in range(a[j]):
				(x, y) = h[j][k]
				if i >> x - 1 & 1 != y:
					f = 0
	if f:
		c = 0
		for j in range(n):
			c += i >> j & 1
		ans = max(ans, c)
print(ans)


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


import itertools
N = int(input())
A = []
for i in range(N):
	a = []
	B = int(input())
	for _ in range(B):
		(x, y) = map(int, input().split())
		a.append([x, y])
	A.append(a)
ans = 0
for i in list(itertools.product(range(2), repeat=N)):
	for j in range(len(A)):
		flag = True
		if i[j] == 0:
			continue
		for (x, y) in A[j]:
			if i[x - 1] != y:
				flag = False
				break
		if not flag:
			break
	if flag:
		ans = max(ans, sum(i))
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):
	b = 1
	for (i, x, y) in ll:
		if p >> i & 1 and p >> x & 1 != y:
			b = 0
			break
	if b:
		c = max(c, sum((p >> i & 1 for i in range(n))))
print(c)


n = int(input())
A = [{} for _ in range(n)]
for i in range(n):
	for _ in range(int(input())):
		(x, y) = map(int, input().split())
		A[i][x] = y
a = 0
for i in range(2 ** n):
	t = 0
	for j in range(n):
		if i >> j & 1:
			if A[j] and any((i >> ~-k & 1 != A[j][k] for k in A[j])):
				break
			else:
				t += 1
	else:
		a = max(a, t)
print(a)


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


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)


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

def is_honest(i, j):
	return (i >> j) % 2 == 1

def honest_cnt(i):
	ans = 0
	for j in range(n):
		ans += is_honest(i, j)
	return ans
ans = 0
for i in range(1 << n):
	ok = True
	for j in range(n):
		if not is_honest(i, j):
			continue
		for (x, y) in Dup[j]:
			if y == 0 and is_honest(i, x):
				ok = False
			if y == 1 and (not is_honest(i, x)):
				ok = False
	if ok:
		ans = max(ans, honest_cnt(i))
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()


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


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)


n = int(input())
a = []
for _ in range(n):
	m = int(input())
	a.append([list(map(int, input().split())) for _ in range(m)])
c = 0
for i in range(1 << n):
	Flag = True
	for j in range(n):
		if i >> j & 1 == 1:
			for k in a[j]:
				if i >> k[0] - 1 & 1 != k[1]:
					Flag = False
		if Flag == False:
			break
	else:
		honest = sum([i >> j & 1 for j in range(n)])
		c = max(c, honest)
print(c)


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())
XY = []
for i in range(N):
	A = int(input())
	XY.append([list(map(int, input().split())) for _ in range(A)])
ans = 0
for bit in range(1 << N):
	honest_cnt = 0
	flag = True
	for i in range(N):
		if bit >> i & 1 == 0:
			continue
		honest_cnt += 1
		for (x, y) in XY[i]:
			if bit >> x - 1 & 1 != y:
				flag = False
				break
	if flag:
		ans = max(ans, honest_cnt)
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())
XY = [[] for _ in range(N)]
for i in range(N):
	A = int(input())
	for _ in range(A):
		(x, y) = map(int, input().split())
		x -= 1
		XY[i].append([x, y])
ans = 0
for bit_state in range(2 ** N):
	flag = True
	for i in range(N):
		if bit_state >> i & 1:
			for (x, y) in XY[i]:
				if bit_state >> x & 1 != y:
					flag = False
	if flag:
		ans = max(ans, bin(bit_state).count('1'))
print(ans)


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

def test(i):
	T = []
	F = []
	TT = set()
	TF = set()
	for n in range(N):
		if 1 & i >> n:
			T += A[n][1]
			F += A[n][0]
			TT.add(n + 1)
		else:
			TF.add(n + 1)
	if set(T) <= TT and set(F) <= TF:
		return len(TT)
	else:
		return -1
s = 0
for i in range(2 ** N):
	s = max(s, test(i))
print(s)


N = int(input())
A = []
data = []
for i in range(N):
	a = int(input())
	A.append(a)
	x = [list(map(int, input().split())) for _ in range(a)]
	data.append(x)
ans = 0
for i in range(1 << N):
	bit = [0] * N
	cnt = 0
	for j in range(N):
		div = 1 << j
		bit[j] = i // div % 2
		if bit[j] == 1:
			cnt += 1
	flag = True
	for j in range(N):
		if bit[j] == 0:
			continue
		for a in range(A[j]):
			x = data[j][a]
			if bit[x[0] - 1] != x[1]:
				flag = False
				break
		if not flag:
			break
	if flag:
		ans = max(ans, cnt)
print(ans)


n = int(input())
a = []
x = []
y = []
for i in range(n):
	z = int(input())
	a.append(z)
	for j in range(z):
		(s, r) = map(int, input().split())
		x.append(s)
		y.append(r)
ans = 0
for i in range(2 ** n):
	t = [0] * n
	j = 0
	k = 0
	z = i
	while z > 0:
		if z % 2 != 0:
			t[j] = 1
			k += 1
		j += 1
		z = z // 2
	flg = True
	j = 0
	z = 0
	p = 0
	while j < n:
		if t[j] == 1:
			for q in range(a[z]):
				if t[x[p + q] - 1] != y[p + q]:
					flg = False
		p += a[z]
		j += 1
		z += 1
	if flg:
		ans = max(ans, k)
print(ans)


N = int(input())
A = [0 for n in range(N)]
XY = [0 for n in range(N)]
count_max = 0
for i in range(N):
	A[i] = int(input())
	xy = []
	for j in range(A[i]):
		x_y = list(map(int, input().split()))
		xy.append(x_y)
	XY[i] = xy
for i in range(2 ** N):
	op = [0] * N
	for j in range(N):
		if i >> j & 1:
			op[N - 1 - j] = 1
	flag = True
	for k in range(len(op)):
		if op[k] == 1:
			for l in range(A[k]):
				if XY[k][l][1] != op[XY[k][l][0] - 1]:
					flag = False
	if flag:
		if sum(op) > count_max:
			count_max = sum(op)
print(count_max)


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())
a = [[] for _ in range(n)]
for i in range(n):
	num = int(input())
	for j in range(num):
		(person, state) = map(int, input().split())
		a[i].append([person - 1, state])
honest = 0
for i in range(1, 2 ** n):
	flag = True
	for j in range(n):
		if i >> j & 1 == 1:
			for (x, y) in a[j]:
				if i >> x & 1 != y:
					flag = False
					break
	if flag:
		honest = max(honest, bin(i)[2:].count('1'))
print(honest)


def popcount(x):
	r = 0
	while x:
		r += 1
		x &= x - 1
	return r
n = int(input())
r = range(n)
a = [[0, 0] for _ in r]
for i in r:
	for _ in range(int(input())):
		(x, y) = map(int, input().split())
		a[i][y] |= 1 << x - 1
m = 0
l = (1 << n) - 1
for x in range(1, l + 1):
	if all((a[i][0] & x == a[i][1] & l - x == 0 for i in r if x >> i & 1)):
		m = max(m, popcount(x))
print(m)


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())
l = []
for _ in range(n):
	a = int(input())
	m = []
	for _ in range(a):
		(xn, yn) = map(int, input().split())
		m.append([xn - 1, yn])
	l.append(m)
for i in itertools.product([1, 0], repeat=n):
	i = list(i)
	flg = 0
	for j in range(n):
		for k in l[j]:
			if i[j] == 1:
				if i[k[0]] != k[1]:
					flg += 1
					break
	if flg == 0:
		break
print(sum(i))


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())
say = []
for i in range(n):
	qq = []
	for i in range(int(input())):
		qq.append(list(map(int, input().split())))
	say.append(qq)
ans = 0
for bit in range(1 << n):
	plate = 0
	L = [bit >> i & 1 for i in range(n)]
	for i in range(n):
		if L[i] == 0:
			continue
		for l in say[i]:
			if L[l[0] - 1] != l[1]:
				plate = 1
				break
		if plate:
			break
	else:
		ans = max(ans, sum(L))
print(ans)


from itertools import product
n = int(input())
Ev = [[] for _ in range(n)]
for i in range(n):
	A = int(input())
	for a in range(A):
		(x, y) = map(int, input().split())
		Ev[i].append((x - 1, y))
bit = list(product([1, 0], repeat=n))
ans = 0
for b in bit:
	for (i, v) in enumerate(b):
		if v == 1:
			for (x, y) in Ev[i]:
				if b[x] != y:
					break
			else:
				continue
			break
	else:
		ans = max(b.count(1), ans)
print(ans)


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 = []
for _ in range(n):
	a = int(input())
	xy.append([list(map(int, input().split())) for _ in range(a)])
ans = 0
for i in range(2 ** n):
	pat = []
	for j in range(n):
		pat.append((i >> j) % 2)
	check = True
	for j in range(n):
		if pat[j]:
			for z in xy[j]:
				if pat[z[0] - 1] != z[1]:
					check = False
	if check:
		ans = max(ans, sum(pat))
print(ans)


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)


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)


N = int(input())
A = [0] * N
XY = [0] * N
for i in range(N):
	A[i] = int(input())
	XY[i] = [list(map(int, input().split())) for _ in range(A[i])]
count = lambda x: sum([x >> i & 1 for i in range(15)])
ans = 0
for i in range(1 << N):
	ok = True
	for j in range(N):
		if i >> j & 1 == 0:
			continue
		for k in range(A[j]):
			if i >> XY[j][k][0] - 1 & 1 ^ XY[j][k][1]:
				ok = False
				break
	ans = max(ans, count(i)) if ok else ans
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())
X = [] * n
A = [] * n
for i in range(n):
	a = int(input())
	A.append(a)
	xy = [list(map(int, input().split())) for _ in range(a)]
	X.append(xy)
ans = 0
for i in range(2 ** n):
	cnt = 0
	for j in range(n):
		if i >> j & 1:
			for (k, l) in X[j]:
				if not i >> k - 1 & 1 == l:
					cnt = 1
	if cnt == 0:
		ans = max(ans, bin(i).count('1'))
print(ans)


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())
xy = [[list(map(int, input().split())) for _ in range(int(input()))] for _ in range(n)]
ans = 0
for i in range(2 ** n):
	flag = True
	for j in range(n):
		if i >> j & 1:
			for (x, y) in xy[j]:
				if i >> x - 1 & 1 != y:
					flag = False
					break
	if flag == True:
		ans = max(ans, bin(i)[2:].count('1'))
print(ans)


n = int(input())
(al, xyl) = ([], [])
for _ in range(n):
	a = int(input())
	xy = [list(map(int, input().split())) for _ in range(a)]
	xyl.append(xy)
ans = 0
for i in range(2 ** n):
	cnt = 0
	flag = True
	for j in range(n):
		if i >> j & 1:
			cnt += 1
			for (x, y) in xyl[j]:
				x -= 1
				if i >> x & 1 != y:
					flag = False
	if flag:
		ans = max(ans, cnt)
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())
xys = []
for i in range(n):
	a = int(input())
	xys.append([list(map(int, input().split())) for _ in range(a)])
ret = 0
for b in range(1 << n):
	ok = True
	c = 0
	for i in range(n):
		if b >> i & 1 != 0:
			c += 1
			for (x, y) in xys[i]:
				if y != b >> x - 1 & 1:
					ok = False
	if ok:
		ret = max(ret, c)
print(ret)


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)


from itertools import product
N = int(input())
datas = []
for i in range(N):
	A = int(input())
	for j in range(A):
		(x, y) = map(int, input().split())
		datas.append((i, x - 1, y))
ans = 0
for i in product([0, 1], repeat=N):
	ok = True
	for j in datas:
		if i[j[0]] == 1 and i[j[1]] != j[2]:
			ok = False
			break
	if ok:
		ans = sum(i)
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())
ls1 = []
for i in range(N):
	A = int(input())
	ls2 = []
	for i in range(A):
		(x, y) = map(int, input().split())
		ls2.append([x, y])
	ls1.append(ls2)
ans = 0
f = True
for i in range(2 ** N):
	for j in range(N):
		if i >> j & 1:
			f = True
			for k in ls1[j]:
				if i >> k[0] - 1 & 1 == k[1] & 1:
					continue
				else:
					f = False
					break
			if f == False:
				break
	if f:
		ans = max(ans, bin(i).count('1'))
print(ans)


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 combinations
n = int(input())
l = (1 << n) - 1
r = range(n)
a = [[0, 0] for _ in r]
for i in r:
	for _ in range(int(input())):
		(x, y) = map(int, input().split())
		a[i][y] |= 1 << x - 1

def fail(x):
	x = sum((1 << i for i in x))
	return not all((a[i][0] & x == a[i][1] & l - x == 0 for i in r if x >> i & 1))
while all(map(fail, combinations(r, n))):
	n -= 1
print(n)


def digitSum(n):
	s = str(bin(n))
	s = s[2:]
	array = list(map(int, s))
	return sum(array)
N = int(input())
A = []
X = []
Y = []
res = 0
for i in range(N):
	a = int(input())
	A.append(a)
	X_temp = []
	Y_temp = []
	for j in range(a):
		(x, y) = map(int, input().split())
		X_temp.append(x)
		Y_temp.append(y)
	X.append(X_temp)
	Y.append(Y_temp)
for i in range(1 << N):
	judge = True
	for j in range(N):
		if i >> j & 1:
			for k in range(A[j]):
				if i >> X[j][k] - 1 & 1 != Y[j][k]:
					judge = False
	if judge:
		res = max(res, digitSum(i))
print(res)


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)


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)


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)


from itertools import product
n = int(input())
tells = [[] for _ in range(n)]
for i in range(n):
	for j in range(int(input())):
		tells[i].append(list(map(int, input().split())))
for i in product(['1', '0'], repeat=n):
	a = list(map(int, i))
	flag = True
	for j in range(n):
		for k in tells[j]:
			if a[j] and a[k[0] - 1] != k[1]:
				flag = False
				break
	if flag:
		print(sum(a))
		break


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())
s = [[] for i in range(n)]
for i in range(n):
	a = int(input())
	for j in range(a):
		s[i].append(list(map(int, input().split())))
for i in range(2 ** n)[::-1]:
	cnt = format(i, 'b').zfill(n)
	flag = 0
	for j in range(n):
		if cnt[j] == '0':
			continue
		else:
			for h in s[j]:
				if int(cnt[h[0] - 1]) ^ h[1] == 1:
					flag = 1
					break
			if flag:
				break
	if flag == 0:
		print(cnt.count('1'))
		exit()


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)


N = int(input())
L = []
for _ in range(N):
	n = int(input())
	t = [list(map(int, input().split())) for _ in range(n)]
	L.append(t)
ans = 0
for i in range(1 << N):
	for p in range(N):
		f = i >> p & 1 == 1
		if not all([not f or (f and i >> t[0] - 1 & 1 == t[1]) for t in L[p]]):
			break
	else:
		ans = max(ans, str(bin(i)).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())
xy = []
for _ in range(n):
	a = int(input())
	xy.append([[int(i) for i in input().split()] for __ in range(a)])
ans = 0
for i in range(2 ** n):
	flag = True
	for j in range(n):
		if i >> j & 1:
			for (x, y) in xy[j]:
				if i >> x - 1 & 1 != y:
					flag = False
					break
	if flag:
		ans = max(ans, sum(map(int, bin(i)[2:])))
print(ans)


def popcount(x):
	(r, q) = (0, x)
	while x:
		r += 1
		x &= x - 1
	return (r, q)
n = int(input())
r = range(n)
a = [[0, 0] for _ in r]
for i in r:
	for _ in range(int(input())):
		(x, y) = map(int, input().split())
		a[i][y] |= 1 << x - 1
l = (1 << n) - 1
b = sorted(map(popcount, range(1, l + 1)))
ans = next((i for (i, x) in reversed(b) if all((a[j][0] & x == a[j][1] & l - x == 0 for j in r if x >> j & 1))), 0)
print(ans)


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)