Problem:


Score : 300 points

Problem Statement

There are N people numbered 1 to N. Each of them is either an honest person whose testimonies are always correct or an unkind person whose testimonies may be correct or not.

Person i gives A_i testimonies. The j-th testimony by Person i is represented by two integers x_{ij} and y_{ij}. If y_{ij} = 1, the testimony says Person x_{ij} is honest; if y_{ij} = 0, it says Person x_{ij} is unkind.

How many honest persons can be among those N people at most?

Constraints

All values in input are integers.

1 \leq N \leq 15

0 \leq A_i \leq N - 1

1 \leq x_{ij} \leq N

x_{ij} \neq i

x_{ij_1} \neq x_{ij_2} (j_1 \neq j_2)

y_{ij} = 0, 1

Input

Input is given from Standard Input in the following format:

N
A_1
x_{11} y_{11}
x_{12} y_{12}
:
x_{1A_1} y_{1A_1}
A_2
x_{21} y_{21}
x_{22} y_{22}
:
x_{2A_2} y_{2A_2}
:
A_N
x_{N1} y_{N1}
x_{N2} y_{N2}
:
x_{NA_N} y_{NA_N}

Output

Print the maximum possible number of honest persons among the N people.

Sample Input 1

3
1
2 1
1
1 1
1
2 0

Sample Output 1

2

If Person 1 and Person 2 are honest and Person 3 is unkind, we have two honest persons without inconsistencies, which is the maximum possible number of honest persons.

Sample Input 2

3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0

Sample Output 2

0

Assuming that one or more of them are honest immediately leads to a contradiction.

Sample Input 3

2
1
2 0
1
1 0

Sample Output 3

1



Sample input:
3
1
2 1
1
1 1
1
2 0


Sample output:
2

Submission status: Runtime Error

Solution code:
import sys
import numpy as np 

n = int(sys.stdin.readline().rstrip())
graph = [None] * n
for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    graph[i] = np.array([sys.stdin.readline().split() for _ in range(a)], dtype=np.int8).T

def main():
    comb = np.arange(1 << n)[:, None] >> np.arange(n) & 1
    for i in range(n):
        x, y = graph[i]
        bl = np.all((comb[:, i][:, None] ^ 1) | (comb[:, x-1] == y), axis=1)
        comb = comb[bl]
    print(np.amax(comb.sum(axis=1)))

if __name__ ==  '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np 

n = int(sys.stdin.readline().rstrip())
graph = [None] * n
for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    graph[i] = np.array([[sys.stdin.readline().split()] for _ in range(a)], dtype=np.int8).T

def main():
    comb = np.arange(1 << n)[:, None] >> np.arange(n) & 1
    for i in range(n):
        x, y = graph[i]
        bl = (comb[:, i][:, None] ^ 1) | (comb[:, x-1] == y).reshape(len(comb), -1)
        bl = np.all(bl, axis=1)
        comb = comb[bl]
    print(np.amax(comb.sum(axis=1)))

if __name__ ==  '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())

g_list = [[]]
for i in range(N):
    for j in range(N):
        g_list[i][j] = -1

for i in range(N):
    m = int(input())
    for j in range(m):
        a_x = list(map(int, input().split()))
        a = a_x[0]
        a -= 1
        x = a_x[1]
        g_list[i][a] = x

ans = 0

for i in range(1<<N):
    d = [0 for l in range(N)]
    for j in range(N):
        if i >> j & 1:
            d[j] = 1
    ok = True
    for j in range(N):
        if d[j]:
            for k in range(N):
                if g_list[j][k] == -1:
                    continue
                if g_list[j][k] != d[k]:
                    ok = False
    if ok:
        total = sum(bin(i)[2:])
        ans = max(ans, total)

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import numpy as np

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N=int(input())
    A = []
    for i in range(N):
        a = int(input())
        xy = None
        for j in range(a):
            xy = list(map(int,input().split()))
        A.append(xy)
    #print(A)

    c = 0
    for bit in range(2**N):
        bs = np.array(list(map(int,list("0"*N+bin(bit)[2:])[-N:])))
        ok = True
        #print(bs)
        for i in range(N):
            x, y = A[i]
            if bs[i]==0:
                y = 1-y
            if bs[x-1]!=y:
                ok=False
                #print("NG")
                break
        if ok:
            #print("OK")
            c = max(c, bs.sum())

    print(c)        


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import copy
from itertools import permutations, product

n = int(input())
al = []
xyl = []
for i in range(n):
    a = int(input())
    al.append(a)
    tl = []
    for j in range(a):
        t = [int(i) for i in input().split()]
        tl.append(t)
    xyl.append(tl)

l = [i for i in product([0, 1], repeat=n)]

ans_list = []

for ll in l:
    ans_flag = 1
    for i in range(n):
        flag = 1
        for j in range(a):
            if ll[xyl[i][j][0]-1] != xyl[i][j][1]:
                flag = 0
        if flag != ll[i]:
            ans_flag = 0
    if ans_flag == 1:
        ans_list.append(copy.deepcopy(ll))

ans = 0
for i in ans_list:
    k = i.count(1)
    if ans < k:
        ans = k

print(ans)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        if A[i] < B[i]:
            B[i] -= A[i]
            ans += A[i]
            if A[i+1] < B[i]:
                ans += A[i+1]
                A[i+1] = 0
            else:
                ans += B[i]
                A[i+1] -= B[i]
        else:
            ans += B[i]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

ans = 0
for b in range(1<<N):
    cnt = bin(b).count('1')
    if cnt <= ans: continue
    for i in range(N):
        if b&(1<<i):
        for x,y in xys[i]:
                if y==1 and b&(1<<x): continue
                if y==0 and b&(1<<x)==0: continue
                break
            else:
                continue
            break
    else:
        ans = cnt
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
from copy import deepcopy
N = int(input())

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

honest = 0

# bit全探索
for i in range(2 ** N):
    flag = True
    for j in range(N):
        if ((i >> j) & 1) == 1:
            # bitが立っている箇所に対して処理。つまり,人jが正直者だとしたとき、
            # その人の発言と、矛盾していないか判定
            for x, y in status[j]: # 人jの証言            
                if ((i >> x) & 1) != y:
                    flag = False
                    break
    if flag:
        honest = max(honest, bin(i)[2:].count('1'))  # 0bが先頭につくため

print(honest)

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
work = []
for i in range(n):
    a = int(input())
    work.append([list(map(int, input().split())) for i in range(a)])
result = 0
for i in range(n):
    count = 0
    d = deque([work[i]])
    honest = deque([i])
    unkind = deque()
    while len(d) > 0:
        human = d.popleft()
        for x, y in human:
            if y == 1:
                if x not in honest:
                    d.append(work[x-1])
                    honest.append(x)
            else:
                if x not in unkind:
                    unkind.append(x)
    finish = False
    while not finish:
        finish = True
        for i in range(1, n+1):
            if i not in honest and i not in unkind:
                flag = True
                for x, y in work[i-1]:
                    if y == 1 and x in unkind:
                        flag = False
                        break
                    elif y == 0 and x in honest:
                        flag = False
                        break
                    elif x not in honest+unkind:
                        finish = False
                if flag:
                    honest.append(i)
                else:
                    unkind.append(i)
    if len(set(honest) & set(unkind)) == 0:
        count = n - len(unkind)
        result = result if result > count else count
print(result)

Submission status: Runtime Error

Solution code:
N = int(input())
path = []
ans = 0
ap = path.append
Ap = path[-1].append
for i in range(N):
    A = int(input())
    ap([])
    for j in range(A):
        x, y = map(int,input().split())
        x -= 1
        Ap((x, y))
for i in range(1<<N):
    i |= (1<<N)
    judge = True
    for j in range(N):
        if (1<<j) & i:
            for k in range(len(path[j])):
                if path[j][k][1] != int(bin(i)[-path[j][k][0] - 1]):
                    judge = False
    if judge:
        if ans < bin(i).count("1") - 1:
            ans = bin(i).count("1") - 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
test_list = [[[int(i) for i in input().split()] for j in range(int(input()))] for k in range(n)]
    
man_list = [[int(j) for j in bin(i)[2:].zfill(n)] for i in range(2**n)]
    
ans = 0
bad = 0
    
for man in man_list:
    for j in range(n):
        if man[j] == 1:
            for k in test_list[j]:
            x = k[0] - 1
            y = k[1]
            if man[x] != y:
                bad = 1
                break
    if bad == 1:
        bad = 0
        break
    else:
        ans = max(ans, sum(man))
    
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
test_list = [[[int(i) for i in input().split()] for j in range(int(input()))] for k in range(n)]
    
man_list = [[int(j) for j in bin(i)[2:].zfill(n)] for i in range(2**n)]
    
ans = 0
bad = 0
    
for man in man_list:
    for j in range(n):
        if man[j] == 1:
            for k in test_list[j]:
            x = k[0] - 1
            y = k[1]
            if man[x] != y:
                bad = 1
                break
        if bad == 1:
            bad = 0
            break
        else:
            ans = max(ans, sum(man))
    
print(ans)

Submission status: Runtime Error

Solution code:
# 初期入力
N = int(input())
A = list(map(int, input().split()))


x = [  A[i]^A[j] for i in range(N-1) for j in range(i+1,N) ]
kotae =sum(x) % (10**9 +7)
print(kotae)

Submission status: Runtime Error

Solution code:
Not found

Submission status: Runtime Error

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

ret = 0
for i in range( 2 ** n - 1, 0, -1 ):
  o = [int(i) for i in str( "{:b}".format(i).zfill(n) )]
  is_right = True
  for j in range( n ):
    for m in range( n ):
      if o[j] == 1:
        is_rzight &= ( l[j][m] in [-1, o[m]] )
    if not is_right:
      break
        
  if is_right:
    ret = sum(o)
    break
          
print( ret )

Submission status: Runtime Error

Solution code:
def judge(bit, n, v):
    # i 人目の証言を検証する
    for i in range(n):
        # 1人目が「不親切」だったら証言はすべて無視
        if not (bit & (1 << i)):
            continue

        x, y = v[i]
        # y == 1 なのに「不親切」だったらダメ
        if y == 1 and not (bit & (1 << x)):
            return False

        # y == 0 なのに「正直者」だったらダメ
        if y == 0 and (bit & (1 << x)):
            return False
    return True


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

ans = 0
for bit in range(1 << n):
    if not judge(bit, n, v):
        continue

    # bit に含まれる人数を数える
    cnt = 0
    for i in range(n):
        if bit & (1 << i):
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

X = [[[-1]*N] for i in range(N)]
for i in range(N):
    a = int(input())
    for i in range(a):
        b, c = map(int, input().split())
        X[i][b-1] = c
ans = 0
for i in range(2**N):
    Y = [0]*(N)
    for j in range(N):
        if ((i >> j) & 1):
            Y[j] = 1
    for j in range(N):
        if Y[j] == 1:
            for k in range(N):
                if X[j][k] == -1:
                    continue
                if X[j][k] != Y[j]:
                    Y[j] = 0
    ans = max(ans, sum(Y))

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
g = [[-1]*15]*15
for i in range(N):
    a = int(input())
    for _ in range(a):
        x,y = map(int,input().split())
        g[i][x] = y
ans = 0

for i in range(1<<N):
  d = [0]*N
  for j in range(N):
    if (i>>j&1):
      d[j] = 1
  flag = True
  for j in range(N):
    if d[j] == 1:
      for k in range(N):
        if g[j][k] == -1:
          continue
        if g[j][k] != d[k]:
          flag = False
  if flag:
    ans = max(ans,sum(d))
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())

S=[[-1]*N for _ in range(N)]
for _ in range(N):
  A=int(input())
  for i in range(A):
    x, y=map(int, input().split())
    
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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 && (s>>j&1) != g[i][j]:
                    ok = False
	if ok:
		ans = max(ans, bin(s).count("1"))

print(ans)

Submission status: Runtime Error

Solution code:
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 && (s>>j&1) != g[i][j]:
                  ok = False
	if ok:
		ans = max(ans, bin(s).count("1"))

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
g = [[-1] * n] * 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)

Submission status: Runtime Error

Solution code:
n = int(input())
xy = []
for _ in range(n):
    xy.append([])
    a = int(input())
    for _ in range(a):
        xy[-1].append([int(i) for i in input().split()])
        xy[-1][0] -= 1

ma = 0

for i in range(2 ** n):
    ok = True
    a = 0
    for j in range(n):
        if (2 ** j) & i != 0:
            a += 1
            for k in xy[j]:
                if ((2 ** k[0]) & i != 0) != (k[1] == 1):
                    ok = False
    if ok:
        ma = max(ma, a)
print(ma)

Submission status: Runtime Error

Solution code:

def main():
    
    n = int(input())

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

    #print(n_list)
    ans = [0]
    for j in range(0,2**n):
        tmp = bin(j)
        tmp = str(int(tmp[2:])).zfill(n)
        #print('tmp')
        #print(tmp)
        
        
        break_on = 0
        for k in range(n):
            if tmp[k] == '1':
                if n_list[k][0] != 0:
                    for h in n_list[k]:
                        #print('########')
                        #print(k)
                        #print(h[1])
                        #print(tmp[h[0]])
                        if h[1] != int(tmp[h[0]]):
                            break_on = 1
                            break
                    if break_on == 1:
                        break
            if break_on == 1:
                break
            
            if tmp[k] == '0':
                continue
        
        if break_on == 0:
            #print('tmp.count()')
            #print(tmp.count('1'))
            ans.append(tmp.count('1'))
    
    #print(ans)
    print(max(ans))
    


            



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

def main():
    
    n = int(input())

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

    #print(n_list)
    ans = [0]
    for j in range(0,2**n):
        tmp = bin(j)
        tmp = str(int(tmp[2:])).zfill(n)
        #print('tmp')
        #print(tmp)
        
        
        break_on = 0
        for k in range(n):
            if tmp[k] == '1':
                for h in n_list[k]:
                    #print('########')
                    #print(k)
                    #print(h[1])
                    #print(tmp[h[0]])
                    if h[1] != int(tmp[h[0]]):
                        break_on = 1
                        break
                if break_on == 1:
                    break
            if break_on == 1:
                break
            
            if tmp[k] == '0':
                continue
        
        if break_on == 0:
            #print('tmp.count()')
            #print(tmp.count('1'))
            ans.append(tmp.count('1'))
    
    #print(ans)
    print(max(ans))
    


            



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
lst = [list(f"{i:0{N}b}") for i in range(2**N)]
X = [[] for i in range(N)]
Y = [[] for i in range(N)]

for i in range(N):
    tmp_A = int(input())
    A.append(tmp_A)
    for j in range(tmp_A):
        tmp_x,tmp_y = input().split()
        X[i].append(int(tmp_x)-1)
        Y[i].append(tmp_y)

ans = -1

for i in range(2**N):
    flag = 1
    for j in range(N):
        if lst[i][j] == "1":
            for k in range(A[j]):
               if lst[i][X[j][k]] != Y[j][k]:
                   flag = 0
    if flag:
        tmp = 0
        for j in lst[i]:
            if j == "1":
               tmp += 1
        if tmp > ans:
            ans = tmp

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
# A = []
lst = [list(f"{i:0{N}b}") for i in range(2**N)]
# X = [[] for i in range(N)]
# Y = [[] for i in range(N)]

# for i in range(N):
#     tmp_A = int(input())
#     A.append(tmp_A)
#     for j in range(tmp_A):
#         tmp_x,tmp_y = input().split()
#         X[i].append(int(tmp_x)-1)
#         Y[i].append(tmp_y)

ans = -1

# for i in range(2**N):
#     flag = 1
#     for j in range(N):
#         if lst[i][j] == "1":
#             for k in range(A[j]):
#                if lst[i][X[j][k]] != Y[j][k]:
#                    flag = 0
#     if flag:
#         tmp = 0
#         for j in lst[i]:
#             if j == "1":
#                tmp += 1
#         if tmp > ans:
#             ans = tmp

print(ans)

Submission status: Runtime Error

Solution code:
# N = int(input())
# A = []
lst = [list(f"{i:0{N}b}") for i in range(2**N)]
# X = [[] for i in range(N)]
# Y = [[] for i in range(N)]

# for i in range(N):
#     tmp_A = int(input())
#     A.append(tmp_A)
#     for j in range(tmp_A):
#         tmp_x,tmp_y = input().split()
#         X[i].append(int(tmp_x)-1)
#         Y[i].append(tmp_y)

ans = -1

# for i in range(2**N):
#     flag = 1
#     for j in range(N):
#         if lst[i][j] == "1":
#             for k in range(A[j]):
#                if lst[i][X[j][k]] != Y[j][k]:
#                    flag = 0
#     if flag:
#         tmp = 0
#         for j in lst[i]:
#             if j == "1":
#                tmp += 1
#         if tmp > ans:
#             ans = tmp

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
lst = [list(f"{i:0{N}b}") for i in range(2**N)]
X = [[] for i in range(N)]
Y = [[] for i in range(N)]

# for i in range(N):
#     tmp_A = int(input())
#     A.append(tmp_A)
#     for j in range(tmp_A):
#         tmp_x,tmp_y = input().split()
#         X[i].append(int(tmp_x)-1)
#         Y[i].append(tmp_y)

ans = -1

# for i in range(2**N):
#     flag = 1
#     for j in range(N):
#         if lst[i][j] == "1":
#             for k in range(A[j]):
#                if lst[i][X[j][k]] != Y[j][k]:
#                    flag = 0
#     if flag:
#         tmp = 0
#         for j in lst[i]:
#             if j == "1":
#                tmp += 1
#         if tmp > ans:
#             ans = tmp

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
lst = [list(f"{i:0{N}b}") for i in range(2**N)]
X = [[] for i in range(N)]
Y = [[] for i in range(N)]

for i in range(N):
    tmp_A = int(input())
    A.append(tmp_A)
    for j in range(tmp_A):
        tmp_x,tmp_y = input().split()
        X[i].append(int(tmp_x)-1)
        Y[i].append(tmp_y)

ans = -1

# for i in range(2**N):
#     flag = 1
#     for j in range(N):
#         if lst[i][j] == "1":
#             for k in range(A[j]):
#                if lst[i][X[j][k]] != Y[j][k]:
#                    flag = 0
#     if flag:
#         tmp = 0
#         for j in lst[i]:
#             if j == "1":
#                tmp += 1
#         if tmp > ans:
#             ans = tmp

print(ans)

Submission status: Runtime Error

Solution code:
from typing import List, Tuple
import sys
input = sys.stdin.readline


class Human:

    def __init__(self, statements: List[Tuple[int, int]]):
        self.statements = statements

    def is_honest(self, honest_list: List[int]):
        for x, y in self.statements:
            if y:
                if x not in honest_list:
                    return False
            else:
                if x in honest_list:
                    return False
        return True


class Humans:

    def __init__(self):
        self.humans = [None]

    def add(self, human: Human):
        self.humans.append(human)

    def is_all_honest(self, honest_list: List[int]):
        for i in honest_list:
            if not self.humans[i].is_honest(honest_list):
                return False
        return True


def main():
    n = int(input())
    humans = Humans()
    for _ in range(n):
        a = int(input())
        xy = [tuple(map(int, input().split())) for _ in range(a)]
        humans.add(Human(xy))
    max_honest = 0
    for bit in range(2**n):
        honest_list = []
        for i in range(n):
            if (bit >> i) & 1:
                honest_list.append(i+1)  # 1ずれるため補正
        if humans.is_all_honest(honest_list):
            max_honest = max(max_honest, len(honest_list))
    print(max_honest)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

def judge(bit):
    for i in range(N):
        if bit&(1<<i)==False: #決め打ち時に不親切の場合
            continue
        for j in range(A[i]): #親切な人の発言検証
            tmpx=pairs[j][0][0]
            tmpy=pairs[j][0][1]
            if tmpy==1  and (bit&(1<<tmpx)==False):
                return False
            elif tmpy==0 and (bit&(1<<tmpx)):
                return False
    return True

ans=0
for bit in range((1<<N)):
    if judge(bit):
        count=0
        for i in range(N):
            if bit&(1<<i):
               count+=1
        ans=max(ans,count)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
testimony = [[0] * N for i in range(N)]
A = []

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

testimony = np.array(testimony)

A = np.array(A)
ans = 0

for i in range(2 ** N):
    honesty = [-1] * N
    h = 0
    for j in range(N):
        if (i >> j) & 1:
            honesty[j] = 1
            h += 1
    honesty = np.array(honesty)
    B = testimony @ honesty - A
    if any(honesty[j] == 1 and B[j] != 0 for j in range(N)):
        continue

    ans = max(ans, h)

print(ans)

Submission status: Runtime Error

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

def judge(bit):
    for i in range(N):
        if bit&(1<<i)==False: #決め打ち時に不親切の場合
            continue
        for j in range(A[i]): #親切な人の発言検証
            tmpx=pairs[j][0][0]
            tmpy=pairs[j][0][1]
            if tmpy==1  and (bit&(1<<tmpx)==False):
                return False
            if tmpy==0 and (bit&(1<<tmpx)):
                return False
    return True

ans=0
for bit in range((1<<N)):
    if judge(bit)==True:
        count=0
        for i in range(N):
            if bit&(1<<i):
               count+=1
        ans=max(ans,count)

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
pairs=[]
for i in range(N):
    a=int(input())
    A.append(a)
    pair=[]
    for j in range(a):
        x,y=map(int,input().split())
        pair.append([x-1,y])
    pairs.append(pair)
print(pairs)
def judge(bit):
    for i in range(N):
        if bit&(1<<i)==False: #決め打ち時に不親切の場合
            continue
        for j in range(A[i]): #親切な人の発言検証
            tmpx=pairs[j][0][0]
            tmpy=pairs[j][0][1]
            if tmpy==1  and (bit&(1<<tmpx)==False):
                return False
            if tmpy==0 and (bit&(1<<tmpx)):
                return False
    return True

ans=0
for bit in range((1<<N)):
    if judge(bit)==True:
        count=0
        for i in range(N):
            if bit&(1<<i):
               count+=1
        ans=max(ans,count)

print(ans)

Submission status: Runtime Error

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

ans = 0
for p in range(1<<N):
    h = []
    judge = True
    for i in range(N):
        h.append(p&1)
        p>>=1
    for i in range(N):
        for x, y in xy[i]:
            if h[i] and y != h[x]:
                judge = False
                break
        if not judge: break
    if not judge: continue
    ans = max(ans,sum(h))

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a,c,e,f=[],[],0,0
for i in range(n):
    a.append(int(input()))
    b=[]
    for i in range(a[-1]):
        b.append(list(map(int,input().split())))
    c.append(b)
for i in range(2**n):
    d=bin(i)[2:-1]+bin(i)[-1]
    d='0'*(n-len(d))+d
    for j in range(n):
        if d[j]==1:
            e+=1
    for j in range(n):
        if d[j]==0:
            continue
        for k in range(a[j]):
            if d[c[j][k][0]]!=c[j][k][1]:
                g=True
                continue
    if g:
        continue
    f=max(e,f)
print(f)

Submission status: Runtime Error

Solution code:
n = int(input())
d = [dict()] * n
for i in range(n):
  a = int(input())
  for j in range(a):
    x,y = map(int,input().split())
    d[i][x-1] = y
ans = 0

def count_honest(bits):
  count = 0
  vec = [-1] * n
  for j in range(n):
    honest = (bits >> j) | 1
    count += honest
    for k,v in d[j]:
      v = v if honest else (v+1) % 2
      if vec[k] == -1:
        vec[k] = v
      elif vec[k] != v:
        return 0
  return count
  
for i in range(2**n):
  ans = max(ans, count_honest(i))

Submission status: Runtime Error

Solution code:
n = int(input())
LST = [0] * n
for i in range(n):
    p = int(input())
    lst = [[0]*2 for _ in range(p)]
    for j in range(p):
        a, b = list(map(int, input().split()))
        lst[j][0] = a - 1
        lst[j][1] = b
    LST[i] = lst

def checker(bit):
    flag = True
    for i in range(n):
        if not ((bit >> (2-i)) & 1):
            continue
        num = len(LST[i])
        for j in range(num):
            people = LST[i][j][0]
            TF = LST[i][j][1]
            if TF == 0 and ((bit >> (2-people)) & 1) == 1:
                flag = False
            if TF == 1 and ((bit >> (2-people)) & 1) != 1:
                flag = False
    return flag

max_num = 0
for k in range(n ** 2 - 1):
    cnt = 0
    if checker(k):
        for l in range(n):
            if((k >> l) & 1):
                cnt += 1
        if cnt > max_num:
            max_num = cnt

print(max_num)

Submission status: Runtime Error

Solution code:
n = int(input())
LST = [0] * n
for i in range(n):
    p = int(input())
    lst = [[0]*2 for _ in range(p)]
    for j in range(p):
        a, b = list(map(int, input().split()))
        lst[j][0] = a - 1
        lst[j][1] = b
    LST[i] = lst

def checker(bit):
    flag = True
    for i in range(n):
        if not ((bit >> 2-i) & 1):
            continue
        num = len(LST[i])
        for j in range(num):
            people = LST[i][j][0]
            TF = LST[i][j][1]
            if TF == 0 and ((bit >> 2-people) & 1) == 1:
                flag = False
            if TF == 1 and ((bit >> 2-people) & 1) != 1:
                flag = False
    return flag

max_num = 0
for k in range(n ** 2 - 1):
    cnt = 0
    if checker(k):
        for l in range(n):
            if((k >> l) & 1):
                cnt += 1
        if cnt > max_num:
            max_num = cnt

print(max_num)

Submission status: Runtime Error

Solution code:
n = int(input())
LST = [0] * n
for i in range(n):
    p = int(input()) # people num
    lst = [[0]*2 for _ in range(p)]
    for j in range(p):
        a, b = list(map(int, input().split())) # talk
        lst[j][0] = a - 1 # 0-indexed
        lst[j][1] = b
    LST[i] = lst

def checker(bit):
    flag = True
    # i番目の人が正直者かどうかをチェック
    for i in range(n):
        # i番目の人が正直者でないなら発言の真偽は両方の可能性があるので無視する
        if not ((bit >> 2-i) & 1):
            continue
        # i番目の人が正直なので発言を見にいく
        num = len(LST[i])  # 何人について発言しているか
        for j in range(num):
            people = LST[i][j][0] # i番目の人のj個目の発言の対象者
            TF = LST[i][j][1] # i番目の人のj個目の発言の対象者が0(=正直者でない)なのか1(=正直者)
            if TF == 0 and ((bit >> 2-people) & 1) == 1:
                flag = False
            if TF == 1 and ((bit >> 2-people) & 1) != 1:
                flag = False
    return flag

max_num = 0
for k in range(n ** 2 - 1):
    cnt = 0
    if checker(k):
        # bitの中で1が立っている(=正直者)をカウント
        for l in range(n):
            if((k >> l) & 1):
                cnt += 1
        if cnt > max_num:
            max_num = cnt

print(max_num)