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:
N = int(input())
A = []
xy = []
for nx in range(N):
  A.append(int(input()))
  for xa in range(A[nx]):
    xy.append([nx+1, list(map(int, input().split()))])

h = [0] * N
l = [0] * N
updateCount = [0] * N
def main():
  for ni in range(N):
    man = xy[ni][1][0]
    testi = xy[ni][1][1]
    if testi == 1:
      h[xy[ni][0]-1] = h[xy[ni][0]-1] + 1
    else:
      l[xy[ni][0]-1] = l[xy[ni][0]-1] + 1
    l[ni] = checkUpdateCount(man)
    updateCount[man-1] += 1

def checkUpdateCount(man):
  if updateCount[man-1]+ 1 >= 2:
    return 1
  else:
    return 0

def solve():
  if sum(h) == 0 and sum(l) == 0:
    print(1)
  elif sum(h) == sum(l):
    print(0)
  else:
    print(N - int(sum(h)-sum(l)))

if __name__ == "__main__":
  main()
  solve()

Submission status: Runtime Error

Solution code:
N = int(input())
i = 0
A = []
y = []
count = 0
for i in range(N):
    count_ai = 0
    x = list([])
    A.append(int(input()))

    while A[i] > 0:
        x.append(list(map(int, input().split())))
        A[i] -= 1
        count_ai += 1

    if x[count_ai-1][1] == 1:
        count += 1
    N -= 1
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
# i = 0
A = []
y = []
count = 0
for i in range(N):
    count_ai = 0
    x = list([])
    A.append(int(input()))

    while A[i] > 0:
        x.append(list(map(int, input().split())))
        A[i] -= 1
        count_ai += 1

    if x[count_ai-1][1] == 1:
        count += 1
    N -= 1
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
for k in range(N):
    tmp = []
    i = int(input())
    for j in range(i):
        tmp.append([int(x) for x in input().split(" ")])
    A.append(tmp)

Contradiction = False
maxi = 0

for truer in range(N):
    layer = []
    Contradiction = False

    for i in A[truer]:
        if i[1] == 0:
            layer.append(i[0] - 1)

    said = [[] for _ in range(N)]
    said[truer].append(1)
    for _ in range(2):
        for i in range(N):
            if(len(said[i]) == 0):
                continue
            if i in layer: # layer
                #print("l")
                for j in A[i]:
                    if _ == 0:
                        j[0] -= 1
                    if j[1] == 0:
                        said[j[0]].append(1)
                    else:
                        said[j[0]].append(0)
            else: # unknown
                for j in A[i]:
                    if _ == 0:
                        j[0] -= 1
                    said[j[0]].append(j[1])
   # print(said)
    
    max_ = 0
    for i in said:
        num_said = len(i)
        #print("len:", len(i))
        if len(i) == 0:
            continue
        if (num_said ) == sum(i) or sum(i) == 0:
            max_ += i[0]
        else:
            Contradiction = True
 #   print(max_, Contradiction)
    if not Contradiction:
        maxi = max(maxi, max_)

print(maxi)

Submission status: Runtime Error

Solution code:
import numpy as np
person = [0 for i in range(15)]
X,Y = [[0 for i in range(15)] for j in range(15)],[[0 for i in range(15)] for j in range(15)]


N = int(input())
# デフォルト 0 でフラグ t/fを追加する。
flg_person = ["init" for i in range(15)]
flg_count = 0

for x in range(1,N+1):
  person[x] = int(input())
  for y in range(1,person[x]+1):
    X[x][y],Y[x][y] = map(int,input().split())


for x in range(1,N+1):
  for y in range(1,person[x]+1):
    # 対象人物チェック 初期人物or正直者の場合
    if flg_person[x]=='init' or flg_person[x]==1:
      if flg_person[X[x][y]] != 'init' and flg_person[X[x][y]] != Y[x][y]:
        flg_count += 1
      flg_person[X[x][y]] = Y[x][y]
    # 対象人物チェック 不親切な人と断言されている場合
    else:
      predict = 0
      if Y[x][y] == 0:
        predict = 1 
      if flg_person[x]!='init' and flg_person[x]!=predict:
        flg_count += 1
# print(flg_person)
print(N-flg_count)

Submission status: Runtime Error

Solution code:
import sys
import itertools

input = sys.stdin.readline

n = int(input())
a_s = [0] * n
xss = []
yss = []
for i in range(n):
	a_s[i] = int(input())
	xss.append([])
	yss.append([])
	for _ in range(a_s[i]):
		x, y = map(int, input().split())
		xss[i].append(x)
		yss[i].append(y)

# print(xss)
# print(yss)

used = []
tmp_shojiki = [True] * n
for i in range(n):
	for shojiki in itertools.permutations(tmp_shojiki):
		# print(i, shojiki)
		if shojiki in used:
			continue
		used.append(shojiki)
		all_shojiki = True
		for j in range(n):
			if not shojiki[j]:
				continue
			for k in range(a_s[i]):
				x, y = xss[j][k] - 1, yss[j][k]
				if y == 1:
					if shojiki[x] == False:
						all_shojiki = False
						break
				else:
					if shojiki[x] == True:
						all_shojiki = False
						break
		if all_shojiki:
			print(n - i)
			sys.exit()

	tmp_shojiki[i] = False

print(0)

Submission status: Runtime Error

Solution code:
import itertools



def main():
    N = int(input())
    A = [0]*N
    x = [0]*N
    y = [0]*N
    for i in range(N):
        A[i] = int(input())
        x_i = deque()
        y_i = deque()
        for j in range(A[i]):
            x_j, y_j = map(int, input().split())
            x_i.append(x_j)
            y_i.append(y_j)
        x[i] = list(x_i)
        y[i] = list(y_i)

    ret_max = 0
    p = itertools.product([0, 1], repeat=N)
    for l in p:
        mujun = True
        for i in range(N):
            for j in range(A[i]):
                n = x[i][j]
                flag = y[i][j]
                if l[n-1] != int(not flag ^ l[i]):
                    mujun = False
                    break
        if mujun:
            ret_max = max(ret_max, sum(l))
    print(ret_max)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
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+1,x,y])

from itertools import permutations, combinations,combinations_with_replacement,product
LL = list(product(range(2), repeat=N))

cnt = 0
for i in LL:
  ii = list(i)
  Ans =[]
  for j in L:
    if j[2]==1 and ii[j[0]-1]==1:
      k = 1
    elif j[2]==1 and ii[j[0]-1]==0:
      k = 0
    elif j[2]==0 and ii[j[0]-1]==1:
      k = 0
    elif j[2]==0 and ii[j[0]-1]==0:
      k = 1
    Ans.append([j[1],k])
  Ans.sort()
  for l in range(len(Ans)):
    if i[Ans[l][0]-1] != Ans[l][1]:
      flg = 0
      break
    else:
      flg = 1
#  print(i,flg,Ans)
  cnt = max(cnt,sum(i)*flg)
print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
xys = []
for k in range(n):
    a = int(input())
    xys.append([])
    for i in range(a):
        xy = list(map(int, input().split()))
        xy[0] -= 1
        if xy[1] == 0:
            xy[1] = -1
        xys[-1].append(xy)
        

best = 0
for l in range(n):
    hantei = [0 for _ in range(n)]
    hantei[l] = 1
#     xys = xys[1:] + [xys[0]]
    flag = 0
    que = [l]
    done = []
    while len(que) > 0:
        i = que[0]
        que = que[1:]    
        if i in done:
            continue
        a = xys[i]
        done.append(i)

#     for i, a in enumerate(xys):
        #print("---")
        #print("done", done)
        #print("que", que)
        #print("han", hantei)
        #print("flag", flag)
        #print("a", a)
        for k, b in enumerate(a):
            if b[0] not in done:
                que.append(b[0])
            #print("b", b)
            if hantei[b[0]] == 0:
                hantei[b[0]] = b[1]
                if b[1] == -1:
                    done.append(b[0])
                #print("hantei", hantei)
            else:
                if hantei[b[0]] == b[1]:
                    pass
#                     if hantei[i] == -1:
#                         flag = -1
#                         #print("bad***")
#                         break
                else:
                    if hantei[i] == 1:
                        flag = -1
                        #print("bad***")
                        break
                    else:
                        hantei[i] = -1
            if flag == -1:
                break
        if flag == -1:
            break
        #print("que", que)
    
    if flag == 0:
        for k in range(n):
            flag2 = -1
            if k not in done:
                if hantei[k] == 0:
                    flag2 = 0
                    for b in xys[k]:
                        if hantei[b[0]] == b[1]:
                            pass
                        else:
                            flag2 = -1
            if flag2 == 0:
                hantei[b[0]] = 1
                
    
    if flag == 0:
        if best < np.sum(np.array(hantei) == 1):
            best = np.sum(np.array(hantei) == 1)


print(best)

Submission status: Runtime Error

Solution code:
N = int(input())

xy = [x ,y] 
A = [0 for i in range(N)]

arr = [[0 for i in range(N)] for j in range(N)]

unkind = 0

for n in range(N):
    A[n] = int(input())
    for m in range(A[n]):
        S1,S2 = map(int, input().split())
        arr[n][S1 - 1] = S2

for n in range(A[n]):
    for l in range(A[n] + 1):
        if(arr[n][l] != arr[n + 1][l]):
            unkind += 1

        else:
            pass

print(N - unkind)
        
pass

Submission status: Runtime Error

Solution code:
# C - HonestOrUnkind2

N = int(input())
A = [0]*N
x = [0]*N
ans0 = [1] * N
ans = 0
ans1 = 1
for i in range(N):
    A[i] = int(input())
    x[i] = [list(map(int, input().split())) for j in range(A[i])]

#print(N,A,x)
#print(x[0],x[0][0],x[0][0][0])

for k in range(N):
    for l in range(N-1):
        # if A[k] == 1:
        #     for m in range
        #     if x[k][l][0]:
        #         if x[k][l][1] == 0:
        #             ans0[m] = ans0[m] * -1
        #         else:
        #             ans0[m] = ans0[m] * 1
        # else:
        for m in range(N): #対象選択
            if x[k][l][0] == m+1:
                if x[k][l][1] == 0:
                    ans0[m] = ans0[m] * -1
                else:
                    ans0[m] = ans0[m] * 1
#print(ans0)

for m in range(N):
    ans1 *= ans0[m]

if ans1 == 1:
    ans = 1

for m in range(N):
    if ans0[m] == 1:
        ans += ans0[m]
    else:
        pass
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
L = [[] for i in range(15)]
for i in range(n):
  for i in range(int(input())):
    x, y = map(int, input().split())
    L[x].append(y)
count = 0  
one = 0
for i in range(len(L)):
  if len(L[i]) == 2:
    count += 1
  elif len(L[i]) == 1:
    one += 1
if one == n:
  print(n-count-1)
else:
  print(n-count)

Submission status: Runtime Error

Solution code:
import numba

Submission status: Runtime Error

Solution code:
N = int(input())
nums = list(map(int, input().split()))

X=0
for i in range(N-1):
    for j in range(N):
        if (j > i):
            X+= nums[i] ^ nums[j]
            
if X< 1000000007:
    print(X)
else:
    print(str(X % (10**9 + 7)))

Submission status: Runtime Error

Solution code:

muzyun = 0
data = {}
num = int(input())
for i in range(num):
    words = int(input())
    for j in range(words):
        a, b = input().split(' ')
        if a not in data:
            data[a] = b
        elif data[a] != b:
            muzyun = muzyun + 1
            break
        #print(str(i+1) + ' ' + str(words) + ' ' + a + ' ' + b)

uso = 0
for i in data:
    uso = uso + int(data[i])
if uso == 0:
    print(num - 1)
else:
    print(num - muzyun)

Submission status: Runtime Error

Solution code:
import itertools

n = int(input())

a_tot = []
xy_tot =[]

for i in range(n):
    xy=[]
    a = int(input())
    a_tot.append(a)
    for i in range(a):
        xy_s = list(map(int, input().split()))
        xy.append(xy_s)
        xy_tot.append(xy)

all_list = list(itertools.combinations_with_replacement([1, 0], n))
ma = 0
for li in all_list:
    for j in range(n):
        if li[j] == 1:
            for k in range(a_tot[j]):
                if xy_tot[j][k][1] == li[k]:
                    pass
                else:
                    break
            else:
                continue
            break
    else:
            ma = max(ma, sum(li))
print(ma)

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
data_dict = {}
for i in range(1, n + 1):
    temp = int(input())
    temp_list = []
    for j in range(0, temp):
        x, y = map(int, input().split())
        temp_list.append(x)
        temp_list.append(y)
    data_dict[i] = temp_list
max_o_man = 0
for i in range(1, n + 1):
    check_dict = {}
    check_list = [-100] * n
    check_list[i-1] = 1
    check_dict[i] = 1
    count = 1
    for j in range(0, len(data_dict[i]), 2):
        check_dict[data_dict[i][j]] = data_dict[i][j+1]
        check_list[i-1] = 0
        if data_dict[i][j+1] == 1:
            count += 1
    flag = 1
    for k in range(0, n - 1):
        x = -1
        if 0 not in check_list:
            x = check_list.index(-100)
        else:
            x = check_list.index(0)
        check_list[x] = 1
        for j in range(0, len(data_dict[x + 1]), 2):
            if data_dict[x + 1][j] in check_dict:
                if check_dict[data_dict[x + 1][j]] != data_dict[x + 1][j+1]:
                    flag = 0
                    break
            else:
                check_dict[data_dict[x + 1][j]] = data_dict[x + 1][j+1]
                check_list[i-1] = 0
                if data_dict[i][j+1] == 1:
                    count += 1
        if flag == 0:
            break
    if flag == 1:
        if max_o_man < count:
            max_o_man = count
        if max_o_man == n:
            break
print(max_o_man)

Submission status: Runtime Error

Solution code:
import itertools

n = int(input())

a_tot = []
xy_tot =[]

for i in range(n):
    xy=[]
    a = int(input())
    a_tot.append(a)
    for i in range(a):
        xy_s = list(map(int, input().split()))
        xy.append(xy_s)
        xy_tot.append(xy)

all_list = list(itertools.combinations_with_replacement([1, 0], n))
ma = 0
for li in all_list:
    for j in range(n):
        if li[j] == 1:
            for k in range(a_tot[j]):
                if xy_tot[j][k][1] == li[k]:
                    pass
                else:
                    break
            else:
                pass
    else:
            ma = max(ma, sum(li))
print(ma)

Submission status: Runtime Error

Solution code:
N = int(input())
collect = []

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

ans = 0
for i in range(N):
    cand = collect[i]
    flag = True
    for j in cand:
	if not collect[j] == cand:
            flag = False
    if flag:
	ans = max(ans, len(cand))

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
L = [[] for i in range(15)]
for i in range(n):
  for i in range(int(input())):
    x, y = map(int, input().split())
    L[x].append(y)

count = 0    
for i in range(len(L)):
  if len(L[i]) == 2:
    count += 1
if count == 0:
  print(n-count-1)
else:
  print(n-count)

Submission status: Runtime Error

Solution code:
best = 0
for l in range(n):
    hantei = [0 for _ in range(n)]
    hantei[l] = 1
#     xys = xys[1:] + [xys[0]]
    flag = 0
    que = [l]
    done = []
    while len(que) > 0:
        i = que[0]
        a = xys[i]
        done.append(i)
        que = que[1:]
#     for i, a in enumerate(xys):
        #print("---")
        #print("done", done)
        #print("que", que)
        #print("han", hantei)
        #print("flag", flag)
        #print("a", a)
        for k, b in enumerate(a):
            if b[0] not in done:
                que.append(b[0])
            #print("b", b)
            if hantei[b[0]] == 0:
                hantei[b[0]] = b[1]
                if b[1] == -1:
                    done.append(b[0])
                    que.remove(b[0])
                #print("hantei", hantei)
            else:
                if hantei[b[0]] == b[1]:
                    pass
#                     if hantei[i] == -1:
#                         flag = -1
#                         #print("bad***")
#                         break
                else:
                    if hantei[i] == 1:
                        flag = -1
                        #print("bad***")
                        break
                    else:
                        hantei[i] = -1
            if flag == -1:
                break
        if flag == -1:
            break
        #print("que", que)
        
    if flag == 0:
        if best < np.sum(np.array(hantei) == 1):
            best = np.sum(np.array(hantei) == 1)


print(best)

Submission status: Runtime Error

Solution code:
import itertools

n = int(input())

a_tot = []
xy_tot =[]

for i in range(n):
    xy=[]
    a = int(input())
    a_tot.append(a)
    for i in range(a):
        xy_s = list(map(int, input().split()))
        xy.append(xy_s)
        xy_tot.append(xy)

all_list = list(itertools.combinations_with_replacement([1, 0], n))
ma = 0
for li in all_list:
    for j in range(n):
        if li[j] == 1:
            for k in range(a_tot[j]):
                if xy_tot[j][k][1] == li[k]:
                    pass
                else:
                    break
        else:
            ma = max(ma, sum(li))
print(ma)

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
a = {}
for i in range(n):
  n2 = int(input())
  for n3 in range(n2):
    a1, a2 = (int(i) for i in input().split())
    if a1 in a:
    	a[a1] = { a2 : a2 + 1 } 
    else:
      	a[a1] = { a2 : 1 } 

for nn in range(len(a), 1,1):
  if a[nn][0] == a[nn + 1][0] and a[nn][1] == a[nn + 1][1]:
    if (nn == len(a) - 1):
    	print(0)
    	sys.exit(1)
    continue
  else:
    print(max(a) - 1)
    sys.exit(1)

print(0)

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
l = []
for _ in range(n):
    m = int(input())
    l.append([list(map(int, input().split())) for _ in range(m)])
# for i in range(1):
for i in range(2 ** n - 1):
    sj = [True] * n
    bin_i = format(i, 'b').rjust(n, "0")
    for j in range(n):
        sj[j] = (bin_i[j] == "0")
        for k in range(n):
            check = True
            for x in range(len(l[k])):
                # print(j, k, x)
                if sj[k] and sj[l[k][x][0]] and l[k][x][1] == 0:
                    check = False
                    break
                elif sj[k] and not(sj[l[k][x][0]]) and l[k][x][1] == 1:
                    check = False
                    break
                elif (not (sj[k])) and (not(sj[l[k][x][0]])) and l[k][x][1] == 1:
                    check = False
                    break
                elif (not (sj[k])) and (sj[l[k][x][0]]) and l[k][x][1] == 0:
                    check = False
                    break
    if check:
        print(n - i)
        exit()
print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
sum = 0
cnt = []
for i in range(N-1):
    if A[i] in cnt:
        sum += a
    else:
        for j in range(i+1, N):
            a = A[i] ^ A[j]
            sum += a
print(sum%1000000007)

Submission status: Runtime Error

Solution code:
from collections import deque
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
C = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        C[i][j] = A[i][j]-B[i][j]
M = 80*(H+W)
dp = [[set() for i in range(W)] for j in range(H)]
c = C[0][0]
dp[0][0].add(c)
dp[0][0].add(-c)
for s in range(1, H+W):
    for b in range(max(s-H+1, 0), min(s, W)):
        a = s-b
        c = C[a][b]
        if a>=1:
            for i in dp[a-1][b]:
                dp[a][b].add(i+c)
                dp[a][b].add(i-c)

        if b>=1:
            for i in dp[a][b-1]:
                dp[a][b].add(i+c)
                dp[a][b].add(i-c)
ans = min(abs(i) for i in dp[-1][-1])
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
dmap = {}
for i in range(0, n):
    an = int(input())
    for j in range(0, an):
        x, y = input().split()
        x = int(x)
        if (x not in dmap):
            dmap[x] = ''
        dmap[x] += y
for i in range(0, n):
    if (i not in dmap):
        continue
    if ('0' not in dmap[i]):
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
honest = 0
arr = []
for i in range(N):
    A = int(input())
    for j in range(A):
        pre_Honest = 0
        pre_unKind = 0
        x,y = map(int,input().split())
        if y == 1:
            pre_Honest +=1
        else:
            pre_unKind +=1
        arr.append(y)
    if pre_Honest > pre_unKind:
        honest +=pre_Honest
if arr.count(0) == len(arr):
    print(1)
else:
    print(honest)

Submission status: Runtime Error

Solution code:
N = int(input())
honest = 0
arr = []
for i in range(N):
    A = int(input())
    for j in range(A):
        pre_Honest = 0
        pre_unKind = 0
        x,y = map(int,input().split())
        if y == 1:
            pre_Honest +=1
        else:
            pre_unKind +=1
        arr.append(y)
    if pre_Honest > pre_unKind:

Submission status: Runtime Error

Solution code:
import sys
from itertools import islice
read = map(int, sys.stdin.read().split())

N = next(read)
candidates = [format(i, 'b').zfill(N) for i in range(2 ** N)]
A = [0] * 3
xy = [[] for _ in range(N)]
for i in range(N):
    A[i] = next(read)
    xy[i].extend(list(islice(read, A[i] * 2)))

answer = 0

for candidate in candidates:
    tmp = 0
    truth = set()
    false = set()
    for k in range(N):
        if candidate[k] == '1':
            truth.add(k)
            for i, j in zip(*[iter(xy[k])] * 2):
                i -= 1
                if j == 1:
                    if i in false:
                        break
                    truth.add(i)
                else:
                    if i in truth:
                        break
                    false.add(i)
            else:
                continue
            break
        else:
            if k in truth:
                break
            false.add(k)
    else:
        if len(truth) > answer:
            answer = len(truth)

print(answer)

Submission status: Runtime Error

Solution code:
N=int(input())
syougen=[]
for i in range(N):
  A=int(input())
  X=[list(map(int,input().split())) for i in range(A)]
  syougen.append(X)

def search(l):
  global seigo
  for x,y in l:
    if y==1:
      seigo[x-1]=1
    else:
      seigo[x-1]=0
def chk(l):
  global seigo
  for x,y in l:
    if seigo[x-1] != y:
      if seigo[x-1]==100:
        seigo[x-1]=y
        if y==1:
          global syougen
          if chk(syougen[x-1],seigo):
            return True
      else:
      	return True
  return False

ans=0
for i in range(N):
  flg=True
  seigo=[100]*N
  _ans=0
  seigo[i]=1
  search(syougen[i])
  for j in range(N):
    if i==j:
      continue
    if seigo[j]==1:
      if chk(syougen[j]):
        flg=False
        break
    if seigo[j]==100:
      continue
  if flg:
    _ans=sum(seigo)%100
    if ans<_ans:
      ans=_ans
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [0 for _ in range(n)]
xy = [[] for _ in range(n)]
for i in range(n):
  a[i] = int(input())
  for j in range(a[i]):
    xy[i].append(list(map(int, input().split())))
#print(xy)

for i in range(2**n-1, -1, -1):
  num = format(i, '03b')
  #print(num)
  flag = False
  for j in range(n):
    #print(num[j])
    if int(num[j]) == 1:
      for k in range(a[j]):
        #print(xy[j][k])
        if int(num[xy[j][k][0]-1]) != xy[j][k][1]:
          flag = True
          break
      if flag:
        break
  if not flag:
    cnt = 0
    for l in range(n):
      if int(num[l]):
        cnt += 1
    break
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
a = {}
for i in range(n):
  n2 = int(input())
  for n3 in range(n2):
    a1, a2 = (int(i) for i in input().split())
    if a1 in a:
    	a[a1] = a[a1] +  1
    else:
      	a[a1] = 1

max_a = max(a)

if max(a) is min(a):
  print(0)
else:
	print(max_a - 1)

Submission status: Runtime Error

Solution code:
N = int(input())
info = [[] for _ in range(N)]
people = [-1] * N
for i in range(N):
    A = int(input())
    for j in range(A):
        x , y = map(int,input().split())
        info[i].append([A , x - 1 , y])
#print(info[0][0][0])
ans = 0
for i in range(2 ** N):
    cnt = 0
    Flag = True
    for j in range(N):
        if i >> j & 1:
            cnt += 1
            people[j] = 1
        else:
            people[j] = 0
    for j in range(N):
        if i >> j & 1:
            info_num = info[j][0][0]
            for k in range(info_num):
                judge = info[j][k][2]
                origin = people[info[j][k][1]]
                if judge != origin:
                    Flag = False
                    break
        if not Flag:
            break
    if Flag:
        if ans < cnt:
            ans = cnt
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
readline = sys.stdin.readline


N = int(readline())
A = []
X, Y = [], []
for i in range(N):
    a = int(readline())
    A.append(a)
    x, y = zip(*[list(map(int, readline().split())) for j in range(a)])
    x = [_x - 1 for _x in x]
    X.append(x)
    Y.append(y)

while True:
    pass
M = 2 ** N
count = 0
for code in range(M - 1, -1, -1):
    contra = False
    for i in range(N):
        if ((code >> i) & 1) == 1:
            x, y = X[i], Y[i]
            for j in range(len(x)):
                if y[j] != ((code >> x[j]) & 1):
                    contra = True
                    break
            if contra:
                break
    if not contra:
        _count = 0
        for i in range(N):
            _count += ((code >> i) & 1)
        count = max(count, _count)

print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
honest = 0
arr = []
for i in range(N):
    A = int(input())
    for i in range(A):
        pre_Honest = 0
        pre_unKind = 0
        x,y = map(int,input().split())
        if y == 1:
            pre_Honest +=1
        else:
            pre_unKind +=1
        arr.append(y)
    if pre_Honest > pre_unKind:
        honest +=pre_Honest
if arr.count(0) == len(arr):
    print(1)
else:
    print(honest)

Submission status: Runtime Error

Solution code:
n=int(input())
xy=[[] for _ in range(n)]
p=[-1 for _ range(n)]

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

    
res=0
for i in range(n):
  for j in range(a):
    x,y=xy[i][j]
    
    if(p[x-1]==-1):
      p[x-1]=y
      res+=1
    elif(p[x-1]==y):
      pass
    else:
      res-=1
print(res)

Submission status: Runtime Error

Solution code:
n = int(input())

stm = [[] for i in range(n)]

def possible(honest):
    for i in range(n):
        if honest[i] == '0':
            continue
        for j in range(len(stm[i])):
            if stm[i][j][1] == 1 and honest[stm[i][j][0]-1] == '0':
                return False
            elif stm[i][j][1] == 0 and honest[stm[i][j][0]-1] == '1':
                return False
    return True

            

for i in range(n):
    a = int(input())
    x,y = map(int, input().split())
    stm[i].append([x,y])
   
count = 0
for k in range(2**n):
    hon = list(bin(k)[2:])
    hon = ['0']*(n-len(hon)) + hon
    if possible(hon):
        print(hon)
        count = max(count, sum([int(x) for x in hon]))
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
lsx = []
lsy = []
ans = 0
def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]
if n==1:
    a = int(input())
    for i in range(a):
    	x,y=map(int,input().split())
      if y==0:
          print(0)
      else:
          print(1)
      break
else:
    for i in range(n):
        a = int(input())
        for j in range(a):
            x,y = map(int,input().split())
            lsx.append(x)
            lsy.append(y)
            if x in lsx:
                p = 0
                p2 = 0
                for k in my_index_multi(lsx,x):
                    if lsy[k] == 1:
                        p+=1
                    else:
                        p2+=1                
                ans+=min(p,p2)
    test=0        
    for i in lsy:
        if i == 0:
            test+=1
    if test==len(lsy):
        print(1)
    else:
        print(n-ans)

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
readline = sys.stdin.readline


N = int(readline())
A = []
X, Y = [], []
for i in range(N):
    a = int(readline())
    A.append(a)
    x, y = zip(*[list(map(int, readline().split())) for j in range(a)])
    x = [_x - 1 for _x in x]
    X.append(x)
    Y.append(y)


M = 2 ** N
count = 0
for code in range(M - 1, -1, -1):
    contra = False
    for i in range(N):
        if ((code >> i) & 1) == 1:
            x, y = X[i], Y[i]
            for j in range(len(x)):
                if y[j] != ((code >> x[j]) & 1):
                    contra = True
                    break
            if contra:
                break
    if not contra:
        _count = 0
        for i in range(N):
            _count += ((code >> i) & 1)
        count = max(count, _count)

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 0

for i in range(n):
    count = 0
    a = int(input())
    for j in range(a):
        x, y = (int(j) for j in input().split())
        if y == 0:
            break
        count += 1
        if count == a:
            ans += 1

print(ans)