CodeEff/ECCO huggingface dataset:
# Original solution
import sys
input = sys.stdin.readline
from operator import eq, ne

def readlines(n):
    for _ in range(n):
        x, y = input().split()
        yield int(x)-1, y

def main():
    n = int(eval(input()))
    graph = []

    for _ in range(n):
        a = int(eval(input()))
        graph.append(list(readlines(a)))

    def check(bits):
        for pre_honest, asserts in zip(bits, graph):
            if pre_honest == "0":
                continue
            for x, y in asserts:
                if bits[x] != y:
                    return -1
        
        return len([b for b in bits if b == "1"])

    for i in range(2**n-1, -1, -1):
        bit = format(i, "0{}b".format(n))
        ans = check(bit)
        if ans > -1:
            print(ans)
            return
    
    print((0))

main()


# Optimized solution
import sys
input = sys.stdin.readline
from itertools import combinations
from operator import contains

def readlines(n):
    for _ in range(n):
        x, y = input().split()
        yield int(x)-1, y=="1"

def main():
    n = int(eval(input()))
    asserts = []

    for _ in range(n):
        a = int(eval(input()))
        asserts.append(list(readlines(a)))

    def check(comb):
        for i in comb:
            for x, y in asserts[i]:
                mujun = contains if not y else lambda a, b: b not in a
                if mujun(comb, x):
                    return -1
        
        return len(comb)

    for i in range(n+1):
        for comb in combinations(list(range(n)), i):
            yield check(set(comb))

    yield 0

print((max(main())))
# Original solution
n = int(eval(input()))

e = [[] for _ in range(n)]

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

ret = 0
for mask in range(1 << n):
    t = [(mask >> i) & 1 for i in range(n)]
    flg = True
    for i in range(n):
        if t[i]:
            for x, y in e[i]:
                if t[x] != y:
                    flg = False
                    break
            if not flg:
                break
    if flg:
        ret = max(ret, sum(t))

print(ret)

# Optimized solution
def main():
    from itertools import product

    N = int(eval(input()))

    g = []
    for _ in range(N):
        a = int(eval(input()))
        t = []
        for _ in range(a):
            x, y = list(map(int, input().split()))
            x -= 1
            t.append((x, y))
        g.append(t)

    def is_ok(prd):
        for j, bl in enumerate(prd):
            if bl:
                for x, y in g[j]:
                    if prd[x] != y:
                        return False
        return True

    ans = 0
    for prd in product([0, 1], repeat=N):
        *prd, = prd  # list化
        if is_ok(prd):
            ans = max(ans, prd.count(1))
    print(ans)


if __name__ == '__main__':
    main()

# bit演算しようとしてはまった
# Original solution
n = int(eval(input()))
x = []
for i in range(n):
    ai = int(eval(input()))
    xi = []
    for j in range(ai):
        xi.append(list(map(int, input().split())))
    x.append(xi)

m = 0
for h in range(2**n - 1, -1, -1):
    is_break = False
    h = bin(h)[2:].zfill(n)
    for i, xi in enumerate(x):
        if h[i] == '0':
            continue
        for xij, yij in xi:
            if (int(h[xij - 1]) != yij):
                is_break = True
                break
        if is_break:
            break
    else:
        m = max(sum(map(int, list(h))), m)

print(m)

# Optimized solution
n = int(eval(input()))
v = []
for i in range(n):
    ai = int(eval(input()))
    vi = []
    for j in range(ai):
        vi.append(list(map(int, input().split())))
    v.append(vi)

m = 0
for bit in range(2**n - 1, -1, -1):
    is_break = False
    for i in range(n):
        if not (bit & (1 << i)):
            continue
        for xij, yij in v[i]:
            if not (not (bit & (1 << xij - 1))) != yij:
                is_break = True
                break
        if is_break:
            break
    else:
        m = max(bin(bit).count('1'), m)

print(m)
# Original solution
n=int(eval(input()))
A=[]
L=[]
for i in range(n):
   a=int(eval(input()))
   A.append(a)
   D=[]
   for j in range(a):
      x,y=list(map(int,input().split()))
      D.append((x,y))
   L.append(D)

ans=0
for i in range(2**n):
   B=[0]*n
   for j in range(n):
      if i>>j&1:
         B[j]=1
   if 1 in B:
      flag=True
      for k in range(n):
         if B[k]==1:
            for m in range(A[k]):
               if B[L[k][m][0]-1]!=L[k][m][1]:
                  flag=False
                  break
      if flag:
         ans=max(ans,sum(B))
print(ans)


# Optimized solution
n=int(eval(input()))
A=[]
L=[]
for i in range(n):
   a=int(eval(input()))
   A.append(a)
   D=[]
   for i in range(a):
      x,y=list(map(int,input().split()))
      D.append((x,y))
   L.append(D)
ans=0
for i in range(2**n):
   B=[0]*n
   for j in range(n):
      if i>>j&1:
         B[j]=1
   if 1 in B:
      flag=True
      for k in range(n):
         if B[k]==1:
            for m in range(A[k]):
               if B[L[k][m][0]-1]!=L[k][m][1]:
                  flag=False
                  break
      if flag:
         ans=max(ans,sum(B))
print(ans)
# Original solution
n=int(eval(input()))
a=[]
for i in range(n):
    x=int(eval(input()))
    aa=[[int(i) for i in input().split()] for i in range(x)]
    a.append(aa)
#print(a)

ans=0
for i in range(2**n):
    status=[True]*n
    for j in range(n):
        if ((i>>j)&1):
            status[j]=False
    check=[None]*n
    flag=True
    for i in range(n):
        if status[i]==True:
            for x,y in a[i]:
                if y==1 and status[x-1]==True and (check[x-1]==None or check[x-1]==True):
                    check[x-1]=True
                elif y==1 and (check[x-1]==False or status[x-1]==False):
                    flag=False
                elif y==0 and status[x-1]==False and (check[x-1]==None or check[x-1]==False):
                    check[x-1]=False
                elif y==0 and (check[x-1]==True or status[x-1]==True):
                    flag=False
    if flag:
        #print(status,check)
        cnt=status.count(True)
        ans=max(ans,cnt)
print(ans)

# Optimized solution
n=int(eval(input()))
a=[]
for i in range(n):
    x=int(eval(input()))
    b=[[int(i) for i in input().split()] for i in range(x)]
    a.append(b)

ans=0

for i in range(2**n):
    status=[True]*n
    for j in range(n):
        if ((i>>j)&1):
            status[j]=False
    
    judge=[None]*n
    contradiction=False
    
    for x,person in enumerate(a):
        if status[x]==False:
            continue
        for testimony in person:
            if testimony[1]==1: 
                if judge[testimony[0]-1]!=False and status[testimony[0]-1]==True:
                    judge[testimony[0]-1]=True
                else:
                    contradiction=True
            else:
                if judge[testimony[0]-1]!=True and status[testimony[0]-1]==False:
                    judge[testimony[0]-1]=False
                else:
                    contradiction=True

    if contradiction==False:
        ans=max(ans,status.count(True))
print(ans)
# Original solution
# coding: utf-8
N = int(eval(input()))
A = {}
for i in range(N):
    a = int(eval(input()))
    l = []
    for j in range(a):
        tmp = list(map(int, input().split()))
        l.append(tmp[:])
    A[i+1] = l[:]
# print(A)

ans = -1
for bit in range(2**N):
    l = []
    # 正直者と嘘つきの配列
    for i in range(N):
        if (bit >> i) & 1 == 1:
            l.append(1)
        else:
            l.append(0)
    
    flag = True
    for i in range(N):
        if (bit >> i) & 1 == 1:
            for j in range(len(A[i+1])):
                if l[A[i+1][j][0]-1] != A[i+1][j][1]:
                    flag = False
    # print(*l)
    # print(flag)
    if flag:
        ans = max(ans, sum(l))
    # if len(l) <= 2:
    #     ans = 1
print(ans)

# Optimized solution
# coding: utf-8
N = int(eval(input()))
A = {}
for i in range(N):
    a = int(eval(input()))
    l = []
    for j in range(a):
        tmp = list(map(int, input().split()))
        l.append(tmp[:])
    A[i+1] = l[:]
ans = -1
for bit in range(2**N):
    l = []
    # 正直者と嘘つきの配列
    for i in range(N):
        if (bit >> i) & 1 == 1:
            l.append(1)
        else:
            l.append(0)
    
    flag = True
    for i in range(N):
        # 正直者の場合、それぞれのいうことに整合性があるかを確認する
        if (bit >> i) & 1 == 1:
            for j in range(len(A[i+1])):
                # 正直者を嘘つき(もしくは逆)を言った場合はその組み合わせで
                # 整合性が取れないので成り立たない組み合わせ
                if l[A[i+1][j][0]-1] != A[i+1][j][1]:
                    flag = False
    if flag:
        ans = max(ans, sum(l))
print(ans)
# Original solution
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

N = int(eval(input()))
evid = [[] for _ in range(N)]

for i in range(N):
  a = int(eval(input()))
  for _ in range(a):
    x, y = list(map(int, input().split()))
    evid[i].append((x-1,y))
    
ans = 0
for bit in range(1<<N):
  cnt = 0
  ok = True
  for i in range(N):
    if not bit>>i & 1:
      continue
    for x, y in evid[i]:
      if y==1 and not bit>>x & 1:
        ok = False
        break
      if y==0 and  bit>>x & 1:
        ok = False
        break
    if ok:
      cnt += 1
    else:
      break
  else:
    ans = max(ans, cnt)
print(ans)    
      
    

# Optimized solution

def resolve():
    N = int(eval(input()))
    evdi = [[] for _ in range(N)]
    for i in range(N):
        cnt = int(eval(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)


if __name__ == "__main__":
    resolve()
# Original solution
import sys
input = sys.stdin.buffer.readline

def main():
    n = int(eval(input()))
    #ビット全探索を行う
    import itertools
    li = list(itertools.product([0, 1], repeat=n)) # ０が不親切もの、１が親切もの

    #dd[i]:人iが人xをy（０なら不親切,１なら親切)だと思っていることを収納
    from collections import deque, defaultdict
    dd = {}
    for i in range(n):
        dd[i] = deque()
    for i in range(n):
        a = int(eval(input()))
        for j in range(a):
            x, y = list(map(int, input().split()))
            dd[i].append((x-1, y))


    from copy import deepcopy
    max_sum = 0 #親切者の数の最大値
    for i in li: # i には親切者のタプルが入っている
        ppp = 0
        for ggg in i:
            ppp += ggg
        if ppp <= max_sum:
            continue
        sum_ = 0
        flag = True
        co = deepcopy(dd)
        for k in range(len(i)): #全員の証言が矛盾しないかを考える
            if i[k] == 0: # 不親切ものの場合
                continue
            else: #以下k人目の証言を考える
                sum_ += 1
                length = len(co[k])
                while co[k]:
                    x, y = co[k].popleft()
                    if i[x] != y: #証言と一致していない場合
                        flag = False
                        break
        if flag:
            max_sum = max(max_sum, sum_)

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

# Optimized solution
import sys
input = sys.stdin.buffer.readline

def main():
    n = int(eval(input()))
    #ビット全探索を行う
    import itertools
    li = list(itertools.product([0, 1], repeat=n)) # ０が不親切もの、１が親切もの

    #dd[i][x] = y:人iが人xをy（０なら不親切,１なら親切)だと思っていることを収納
    NIL = -1
    dd = [[NIL]*n for _ in range(n)]
    for i in range(n):
        a = int(eval(input()))
        for j in range(a):
            x, y = list(map(int, input().split()))
            x = x-1
            dd[i][x] = y


    from copy import deepcopy
    max_sum = 0 #親切者の数の最大値
    for i in li: # i には親切者のタプルが入っている
        ppp = 0
        for ggg in i:
            ppp += ggg
        if ppp <= max_sum:
            continue
        sum_ = 0
        flag = True
        for k in range(len(i)): #全員の証言が矛盾しないかを考える
            if i[k] == 0: # 不親切ものの場合
                continue
            else: #以下k人目の証言を考える
                sum_ += 1
                for l in range(n):
                    if dd[k][l] != NIL and dd[k][l] != i[l]: #証言と一致していない場合
                        flag = False
                        break
        if flag:
            max_sum = max(max_sum, sum_)

    print(max_sum)
            
if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
S = ['']

res = []

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

allp = 2**N - 1

for i in range(allp, -1, -1):
    pat = bin(i).replace('0b', '')
    pat = pat.zfill(N)
    h_list = []
    l_list = []
    for (i, p) in enumerate(pat):
        t = i + 1
        if p == '1':
            if t in l_list:
                break
            h_list.append(t)
            for s in S[t]:
                if s[1] == 1:
                    if s[0] in l_list:
                        break
                    h_list.append(s[0])
                else:
                    if s[0] in h_list:
                        break
                    l_list.append(s[0])
            else:
                continue
            break
        else:
            if t in h_list:
                break
            l_list.append(t)
            # for s in S[t]:
            #     if s[1] == 1:
            #         if s[0] in h_list:
            #             break
            #         l_list.append(s[0])
            #     else:
            #         if s[0] in l_list:
            #             break
            #         h_list.append(s[0])
            # else:
            #     continue
            # break
    else:
        res.append(pat)

maxA = 0
for r in res:
    maxA = max(maxA, r.count('1'))
print(maxA)


# Optimized solution
N = int(eval(input()))
S = ['']

res = []

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

allp = 2**N - 1

for i in range(allp, -1, -1):
    pat = bin(i).replace('0b', '')
    pat = pat.zfill(N)
    h_list = []
    l_list = []
    for (i, p) in enumerate(pat):
        t = i + 1
        if p == '1':
            if t in l_list:
                break
            h_list.append(t)
            for s in S[t]:
                if s[1] == 1:
                    if s[0] in l_list:
                        break
                    h_list.append(s[0])
                else:
                    if s[0] in h_list:
                        break
                    l_list.append(s[0])
            else:
                continue
            break
        else:
            if t in h_list:
                break
            l_list.append(t)
    else:
        res.append(pat)

maxA = 0
for r in res:
    maxA = max(maxA, r.count('1'))
print(maxA)
# Original solution
N=int(eval(input()))
testimony=[[-1]*N for i in range(N)]
count=0
for i in range(N):
    A=int(eval(input()))
    for j in range(A):
        x,y=list(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)

# Optimized solution
N=int(eval(input()))
xy=[[-1]*N for i in range(N)]
count=0
for i in range(N):
    A=int(eval(input()))
    for j in range(A):
        x,y=list(map(int,input().split()))
        xy[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 xy[j][k]==-1:
                    continue
                if xy[j][k]!=honest[k]:
                    flag=False
    if flag:
        count=max(count,honest.count(1))
print(count)
# Original solution
n = int(eval(input()))
lst = [(bin(i)[2:]).zfill(n) for i in range(2**n)]
num_list = []
A_list = []
xy_list = []
for i in range(n):
    a = int(eval(input()))
    A_list.append(a)
    for j in range(a):
        x,y = list(map(int,input().split()))
        xy_list.append([x,y])
for i in range(len(lst)):
    choose = lst[i]
    one_count = choose.count("1")
    a_count = 0
    flag = True
    for num, j in enumerate(A_list):
        a_count += j
        for k in range(a_count-j, a_count):
            x,y = xy_list[k][0],xy_list[k][1]
            if choose[num] == "1" and choose[x-1] != str(y):
                flag = False
    if flag:
        num_list.append(one_count)
    else:
        num_list.append(0)
print((max(num_list)))


# Optimized solution
n = int(eval(input()))
lst = [(bin(i)[2:]).zfill(n) for i in range(2**n)]
num_list = []
A_list = []
xy_list = []
for i in range(n):
    a = int(eval(input()))
    A_list.append(a)
    for j in range(a):
        x,y = list(map(int,input().split()))
        xy_list.append([x,y])
for i in range(len(lst)):
    choose = lst[i]
    one_count = choose.count("1")
    a_count = 0
    flag = True
    for num, j in enumerate(A_list):
        a_count += j
        for k in range(a_count-j, a_count):
            x,y = xy_list[k][0],xy_list[k][1]
            if choose[num] == "1" and choose[x-1] != str(y):
                flag = False
                break
    if flag:
        num_list.append(one_count)
    else:
        num_list.append(0)
print((max(num_list)))
# Original solution
n = int(eval(input()))
lst = [(bin(i)[2:]).zfill(n) for i in range(2**n)]
num_list = []
A_list = []
xy_list = []
for i in range(n):
    a = int(eval(input()))
    A_list.append(a)
    for j in range(a):
        x,y = list(map(int,input().split()))
        xy_list.append([x,y])
for i in range(len(lst)):
    choose = lst[i]
    one_count = choose.count("1")
    a_count = 0
    flag = True
    for num, j in enumerate(A_list):
        a_count += j
        for k in range(a_count-j, a_count):
            x,y = xy_list[k][0],xy_list[k][1]
            if choose[num] == "1" and choose[x-1] != str(y):
                flag = False
                break
    if flag:
        num_list.append(one_count)
    else:
        num_list.append(0)
print((max(num_list)))


# Optimized solution
n = int(eval(input()))
lst = [(bin(i)[2:]).zfill(n) for i in range(2**n)]
ans = 0
A_list = []
xy_list = []
for i in range(n):
    a = int(eval(input()))
    A_list.append(a)
    for j in range(a):
        x,y = list(map(int,input().split()))
        xy_list.append([x,y])
for i in range(len(lst)):
    choose = lst[i]
    one_count = choose.count("1")
    a_count = 0
    flag = True
    for num, j in enumerate(A_list):
        a_count += j
        for k in range(a_count-j, a_count):
            x,y = xy_list[k][0],xy_list[k][1]
            if choose[num] == "1" and choose[x-1] != str(y):
                flag = False
                break
    if flag:
        ans = max(ans,one_count)
print(ans)
# Original solution
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
A = [[] for _ in range(N)]
for i in range(N):
    a = ri()
    l = []
    for j in range(a):
        x, y = rl()
        l.append((x, y))
    A[i] = l

answer = 0

for i in range(2 ** N):
    honest = [False] * (N+1)
    bool = True
    for j in range(N):
        if ((i >> j) & 1):
            honest[N - j] = True
    for k in range(1, N+1):
        if honest[k] == True:
            #k番目の人は正直者
            for x, y in A[k-1]:
                if y == 1 and honest[x] == False:
                    bool = False
                    break
                if y == 0 and honest[x] == True:
                    bool = False
                    break
    if bool and sum(honest) > answer:
        answer = max(answer, sum(honest))

print(answer)


# Optimized solution
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

answer = 0
N = ir()
honest = [[] for _ in range(N+1)]
liar = [[] for _ in range(N+1)]
# bit全探索
for i in range(N):
    a = ir()
    for _ in range(a):
        x, y = lr()
        if y == 1:
            honest[i].append(x-1)
        else:
            liar[i].append(x-1)

for bit in range(1<<N):
    bl = True
    h = []
    for i in range(N):
        if (bit >> i) & 1:
            h.append(i)
    s = set(h)
    for person in h:
        for x in honest[person]:
            if x not in s:
                bl = False
                break
        for y in liar[person]:
            if y in s:
                bl = False
                break
        if not bl:
            break
    if bl:
        answer = max(answer, len(s))

print(answer)
# Original solution
n = int(eval(input()))
ls = []
for i in range(n):
    a = int(eval(input()))
    p = []
    for i in range(a):
        x,y = list(map(int,input().split()))
        p.append([x-1,y])
    ls.append(p)

ans = 0

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

# Optimized solution
n = int(eval(input()))
ls = []
for i in range(n):
    a = int(eval(input()))
    p = []
    for i in range(a):
        x,y = list(map(int,input().split()))
        p.append([x-1,y])
    ls.append(p)

ans = 0

for i in range(2**n):
    flag = 0
    for j in range(n):
        if (i >> j) & 1:#もし正直者だったら
            for k in ls[j]:#証言の確認
                if (i >> k[0])&1 != k[1]:#もし証言がおかしかったら
                    flag = 1
                    break
    if flag == 0:
        ans = max(ans, bin(i)[2:].count('1'))
print(ans)
# Original solution
N = int(eval(input()))
A = []
x = [[] for i in range(N)]
y = [[] for i in range(N)]
for i in range(N):
    A.append(int(eval(input())))
    for j in range(A[i]):
        tmpX, tmpY = list(map(int, input().split()))
        x[i].append(tmpX-1)
        y[i].append(tmpY)
ans = 0

for case in range(2**N):
    flag = True
    honest = 0
    for i in range(N):
        for j in range(A[i]):
            if (case >> i)&1 and (case >> x[i][j])&1 != y[i][j]:
                flag = False
        honest += (case >> i)&1

    if flag:
        ans = max(ans, honest)

print(ans)

# Optimized solution
N = int(eval(input()))
A = []
x = [[] for i in range(N)]
y = [[] for i in range(N)]
for i in range(N):
    A.append(int(eval(input())))
    for j in range(A[i]):
        tmpX, tmpY = list(map(int, input().split()))
        x[i].append(tmpX-1)
        y[i].append(tmpY)
ans = 0

for case in range(2**N):
    flag = True
    honest = 0
    for i in range(N):
        if (case >> i)&1 == False:  continue
        for j in range(A[i]):
            if (case >> x[i][j])&1 != y[i][j]:
                flag = False
        honest += (case >> i)&1

    if flag:
        ans = max(ans, honest)

print(ans)