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:
if __name__ == '__main__':
    n = int(input())

    testimony = {}
    for i in range(n):
        a = int(input()) # 証言数
        for j in range(a):
            who, ans = list(map(int, input().split(' ')))
            if j == 0:
                testimony[i + 1] = [{
                    'who': who,
                    'ans': ans
                }]
            else:
                testimony[i + 1].append({
                    'who': who,
                    'ans': ans
                })

    # print(testimony)
    # testimony = {1: [{'who': 2, 'ans': 1}], 2: [{'who': 1, 'ans': 1}], 3: [{'who': 2, 'ans': 0}]}

    max_honest = 0
    for i in reversed(range(2 ** n)):
        check_list = bin(i)[2:].zfill(n)
        # print(check_list) # 000 - 111
        ng_flag = 0
        for j in range(n):
            if check_list[j] == '1':
                for k in testimony[j + 1]: #正直者j +1さんの意見を順にチェック
                    if check_list[k['who'] - 1] != str(k['ans']):
                        ng_flag = 1
                        break
        if ng_flag == 0:
            if check_list.count('1') > max_honest:
                max_honest = check_list.count('1')

    print(max_honest)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    n = int(input())

    info = {}
    for i in range(n):
        a = int(input())
        for j in range(a):
            x, y = list(map(int, input().split(' ')))
            if j == 0:
                info[i] = [(x, y)]
            else:
                info[i].append((x, y))

    # print(info)

    max_p = 0
    for i in reversed(range(2 ** n)):
        check_list = bin(i)[2:].zfill(n)
        # print(check_list)
        ng_flag = 0
        for j in range(n):
            if check_list[n - j - 1] == '1':
                for k in info[j]:
                    if check_list[n - k[0]] != str(k[1]):
                        ng_flag = 1
                        break
        if ng_flag == 0:
            if check_list.count('1') > max_p:
                max_p = check_list.count('1')

    print(max_p)

Submission status: Runtime Error

Solution code:
N = int(input())

L = [0] * N

for i in range(N):
  A = int(input())
  #print(i)
  L[i] = [list(map(int, input().split()))]
  for j in range(1,A):
    L[i].append(list(map(int, input().split())))
    
#print(L)

ans = 0
for i in range(2**N):
  pat = str(format(i, '0' + str(N) + 'b'))
  flg = True
  #S = [-1] * (N)
  for j in range(N):
    if pat[j] == "1": # trueman
      for rule in L[j]:
        if pat[rule[0]-1] == "0" and rule[1] == 1:
          flg = False
          break
        if pat[rule[0]-1] == "1" and rule[1] == 0:
          flg = False
          break
  #print("XXX", flg, pat, j)
  if flg:
    work = 0
    for ch in pat:
      if ch == "1":
        work += 1
    #print("XXX", flg, pat, j, work)
    ans = max(ans, work)
    
print(ans)

Submission status: Runtime Error

Solution code:
import sys, itertools
input = sys.stdin.readline

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

ans = 0

for p in itertools.product([1,0], repeat=n):
  ok = 1
  for l in ll:
    if p[l[0]] == 1 and p[l[1]] != l[2]:
      ok = 0
      break
  if ok:
    ans = max(ans, sum(p))

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

l = []
for i in range(2**n,,-1):
  l += ['{:0=3}'.format(int(str(bin(i))[2:]))]

print(l)

Submission status: Runtime Error

Solution code:
def dudge(k):
    for i in reversed(range(n)):
        p = (k >> i) % 2
        if p == 0: continue

        for claim in xy[i]:
            x = claim[0]
            y = claim[1]

            truth = (k >> x-1) % 2
            if truth == 1 and y == 0:
                return False
            elif truth == 0 and y == 1:
                return False
    return True


n = int(input())

xy = []
for i1 in range(n):
    ai = int(input())
    xy.append([])

    for i2 in range(ai):
        xi,yi = map(int, input().split())
        xy[i1].append((xi, yi))


        result = 0
for k in reversed(range(1 << n)):

    if dudge(k):
        l = [i for i in range(n) if (k >> i) % 2 == 1]
        result = max(result, len(l))

print(result)

Submission status: Runtime Error

Solution code:
import itertools

n = input()
array = []
for i in range(n):
  t = input()
  array.append(set())
  for j in range(t):
    tmp = list(map(int, input().split(" ")))
    if tmp[1] == 1:
      array[i].add(tmp[0])
      
allcombs = list(itertools.product([0, 1], repeat=n))
max_val = 0
for comb in allcombs:
  
  if sum(comb) <= max_val:
    continue
  
  for i, j in enumerate(comb):
    broke = False
    if j == 1:
      for k in array[i]:
        if comb[k] == 0:
          broke = True
          break
    if broke:
      break
  if not broke:
    max_val = max(max_val, sum(comb))
   
        
        
print(max_val)

Submission status: Runtime Error

Solution code:
N=int(input())
A,X,Y=[],[],[]
for n in range(N):
    An=int(input())
    Xn,Yn=[],[]
    for a in range(An):
        x,y=map(int,input().split())
        Xn.append(x-1)
        Yn.append(y)
    A.append(An)
    X.append(Xn)
    Y.append(Yn)

max_count=0
for k in range(2**N):
    P=[int(_) for _ in bin(k)[2:].zfill(N)]
    ok=True
    for i in range(N):
        for j in range(A[i]):
            if P[i]==1 and P[X[i][j]]!=Y[i][j]
                ok=False
    if ok:
        max_count=max(max_count,sum(P))
print(max_count)

Submission status: Runtime Error

Solution code:
import itertools
N=int(input())
nums = [0,1]
p=list(itertools.product(nums, repeat=3))
A=[]
x = []
y = []
for j in range(N):
    A.append((int(input())))
    x2 = []
    y2 = []
    for i in range(A[j]):
        x1,y1=[int(i) for i in input().split()]
        x2.append(x1)
        y2.append(y1)
    x.append(x2)
    y.append(y2)

for i in range(len(p)):

Submission status: Runtime Error

Solution code:
# ABC147C - HonestOrUnkind2
from itertools import combinations


def main():
    N = int(input())
    testimonies = [[] for _ in range(N + 1)]
    for i in range(1, N + 1):
        A = int(input())
        for _ in range(A):
            testimonies[i].append(map(int, input().split()))

    for cnt_honest in range(N, 0, -1):
        for honest_people in combinations(range(1, N + 1), cnt_honest):
            is_consistent = True
            for i in honest_people:
                for x, y in testimonies[i]:
                    if (x in honest_people and not y) or (x not in honest_people and y):
                        is_consistent = False
                        break
                if not is_consistent:
                    break
            if is_consistent:
                print(cnt_honest)
                return
    print(0)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
ans = 0
evidence = [[] for n in range(N)]

for n in range(N):
    A = int(input())
    for a in range(A):
        lis = list(map(int, input().split()))
        evidence[n].append(lis)

for n in range(1 << N):
    bits = [(n >> i) & 1 for i in range(N)]
    boolean = True
    for i in range(N):
        if (n >> i) & 1 == 0:
            continue
        for x, y in evidence[i]:
            if bits[x-1] == y:
                continue
            flag = False
    if flag:
        ans = max(ans, sum(bits))
print(ans)

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 i in range(1<<n):
    ok = True
    for j in range(n):
        # if jth person may be honest, verify testimony of him.
        if (i>>j) & 1 == 1:
            for xy in xys[j]:
                x, y = xy
                if (i>>x) & 1 != y:
                    ok = False
                    break
        if not ok:
            break
    if ok:
        ans = max(ans, bin(x).count('1'))
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

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

ans = 0
for i in range(1, 2**N):
    flag = 0
    for j in range(N):
        if (i>>j) & 1 == 1:
            for x, y in proof[j]:
                if (i>>x)&1 != state:
                    flag = 1
                    break
    if flag == 0:
        ans = max(ans, bin(i)[2:].count('1'))
print(ans)

Submission status: Runtime Error

Solution code:
g = [[-1] * 15 for _ in range(15)]
n = int(input())
for i in range(n):
    m = int(input())
    for j in range(m):
        a, x = map(int, input().split())
        a -= 1
        g[i][a] = x
def count_ones_by_minus(num):
    count = 0
    while num:
        num &= num -1
        count += 1
    return count
for i in range(1 << 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[j][k] == -1:
                    continue
                if g[j][k] != d[k]:
                    ok = False
        if ok:
            ans = max(ans, count_ones_by_minus(i))
    print(ans)

Submission status: Runtime Error

Solution code:
import itertools

n = 10
data = [_ for _ in range(1,n+1)]
print(data)

dt = [2,4635,534,534,5,2345,13,41,51,23]

for i in itertools.combinations(data, 1):
    print(i)





for i in fakePeople:
            if turndata[i] != []:
                for j in turndata[i]:
                    if j[1] == 0:
                        j[1] = 1
                    else:
                        j[1] = 0

import itertools
import copy

n = int(input())
indexes = [_ for _ in range(1, n+1)]

def ifCorrect(data, fakes):
    answer_sheet = [-1 for i in range(n+1)]
    for i in fakes:
        answer_sheet[i] = 0

    #このあたりで、fakeでない人の情報とも比較して、正直者の証言がそれらのリストと合致しているかを確認すれば良い
    for i in range(len(data)):
        for j in data[i]:
            if not i in fakes:
                if answer_sheet[j[0]] == -1:
                    if j[1] == 0 and not j[0] in fakes:
                        return False
                    else:
                        answer_sheet[j[0]] = j[1]
                elif not answer_sheet[j[0]] == j[1]:
                    return False
                    
    return True

data = [[] for _ in range(n+1)]
for i in range(n):
    id = int(input())
    for _ in range(id):
        x, y = map(int, input().split(" "))
        data[i+1].append([x,y])

fakePersonCount = 0
flag = True
while fakePersonCount <= n and flag:
    comb = itertools.combinations(indexes, fakePersonCount)
    for fakePeople in comb:
        if ifCorrect(data, fakePeople):
            print(n - fakePersonCount)
            flag = False
            break
    fakePersonCount += 1

if flag:
    print(0)

#[[], [[2, 1], [3, 0]], [[3, 1], [1, 0]], [[1, 1], [2, 0]]]

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
d=[]
for i in range(n):
  c=[]
  b=int(input())
  d.append(b)
  for j in range(b):
    c.append(list(map(int,input().split())))
  a.append(c)


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

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
d=[]
for i in range(n):
  c=[]
  b=int(input())
  d.append(b)
  for j in range(b):
    c.append(list(map(int,input().split())))
  a.append(c)


count=0
for i in range(2**n):
  x=[0]*n
  for j in range(n):
    if ((i>>j)&1):
      x[n-1-j]=1 


  pre=0
  for k in range(n):
    for l in range(d[n-1]):
      #print([x[a[k][l][0]-1],a[k][l][1]])
      if ((x[k]==1 and x[a[k][l][0]-1]!=a[k][l][1]) or 
          (x[k]==0 and x[a[k][l][0]-1]==a[k][l][1])):
        pre+=1
  if pre!=0:
    count=count
  else:
    count=max(count,x.count(1))
print(count)

Submission status: Runtime Error

Solution code:
import itertools
N = int(input())
item = []
for i in range(N):
    A = int(input())
    s = []
    for ii in range(A):
        x, y = map(int, input().split())
        s.append((x, y))
        item.append(s)

Ps = itertools.product([0, 1], repeat=N)
ans = 0
for P in Ps:
    right = True
    for i, p in enumerate(P):
        if p == 1:
            for x, y in item[i]:
                if (y == 1 and P[x - 1] == 0) or (y == 0 and P[x - 1] == 1):
                    right = False
    if right:
        ans = max(ans, sum(P))

print(ans)

Submission status: Runtime Error

Solution code:
numbers = list(map(int, input().split()))
n = numbers[0]

v = []

for i in range(n):
    numbers = list(map(int, input().split()))
    a = numbers[0]
    
    w = []
    
    for j in range(a):
        z = list(map(int, input().split()))
        w.append(z)
        
    v.append(w)
    
rezultat = 0

max_steps = 2 ** n

for i in range(max_steps):
    w = [-1] * n
    
    for j in range(n):
        if i >> j & 1:
            w[j] = 1
        else:
            w[j] = 0
    
    ok = 1
    
    for j in range(n):
        if ok == 0:
            break
        for a, b in v[j]:
            if w[j] == 1:
                a = a - 1
            if w[a] != b:
                ok = 0
                break
                
    if ok:
        rezultat = rezultat if rezultat > sum(w) else sum(w)
        
print(rezultat)

Submission status: Runtime Error

Solution code:
import math

a, b, x = map(int, input().split()  ) #split()で分解したものを別々の変数に入れる

m=0
n=x+1

while (n-m) >1:
    num = (m+n) // 2
    if x>= a*num +b*len(str(num)):
        m =num
    else:
        n =num

print(min(m,pow(10,9)))

Submission status: Runtime Error

Solution code:
import itertools

def check_honesty(x, honest_list):
    global N
    for i in range(N):
        for j in range(N):
            if honest_list[i] == 1:
                if x[i][j] == -1 and honest_list[j] == 1:
                    return False
                elif x[i][j] == 1 and honest_list[j] == 0:
                    return False
            elif honest_list[i] == 0:
                if x[i][j] == -1 and honest_list[j] == 0:
                    return False
                elif x[i][j] == 1 and honest_list[j] == 1:
                    return False
    return True

def print_max_honest():
    global N
    global x
    
    for i in range(N):
        r = N - i
        for ite in itertools.combinations(list(range(N)), r):
            honest_list = [0 for j in range(N)]
            for n in ite:
                honest_list[n] = 1
            if check_honesty(x, honest_list):
                print(r)
                return
    print(0)
            
N = int(input())
X = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x_ij,y_ij = map(int, input().split())
        if y_ij == 1:
            X[i][x_ij-1] = 1
        elif y_ij == 0:
            X[i][x_ij-1] = -1
print_max_honest()

Submission status: Runtime Error

Solution code:
def check_honesty(x):
    global HONEST_LIST
    for i in range(len(x)):
        for j in range(len(x[i])):
            if HONEST_LIST[i] == 1:
                if x[i][j] == -1 and HONEST_LIST[j] == 1:
                    HONEST_LIST[i] = 0
                    check_honesty(x)
                elif x[i][j] == 1 and HONEST_LIST[j] == 0:
                    HONEST_LIST[i] = 0
                    check_honesty(x)
            elif HONEST_LIST[i] == 0:
                if x[i][j] == -1 and HONEST_LIST[j] == 0:
                    HONEST_LIST[j] = 0
                    check_honesty(x)
                elif x[i][j] == 1 and HONEST_LIST[j] == 1:
                    HONEST_LIST[j] = 0
                    check_honesty(x)
            
            
N = int(input())
HONEST_LIST = [1 for i in range(N)]
x = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x_ij,y_ij = map(int, input().split())
        if y_ij == 1:
            x[i][x_ij-1] = 1
        elif y_ij == 0:
            x[i][x_ij-1] = -1

check_honesty(x)
print(sum(HONEST_LIST))

Submission status: Runtime Error

Solution code:
n=int(input())
a=[[]] * n
x=[[]] * n
y=[[]] * n
for i in range(n):
  a[i]=int(input())
  x[i]=[[]] * a[i]
  y[i]=[[]] * a[i]
  for j in range(a[i]):
    x[i][j],y[i][j]=map(int,input().split())
def eva(o,p,q):
  for i in range(a[p]):
    if x[p][i]-1==q:
      return(y[p][i])
  for i in range(a[p]):
    if x[p][i]-1==o:
      return(1)
  for i in range(a[p]):     
    if y[p][i]==1:     
      return(eva(o,x[p][i]-1,q))
  return(1)
def test(p,q):
  return(eva(p,p,q)*eva(q,q,p))

ans=[[[] for i in range(n) ] for j in range(n)]
for i in range(n):
  for j in range(n):
    ans[i][j]=test(i,j)

b=[sum(ans[i])for i in range(n)]

sum=0
for i in range(n):
  if max(b)==0:
    break
  c=b.index(max(b))
  for j in range(n):
    if ans[c][j]==0:
      b[j]=0
  b[c]=0
  sum+=1
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
S = []
for _ in range(N):
    s = list(input())
    s.sort()
    # s = ''.join(s)
    S.append(s)

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(10):
            a = S[i]
            b = S[j]
            if a[k] != b[k]:
                break
        else:
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
data_xy = []
for i in range(N):
    A = int(input())
    xy = []
    for i in range(A):
        [x,y] = list(map(int,input().split()))
        xy.append([x-1, y])
    data_xy.append(xy)
data_xy = np.array(data_xy,dtype=np.int64)
ans = 0
for i in range(2**N):
    p_list = np.zeros(N,dtype=np.int64)
    for j in range(N):
        if (i>>j) & 1 == 1:
            p_list[j] = 1
    flag = True
    for j in range(N):
        if p_list[j] == 1:
            for k in range(len(data_xy[j])):
                x = data_xy[j][k][0]
                y = data_xy[j][k][1]
                if p_list[x] != y:
                    flag = False
    if flag == True:
        ans = max(sum(p_list),ans)
print(ans)

Submission status: Runtime Error

Solution code:
def max_honest(n_ppl, testimonies):
    formating_str = "{0:0" + str(n_ppl) + "b}"
    max = 0
    for i in range(1, 2**n_ppl + 1):
        current_val = formating_str.format(2**n_ppl - i)
        potential = True
        valid_testemonies = []
        for j in range(0, len(current_val)):
            if current_val[j] == "1":
                for k in range(0, len(testimonies[j])):
                    valid_testemonies.append(testimonies[j][k])
        for j in range(0, len(valid_testemonies)):
            if str(valid_testemonies[j][1]) != current_val[valid_testemonies[j][0] - 1]:
                potential = False
                break
        if potential:
            if current_val.count("1") > max:
                max = current_val.count("1")
    return max

testimonies = []
n_ppl = int(input())

for i in range(0, n_ppl):
    tests = []
    n_tests = int(input())
    for j in range(0, n_tests):
        test = input().split(" ")
        test = (int(test[0]), int(test[1]))
        tests.append(test)
    testimonies.append(tests)
    
print("")
print(max_honest(n_ppl, testimonies))
input("Press enter")

Submission status: Runtime Error

Solution code:
def max_honest(n_ppl, testimonies):
    formating_str = "{0:0" + str(n_ppl) + "b}"
    max = 0
    for i in range(1, 2**n_ppl + 1):
        current_val = formating_str.format(2**n_ppl - i)
        potential = True
        valid_testemonies = []
        for j in range(0, len(current_val)):
            if current_val[j] == "1":
                for k in range(0, len(testimonies[j])):
                    valid_testemonies.append(testimonies[j][k])
        for j in range(0, len(valid_testemonies)):
            if str(valid_testemonies[j][1]) != current_val[valid_testemonies[j][0] - 1]:
                potential = False
                break
        if potential:
            if current_val.count("1") > max:
                max = current_val.count("1")
    return max

testimonies = []
n_ppl = int(input())

for i in range(0, n_ppl):
    tests = []
    n_tests = int(input())
    for j in range(0, n_tests):
        test = input()
        test = (int(test[0]), int(test[2]))
        tests.append(test)
    testimonies.append(tests)
print(max_honest(n_ppl, testimonies))

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=[0]*a
  y=[0]*a
  for j in range(a):
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
s=0
for i in range(2**n):
  c=0
  d=0
  B=[0]*n
  for j in range(n):
    if((i >> j) & 1):
      c=c+1
      B[j]=1
  for k in range(n):
    if B[k]==1:
      for j in range(A[k]):
        if Y[k][j]!=B[X[k][j]]:
          d=-1
          break
    if d<0:
      break
  if s<c:
    s=c
      
      
print(s)

Submission status: Runtime Error

Solution code:
    #ABC147 C
    si = lambda: input()
    ni = lambda: int(input())
    nm = lambda: map(int, input().split())
    nl = lambda: list(map(int, input().split()))
    n=int(input())
    shogen=[]
    for _ in range(n):
    a=int(input())
    t=[]
    for __ in range(a):
        s=list(map(int,input().split()))
        t.append(s)
    shogen.append(t)

    ans=0

    for i in range(2**n):
    flag=True
    for j in range(n):
        if not flag:
        break
        if ((i>>j) & 1):
        for s in shogen[j]:
            if ((i>>s[0]-1)&1) !=s[1]:
            flag=False
    if flag:
        mnt = bin(i).count("1")
        ans=max(ans,mnt)
    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
    for _ in range(int(input())):
        A[i].append([int(s) for s in input().split()])

ret = 0
for i in range(2 ** N):#2**Nだけ正解の候補がある
    bits = [i >> j & 1 for j in range(N)]#　N桁の２進数iについて、逆順に並べた配列が生成
    #print(bits)
    for i, a in enumerate(A):#i→人、a→人iの証言のリスト
        if bits[i] == 0:#人iが正直者じゃない場合、continueして次の人の証言に移行
            continue
        for x, y in a:
            # print(bits, bits[x - 1], y)
            if bits[x - 1] == y:#正解の候補と証言が一致する場合、その人の次の証言を参照
                continue
            break　　　　　　　　　#そうでない場合、その人の証言を聞くのをやめて次の人の証言を聞く
        else:#breakでループを抜けなかったときにのみ、elseが実行
            continue#このcontinueは２つ上のfor文のcontinueつまり、間違った証言がある場合、一つ下のbreakが評価されて、次の正解候補にうつる
        break
    else:#breakでループを抜けなかったときにのみ、elseが実行
        ret = max(ret, sum(bits))
print(ret)

Submission status: Runtime Error

Solution code:
N = int(input())
lista = []
for n in range(N):
    listan = []
    an = int(input())
    for n in range(an):
        listxy = tuple(map(int, input().split()))
        listan.append(listxy)
        listset = tuple(listan)
    lista.append(listset)    
tuplea = tuple(lista)    
#print(lista)
ansfin = 0
for n in range(2**N):
    bin2 = list(bin(n))[2:]
    bin2.reverse()
    #print(bin2)
    l = len(bin2)
    rightwrong = set()
    #print(l)
    setright = set()
    for n in range(N):
        if n<l:
            #print(bin2[n])
            if bin2[n] == str(1):
                rightwrong.add((n+1, 1))
                lo = len(tuplea[n])
                for m in range(lo):
                    setright.add(tuplea[n][m])
            else:
                rightwrong.add((n+1, 0))
        else:
            rightwrong.add((n+1, 0))  
    #print('a')                     
    #print(setright)
    #print(rightwrong)
    if setright.issubset(rightwrong):
        ans = bin2.count(str(1))
        if ansfin>=ans:
            pass
        else:
            ansfin = ans
    #print(ans)    
print(ansfin)

Submission status: Runtime Error

Solution code:
N=int(input())
ans=[]
A=[0 for i in range(N)]
Axy=[0 for i in range(N)]
for i in range(N):
    A[i]=int(input())
    Axy[i]=[[int(i)for i in input().split()]for j in range(A[i])]
for i in range(i<<N):
    Truth=[]
    maru=0
    for j in range(N):
        Truth.append(((i>>j)&1)==1)
        maru+=((i>>j)&1)
    syogen=[1 if Truth[i] else 0 for i in range(N)]
    isMujun = True
    for k in range(N):
        if Truth[k] and isMujun:
            for x,y in Axy[k]:
                if syogen[x-1]==y:
                    pass
                else:
                    ans.append(0)
                    isMujun = False
                    break
    if isMujun:
        ans.append(maru)
print(max(ans))

Submission status: Runtime Error

Solution code:
ans=0
shogen=[]
n=int(input())
for _ in range(n):
  t=[]
  a=int(input())
  for __ in range(a):
    h=list(map(int,input().split()))
    t.append(s)
  shogen.append(t)
for i in range(2**n):
  flag=True
  for j in range(n):
    if not flag:
      break
    if ((i>>j) & 1):
      for h in shogen[j]:
        if ((i>>h[0]-1)&1) !=h[1]:
          flag=False
  if flag:
    mnt = bin(i).count("1")
    ans=max(ans,mnt)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A_map = {}

# input
for i in range(N):
    A = int(input())
    if A > 0:
        for j in range(A):
            xy = list(map(int,input().split()))
            if i in A_map.keys():
                A_map[i].append(xy)
            else:
                A_map[i] = [xy]

ans = 0

for bits in range(1,2**N):
    honest = True
    for i in range(1,N+1):
        if not (bits & (1 << (i-1))): continue

        if i in A_map.keys():
            for a in A_map[i-1]:   
                if ((bits >> (a[0] -  1)) & 1) ^ a[1] : honest = False
    if honest : 
        ans = max(ans, bin(bits).count('1'))

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A_map = {}

# input
for i in range(N):
    A = int(input())
    if A > 0:
        for j in range(A):
            xy = list(map(int,input().split()))
            if i in A_map.keys():
                A_map[i].append(xy)
            else:
                A_map[i] = [xy]

ans = 0

for bits in range(1,2**N):
    honest = True
    for i in range(1,N+1):
        if not (bits & (1 << (i-1))): continue
        for a in A_map[i-1]:   
            if ((bits >> (a[0] -  1)) & 1) ^ a[1] : honest = False
    if honest : 
        ans = max(ans, bin(bits).count('1'))

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A_map = {}

# input
for i in range(N):
    A = int(input())
    if A > 0:
        for j in range(A):
            xy = list(map(int,input().split()))
            if i in A_map.keys():
                A_map[i].append(xy)
            else:
                A_map[i] = [xy]

ans = 0

for bits in range(1,2**N):
    honest = True
    for i in range(1,N+1):
        if not (bits & (1 << (i-1))): continue
        for a in A_map[i]:   
            if ((bits >> (a[0] -  1)) & 1) ^ a[1] : honest = False
    if honest : 
        ans = max(ans, bin(bits).count('1'))

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A_map = {}

# input
for i in range(N):
    A = int(input())
    if A > 0:
        for j in range(A):
            xy = list(map(int,input().split()))
            if i in A_map.keys():
                A_map[i].append(xy)
            else:
                A_map[i] = [xy]

ans = 0

for bits in range(1,2**N):
    honest = True
    for i in range(1,N):
        if not (bits & (1 << (i-1))): continue
        for a in A_map[i]:   
            if ((bits >> (a[0] -  1)) & 1) ^ a[1] : honest = False
    if honest : 
        ans = max(ans, bin(bits).count('1'))

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

def checkTestimony(honest, A_map, N):
    # print(f"A_map{A_map}")
    for i in range(N):
        for a in A_map[i]:
            # print(f"a:{a}")
            Opponent = a[0] - 1
            OpJudge  = a[1]

            if honest[i] ^ OpJudge :
                return False
    return True    

def setHonest (num, l):
    for i in range(len(l)):
        if (num >> i) & 1 == 1:
            l[i] = 1

N = int(input())
A_map = {}
ans = 0

for i in range(N):
    A = int(input())
    if A > 0:
        for j in range(A):
            xy = list(map(int,input().split()))
            if i in A_map.keys():
                A_map[i].append(xy)
            else:
                A_map[i] = [xy]

if len(A_map) > 0:
    for i in range(2**N):
        honest = [0] * N
        setHonest(i, honest)

        if checkTestimony(honest, A_map, N) :
            honestNum = honest.count(1)
            ans = max(honestNum, ans)
else:
    ans= N

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

def checkTestimony(honest, A_map, N):
    for i in range(N):
        for a in A_map[i]:
            Opponent = a[0] - 1
            OpJudge  = a[1]
            if honest[i] == 0:
                if honest[Opponent] == OpJudge:
                    return False 
            else:
                if honest[Opponent] != OpJudge:
                    return False 
    return True    

def setHonest (num, l):
    for i in range(len(l)):
        if (num >> i) & 1 == 1:
            l[i] = 1

N = int(input())
A_map = {}
ans = [0]

for i in range(N):
    A = int(input())
    if A > 0:
        for j in range(A):
            xy = list(map(int,input().split()))
            if i in A_map.keys():
                A_map[i].append(xy)
            else:
                A_map[i] = [xy]

if len(A_map) > 0:
    for i in range(2**N):
        honest = [0] * N
        setHonest(i, honest)

        if checkTestimony(honest, A_map, N) :
            honestNum = honest.count(1)
            ans.append(honestNum)
else:
    ans.append(N)

print(max(ans))