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())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  #l=[1]*n
  #for j in range(i, n-i):
    #if l[j]==0:continue
    #for k in range(A[j]):
      #b=X[j][k]
      #l[b] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  #l=[1]*n
  for j in range(i, n-i):
    #if l[j]==0:continue
    for k in range(A[j]):
      #b=X[j][k]
      #l[b] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  l=[1]*n
  for j in range(i, n-i):
    #if l[j]==0:continue
    for k in range(A[j]):
      #b=X[j][k]
      #l[b] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  l=[1]*n
  for j in range(i, n-i):
    if l[j]==0:continue
    for k in range(A[j]):
      #b=X[j][k]
      #l[b] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  l=[1]*n
  for j in range(i, n-i):
    if l[j]==0:continue
    for k in range(A[j]):
      b=X[j][k]
      l[b] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  l=[1]*n
  for j in range(i, n-i):
    if l[j]==0:continue
    for k in range(A[j]):
      b=X[j][k]
      #l[b] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
import itertools
N =int(input())
XY = []
for _ in range(N):
    a = int(input())
    if a == 0:
        XY.append(list(map(int,input().split)))
    else:
        xy = []
        for _ in range(a):
            xy.append(list(map(int,input().split())))
        XY.append(xy)
    
    

bit_list = list(itertools.product([0, 1], repeat=N))


answer = 0
for b in bit_list:
    for i in range(N):
        for x,y in XY[i]:
            if b[i] ==1:
                if b[x-1] == y:
                    continue
                else:
                    break
        else:
            continue
        break
    else:
        answer = max(sum(b),answer)
print(answer)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  l=[1]*n
  for j in range(i, n-i):
    if l[j]==0:continue
    for k in range(A[j]):
      b=X[j][k]
      l[b] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
import itertools
N =int(input())
XY = []
for _ in range(N):
    a = int(input())
    if a == 0:
        XY.append(list(map(int,input().split)))
    else:
        xy = []
        for _ in range(a):
            xy.append(list(map(int,input().split())))
        XY.append(xy)
    
    

bit_list = list(itertools.product([0, 1], repeat=N))


answer = 0
for b in bit_list:
    for i in range(N):
        for x,y in XY[i]:
            if b[i] ==1:
                if b[x-1] == y:
                    continue
                else:
                    break
        else:
            continue
        break
    else:
        answer=(sum(b))

print(max(0,answer))

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
#for i in range(n):
#l=[1]*n
  #for j in range(i, n-i):
    #if l[j]==0:continue
    #for k in range(A[j]):
l[X[1][1]] *= Y[1][1]
#if c<l.count(1):
  #c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
import itertools
N =int(input())
XY = []
for _ in range(N):
    a = int(input())
    if a == 0:
        XY.append(list(map(int,input().split)))
    else:
        xy = []
        for _ in range(a):
            xy.append(list(map(int,input().split())))
        XY.append(xy)
    
    

bit_list = list(itertools.product([0, 1], repeat=N))


answer = 0
for b in bit_list:
    for i in range(N):
        for x,y in XY[i]:
            if b[i] ==1:
                if b[x-1] != y:
                    break
        else:
            continue
        break
    else:
        answer=(sum(b))

print(max(0,answer))

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
#for i in range(n):
l=[1]*n
  #for j in range(i, n-i):
    #if l[j]==0:continue
    #for k in range(A[j]):
l[X[1][1]] *= Y[1][1]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
import itertools
N =int(input())
XY = []
for _ in range(N):
    a = int(input())
    if a == 0:
        XY.append(list(map(int,input().split)))
    else:
        xy = []
        for _ in range(a):
            xy.append(list(map(int,input().split())))
        XY.append(xy)
    
    

bit_list = list(itertools.product([0, 1], repeat=N))


answer = 0
for b in bit_list:
    for i in range(N):
        for x,y in XY[i]:
            if b[i] ==1:
                if b[x-1] != y:
                    break
        else:
            continue
        break
    else:
        answer=(sum(b))

print(max(0,answer)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  l=[1]*n
  for j in range(i, n-i):
    if l[j]==0:continue
    for k in range(A[j]):
    　　l[X[j][k]] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
import itertools
N =int(input())
XY = []
for _ in range(N):
    a = int(input())
    if a == 0:
        XY.append(list(map(int,input().split)))
    else:
        xy = []
        for _ in range(a):
            xy.append(list(map(int,input().split())))
        XY.append(xy)
    
    

bit_list = list(itertools.product([0, 1], repeat=N))


ans = 0
answer = 0
for b in bit_list:
    for i in range(N):
        for x,y in XY[i]:
            if b[i] ==1:
                if b[x-1] != y:
                    break
        else:
            continue
        break
    else:
        answer=(sum(b))

print(answer)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[]
for i in range(n):
  A=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
   # 　　l[X[j][k]] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = []
x = []
y = []


for i in range(0,n):
  b = int(input())
  a.append(b)
  for j in range(0,a[i]):
    x1,y1=[int(j) for j in input().split()]
    x.append(x1)
    y.append(y1)
    
#print(x)
#print(y)

l = len(x)

z = []
m = []
for i in range(0,l):
  s = 0
  t = 0
  for j in range(0,l):
    if x[j] == i+1:
      if y[j] == 0:
        s += 1
      elif y[j] == 1:
        t += 1
  z.append((s,t))
  
for i in range(0,n):
  m.append( min(z[i]) )
  
ans = 0

for i in range(0,n):
  count = 0
  for j in range(0,n):
    if m[j] == i:
      count += 1
  if count > ans:
    ans = count

#print(z)
#print(m)

if int(max(m)) == 0:
  print(int(n/2))
elif ans == n:
  print("0")
else:
  print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[]
for i in range(n):
  A=int(input())
  x=[]
  y=[]
  for j in range(A[i]):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
   # 　　l[X[j][k]] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[]
 for i in range(n):
  A=int(input())
  x=[]
  y=[]
  for j in range(A[i]):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
   # 　　l[X[j][k]] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
#A=[]
 for i in range(n):
  A=int(input())
  x=[]
  y=[]
  for j in range(A[i]):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
   # 　　l[X[j][k]] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
#A=[]
#for i in range(n):
A=int(input())
x=[]
y=[]
  #for j in range(A[i]):
x,y=[int(s) for s in input().split()]
X.append(x)
Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
   # 　　l[X[j][k]] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
#A=[]
#for i in range(n):
A=int(input())
x=[]
y=[]
  #for j in range(A[i]):
x,y=[int(s) for s in input().split()]
  #X.append(x)
  #Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
   # 　　l[X[j][k]] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
#A=[]
for i in range(n):
  A=int(input())
  #x=[]
  #y=[]
  #for j in range(A[i]):
    #x,y=[int(s) for s in input().split()]
  #X.append(x)
  #Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
   # 　　l[X[j][k]] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n  = int(input())
count = []
contradiction = False

if 1 <= n <= 15:
  for i in range(0,n):
    i = int(input())
    for j in range(0,i):
      x,y= map(int, input().strip().split())
      if y == 1:
        count.append(x)  
      else:
        if count[j] == 0:
          count.append(x)
          contradiction = True
        else:
          contradiction = False
          


if contradiction == True:
  print(1)
else:
  print(len(count))

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
#A=[]
#for i in range(n):
  a=int(input())
  #x=[]
  #y=[]
  #for j in range(A[i]):
    #x,y=[int(s) for s in input().split()]
  #X.append(x)
  #Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
   # 　　l[X[j][k]] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = []
x = []
y = []


for i in range(0,n):
  b = int(input())
  a.append(b)
  for j in range(0,a[i]):
    x1,y1=[int(j) for j in input().split()]
    x.append(x1)
    y.append(y1)
    
#print(x)
#print(y)

l = len(x)

z = []
m = []
for i in range(0,l):
  s = 0
  t = 0
  for j in range(0,l):
    if x[j] == i+1:
      if y[j] == 0:
        s += 1
      elif y[j] == 1:
        t += 1
  z.append((s,t))
  
for i in range(0,n):
  m.append( min(z[i]) )
  
max = 0

for i in range(0,n):
  count = 0
  for j in range(0,n):
    if m[j] == i:
      count += 1
  if count > max:
    max = count

#print(z)
#print(m)
if min(m) == 0:
  print(int(n/2))
elif max == n:
  print("0")
else:
  print(max)

Submission status: Runtime Error

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


#print(li)

ans = 0
for bit in range(2**N):
	ok = True
	is_honest = [(bit>>i) & 1 for i in range(N)[::-1]]
	#print(is_honest)
	for i in range(N):
		if not is_honest[i]:
			continue
		for x, y in li[i]:
			if is_honest[x] != y:
				ok = False
	if ok:
		ans = max(ans, sum(is_honest))
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    S = [[] * N for i in range(N)]
    ans = 0

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

    P = [0]*N

    for i in range(2**N):
        for j in range(N):
            if P[j] == 0:
                P[j] = 1
                break
            else:
                P[j] = 0

        if sum(P) <= ans:
            continue
        flag = 0
        for p in range(len(P)):
            if P[p] == 1:
                for s in S[p]:
                    if s[1]!= P[s[0]]:
                        flag = 1
        if flag == 1:
            continue
        else:
            ans = sum(P)

    print(ans)


 
if name == 'main':
    main()

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    S = [[] * N for i in range(N)]
    ans = 0

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

    P = [0]*N

    for i in range(2**N):
        for j in range(N):
            if P[j] == 0:
                P[j] = 1
                break
            else:
                P[j] = 0

        if sum(P) <= ans:
            continue
        flag = 0
        for p in range(len(P)):
            if P[p] == 1:
                for s in S[p]:
                    if s[1]!= P[s[0]]:
                        flag = 1
        if flag == 1:
            continue
        else:
            ans = sum(P)

    print(ans)


 
if name == 'main':
    main()

Submission status: Runtime Error

Solution code:
from itertools import product

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

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)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
#A=[]
#for i in range(n):
  A=int(input())
  #x=[]
  #y=[]
  #for j in range(A[i]):
    #x,y=[int(s) for s in input().split()]
  #X.append(x)
  #Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
   # 　　l[X[j][k]] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[]
#for i in range(n):
  A=int(input())
  x=[]
  y=[]
  #for j in range(A[i]):
    #x,y=[int(s) for s in input().split()]
  #X.append(x)
  #Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
   # 　　l[X[j][k]] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[]
for i in range(n):
  A=int(input())
  x=[]
  y=[]
  for j in range(A[i]):
    #x,y=[int(s) for s in input().split()]
  #X.append(x)
  #Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
   # 　　l[X[j][k]] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[]
for i in range(n):
  A=int(input())
  x=[]
  y=[]
  for j in range(A[i]):
    x,y=[int(s) for s in input().split()]
  #X.append(x)
  #Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
   # 　　l[X[j][k]] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

import random

def check(index_person, x_true_or_false, bin_str):
    return (bin_str[index_person] == x_true_or_false)


def main():
    n = int(input().strip())
    ll_xy = [[] for _ in range(n)]
    for i in range(n):
        a = int(input().strip())
        for j in range(a):
            l = list(map(int, input().strip().split()))
            l[0]-=1
            ll_xy[i].append(l)
    #eprint("ll_xy ",end=": ")
    #eprint(ll_xy)

    cnt=0
    ans=0
    for i in range(2 ** n):     # 場合ループ
        #eprint("i ",end=": ")
        #eprint(i,end=" and ")

        bin_str = format(i,'b').zfill(n)
        #eprint("bin_str ",end=": ")
        #eprint(bin_str)
        failure_flag=0
        for j in range(n):      # 人ループ
            if bin_str[j]=="1":   # その人を「真実の人」だと仮定している場合
                a=len(ll_xy[j])
                for k in range(a):  # 証言ループ
                    #eprint("証言ループ")
                    p=int(bin_str[ll_xy[j][k][0]])
                    if ll_xy[j][k][1] == 0:
                        if check(p,"0",bin_str):
                            pass
                        else:
                            failure_flag=1

                    elif ll_xy[j][k][1] == 1:
                        if check(p,"1",bin_str):
                            pass
                        else:
                            failure_flag=1
                    else:
                        try:
                            #eprint("error1")
                        except Exception:
                            #eprint("errorE")
        if failure_flag==0:
            cnt+=1
            ans_temp=0
            for x in bin_str:
                if x=="1":
                    ans_temp+=1
            ans=max(ans_temp,ans)
            # #eprint("success!")
    #eprint("cnt ",end=": ")
    #eprint(cnt)
    print(ans)
    return
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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




ans = 0
for bit in range(2**N):
	ok = True
	is_honest = [(bit>>i) & 1 for i in range(N)]
	#print(is_honest)
	for i in range(N):
		if not is_honest[i]:
			continue
		for x, y in li[i]:
			if is_honest[x] != y:
				ok = False
	if ok:
		ans = max(ans, sum(is_honest))
print(ans)

Submission status: Runtime Error

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


net = [[0] * N] * N
# ナップザック？

ans = 0
for bit in range(2**N):
	ok = True
	is_honest = [(bit>>i) & 1 for i in range(N)]
	print(is_honest)
	for i in range(N):
		if not is_honest[i]:
			continue
		for x, y in li[i]:
			if is_honest[x] != y:
				ok = False
	if ok:
		ans = max(ans, sum(is_honest))
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [0]*n
x = [[] for i in range(n)]
y = [[] for i in range(n)]
for i in range(n):
    a[i] = int(input())
    for j in range(a[i]):
        tmp1,tmp2 = list(map(int,input().split()))
        x[i].append(tmp1-1)
        y[i].append(tmp2)

ans = 0
honest = [0]*n
cnt=0
for i in range(2**n): #bit全探索
    for j in range(n):
        if((i>>j)&1):
            honest[j] = 1
            cnt+=1
        else:
            honest[j] = 0
            
        f = True
        for k in range(n):
          	if honest[k]!=1:
                f = False
                break
            for l in range(a[k]):
                if( and y[k][l]!=honest[x[k][l]]):
                    f = False
                    break
        	if f:
            	ans = max(ans,cnt)
        cnt=0

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

testimony_dict = {}
for i in range(n):
    a = int(input())
    testimony_dict[i + 1] = []
    for j in range(a):
        xy = input().split(' ')
        testimony_dict[i + 1].append(xy)

max_valid_bin = ''
for i in range(2 ** n - 1, 0, -1):
    is_valid = True
    bin_i = format(i, f'0{n}b')
    for j in range(1, len(bin_i) + 1):
        if bin_i[j - 1] == '1':
            for xy_list in testimony_dict[j]:
                if bin_i[int(xy_list[0]) - 1] != xy_list[1]:
                    is_valid = False
    if is_valid:
        max_valid_bin = bin_i
        break

print(len([i for i in max_valid_bin if i == '1']))

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
Y=[]
A=[]
for i in range(n):
  A=int(input())
  x=[]
  y=[]
  for j in range(A[i]):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  l=[1]*n
  for j in range(i, n-i):
    if l[j]==0:continue
    for k in range(A[j]):
    　　l[X[j][k]] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n = int(input())

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

def count(honest):
	count = 0
	for v in honest:
		if v == 2:
			count += 1
	return count

def checkHonest(sayArray, honest):
	for x, y in sayArray:
		if y == 2 and honest[x] != 2:
			return False
	return True

def checkHonestAll(sayTable, honest):
	for i in range(n):
		h = honest[i]
		if h != 2:
			continue
		sayArray = sayTable[i]
		for x, y in sayArray:
			if y != honest[x]:
				return False
	return True

def setHonest(sayArray, honest):
	for x, y in sayArray:
		honest[x] = y

def search(sayTable, honest, i):
	if i >= n:
		if checkHonestAll(sayTable, honest):
			return count(honest)
		else:
			return 0

	count = 0
	h = honest[i]
    sayArray = sayTable[i]
	if (h == 0 or h == 2) and checkHonest(sayArray, honest):
		copyHonest = honest[:]
		setHonest(sayArray, copyHonest)
		copyHonest[i] = 2
		c = search(sayTable, copyHonest, i+1)
		if count < c:
			count = c

	honest[i] = 1
	c = search(sayTable, honest, i+1)
	if count < c:
		count = c
	return count

print(search(sayTable, [0] * n, 0));

Submission status: Runtime Error

Solution code:
n=int(input().strip())
X=[]
Y=[]
A=[]
for i in range(n):
  A=int(input().strip())
  x=[]
  y=[]
  for j in range(A[i]):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  l=[1]*n
  for j in range(i, n-i):
    if l[j]==0:continue
    for k in range(A[j]):
    　　l[X[j][k]] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
n = int(input())

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

def count(honest):
	count = 0
	for v in honest:
		if v == 2:
			count += 1
	return count

def checkHonest(sayArray, honest):
	for x, y in sayArray:
		if y == 2 and honest[x] != 2:
			return False
	return True

def checkHonestAll(sayTable, honest):
	for i in range(n):
		h = honest[i]
		if h != 2:
			continue
		sayArray = sayTable[i]
		for x, y in sayArray:
			if y != honest[x]:
				return False
	return True

def setHonest(sayArray, honest):
	for x, y in sayArray:
		honest[x] = y

def search(sayTable, honest, i):
	if i >= n;
		if checkHonestAll(sayTable, honest):
			return count(honest)
		else:
			return 0

	count = 0
	h = honest[i]
    sayArray = sayTable[i]
	if (h == 0 or h == 2) and checkHonest(sayArray, honest):
		copyHonest = honest[:]
		setHonest(sayArray, copyHonest)
		copyHonest[i] = 2
		c = search(sayTable, copyHonest, i+1)
		if count < c:
			count = c

	honest[i] = 1
	c = search(sayTable, honest, i+1)
	if count < c:
		count = c
	return count

print(search(sayTable, [0] * n, 0));

Submission status: Runtime Error

Solution code:
n=int(input().strip())
X=[]
Y=[]
A=[]
for i in range(n):
  a=int(input().strip())
  A.append(a)
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  l=[1]*n
  for j in range(i, n-i):
    if l[j]==0:continue
    for k in range(A[j]):
    　　l[X[j][k]] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Runtime Error

Solution code:
from itertools import product # 直積をインポートしている

N = int(input())
A = [[] for i in range(N)] # 初期化

for i in range(N): # 何人分
    ai = int(input()) # いくつ証言を受け取るか
    for j in range(ai): 
        x, y = map(int, input().split())
        x = x - 1 # 0スタートにするため
        A[i].append([x, y])
        
# ここから判定
ans = 0
for pattern in product([0, 1], repeat=N):
    num = pattern.count(1) # pattern 内の 1 の数
    contradictions = False
    for i, testimony in enumerate(A):
        if pattern[i] == 0:
            continue
        for t in testimony:
            x, y = t
            if pattern[x] != Y ^ (1- pattern[i]):
                contradictions  = True
                break
        if contradictions:
            break
    if contradictions:
        continue
    ans = max(ans, num)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

def count(honest):
	count = 0
	for v in honest:
		if v == 2:
			count += 1
	return count

def checkHonest(sayArray, honest):
	for x, y in sayArray:
		if y == 2 and honest[x] != 2:
			return False
	return True

def checkHonestAll(sayTable, honest):
	for i in range(n):
		h = honest[i]
		if h != 2:
			continue
        sayArray = sayTable[i]
		for x, y in sayArray:
			if y != honest[x]:
				return False
	return True

def setHonest(sayArray, honest):
	for x, y in sayArray:
		honest[x] = y

def search(sayTable, honest, i):
	if i >= n;
		if checkHonestAll(sayTable, honest):
			return count(honest)
		else:
			return 0

	count = 0
	h = honest[i]
    sayArray = sayTable[i]
	if (h == 0 or h == 2) and checkHonest(sayArray, honest):
		copyHonest = honest[:]
		setHonest(sayArray, copyHonest)
		copyHonest[i] = 2
		c = search(sayTable, copyHonest, i+1)
		if count < c:
			count = c

	honest[i] = 1
	c = search(sayTable, honest, i+1)
	if count < c:
		count = c
	return count

print(search(sayTable, [0] * n, 0));

Submission status: Runtime Error

Solution code:
n=int(input().strip())
X=[]
Y=[]
A=[]
for i in range(n):
  A[i]=int(input().strip())
  x=[]
  y=[]
  for j in range(A[i]):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  l=[1]*n
  for j in range(i, n-i):
    if l[j]==0:continue
    for k in range(A[j]):
    　　l[X[j][k]] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)