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 = list(map(int, input().split()))

o = []

MOD = 10**9 + 7

for b in range(60):
    count = 0
    x = 2**b
    for i in range(n):
        if (a[i] & x) == 0:
            count += 1
    o.append(count)

sum = 0
for b in range(60):
    sum += (o[b] * (n - o[b])) * 2**b

print(sum % MOD)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

o = []

MOD = 10**9 + 7

for b in range(60):
    count = 0
    x = 2**b
    for i in range(n):
        if (a[i] & x) == 0:
            count += 1
    o.append(count)

sum = 0
for b in range(60):
    sum += (o[b] * (n - o[b])) * 2**b

print(sum % MOD)

Submission status: Runtime Error

Solution code:
import itertools as it
def all_same(items):
    return all(x == items[0] for x in items)
Num=input()
persons=[]
for i in range(0,Num):
    stuff=[]
    for i in range(0,input()):
        stuff.append(map(int,input().split(' ')))
    persons.append(stuff)
n=0
n2=0
for i in range(0,Num+1):
    ultimatetruthtable=[None]*(Num)
    for j in list(it.combinations(range(Num),i)):
        for k in range(0,len(j)):
            for p in j[k]:
                for q in range(0,len(persons[p])):
                    ultimatetruthtable[persons[p][q][0]].append(persons[p][q][1])
    for r in ultimatetruthtable:
        if all_same(r):
            n=n+1
    if n==Num:
        n2=i
print(n2)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
x = []
num = []

for i in range(n):
  a.append(int(input()))
  x.append([list(map(int, input().split())) for _ in range(a[i])])

def dfs(i):
  if i == n:
    #証言の判定
    for j in range(n):
      for k in range(a[j]):
        if x[j][k][1] == 1:
          if num[j-1] == 1 and num[x[j][k][0] == 0:
            return False
          else:
            return True                       
        else:
          if return num[j-1] == 1 and num[x[j][k][0] == 1
            return False
          else:
            return True                                                 
    
  if dfs(i+1):
    num.append(1)
    print(num)                                      
    return True
  
  if dfs(i+1):
    num.append(0)
    print(num)                                      
    return True
  
  return False

if dfs(0):
  print(sum(num))
else:
  print(0)

Submission status: Runtime Error

Solution code:
N = int(input())

tmpobj = {}
for i in range(N):
    n = int(input())
    list_tmp =[list(map(int,input().split())) for i in range(n)]
    tmpobj[i+1] = list_tmp
print(tmpobj)
# X2_list = [list(map(int,input().split())) for i in range(N)]
import itertools
target = list(itertools.product([0,1],repeat=N))

result = 0

def shogenCheck(reusltList, obj,target,max) :
    for shogen in obj[target]:
        reusltList.append(shogen)
        if max == len(reusltList):
            return reusltList
        if shogen[1] == 1:
            shogenCheck(reusltList,obj,shogen[0],max)
    return reusltList

for i,T in enumerate(target):
    hanashi = []

    for j,t in enumerate(T):
        if t == 0:
            continue
        else:
            hanashi = shogenCheck([],tmpobj,j+1,N)

    mujun = False
    hanashiObj = {}
    for h in hanashi:
        if hanashiObj.get(h[0]) is None:
            hanashiObj[h[0]] = h[1]
        else:
            # 被ったらアウト
            if hanashiObj[h[0]] != h[1]:
                mujun = True
                break
    if not mujun:
        result = max(result,T.count(1))
print(result)

Submission status: Runtime Error

Solution code:
from itertools import zip_longest as zi
n=int(input())
hil=[ [ [],[] ] for i in range(n)]
for i in range(n):
  hint=int(input())
  if hint:
    for j in range(hint):
      a,s=map(int,input().split())   
      hil[a-1][s]+=[i]

ans=0
for i in range(2**n)[::-1]:
  ss=bin(i)[2:]
  s="0"*(n-len(ss))+ss
  sset=set([fg for fg in range(n) if s[fg]=="1"])
  hset=set(range(n))-sset
  print(sset,hset)
  jjj,kkk=set(),set()
  for kk in sset:
    j,k=hil[kk]
    j,k=set(j),set(k)
    jjj|=j;kkk|=k
    
  if len(jjj&sset) or len(kkk&hset) :
    contiue
  else:
    ans=max(ans,len(ss.replace("0","")))
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
test = []
count = 0
for i in range(0, n):
    num_test = int(input())
    for j in range(0, num_test):
        answer = input().split()
        a = answer[1]
        if a == '1':
            count += 1
        else:
            continue
            return 1
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
lst = [format(i, '08b') for i in range(2**N)]
lst.reverse()
X = [[] for i in range(N)]
Y = [[] for i in range(N)]
ans_i = None
ans = 0
for i in range(N):
    tmp_A = int(input())
    A.append(tmp_A)
    for j in range(tmp_A):
        tmp_x,tmp_y = map(int,input().split())
        X[i].append(tmp_x)
        Y[i].append(tmp_y)
for i in lst:
    flag = 0
    PEOPLE = [j for j in i]
    for k in range(N):
        if PEOPLE[k]=="1":
            LEN = len(X[k])
            for l in range(LEN):
                if PEOPLE[X[l]-1]!=Y[l]:
                    flag = 1
    if flag == 0:
        ans_i = i
        break
print(ans_i)
for i in ans_i:
    if i == "1":
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()

dicts = {i+1:{}  for i in range(N)}
un_dicts={i+1:{}  for i in range(N)}
for i in range(1,N+1):
    num = one_int()
    bits = ["0" for k in range(N)]
    un_bits = ["1" for k in range(N)]
    
    bits[int(i-1)]="1"
    un_bits[int(i-1)]="0"

    
    for j in range(num):
        hito, singi = two_int()
        bits[hito-1] = str(singi)
        
        if singi==1:
            un_bits[hito-1] = str(0)
        else:
            un_bits[hito-1] = str(1)
    
    dicts[i] = "".join(bits)
    un_dicts[i] = "".join(un_bits)



users = [j+1 for j in range(N)]
max_n=0
# 信じる人のループ
for i in dicts:
    all_syougens=[]
    all_or = 0
    old=0
    flg=False
    #信じる人の証言取得
    syougen = list(map(int, list(dicts[i])))
    
    # 信じる人の証言を各人の証言に適応
    count = 0
    
    aaaa = [[] for j in range(N)]
    for u,s in zip(users,syougen):
        si = dicts[u]
        #信じる人がうそつきだといったら反転
        if s==0:
            si = un_dicts[u]
        for k in list(si):
            aaaa[k].append(k)
    
    count=0
    
    for i in aaaa:
        if len(set(aaaa)) ==1:
            count+=1
            
    if count >= max_n:
        max_n = temp
print(max_n)

Submission status: Runtime Error

Solution code:
n = int(input())
xy = []
ansp = []
people =[-1]*n
sp = [-1]*n



for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int,input().split())
        xy.append([x-1,y])
def dfs(now,ok):
    global sp
    global people
    if now ==n:
        ansp.append(people.count(1))
        sp = [-1]*n
        people = [-1]*n
        return
    if len(xy[now]) >0:
        for i in range(len(xy[now])):
            x = xy[i][0]
            y = xy[i][1]
            if ok:
                if sp[x] == y or sp[x] == -1:
                    sp[x] = y
                else:continue
            else:
                if sp[x] == y^1 or sp[x] == -1:
                    sp[x] == y^1
                else:continue
    
        
        
    people[now] = ok    
    dfs(now+1,ok)
    dfs(now+1,ok^1)
dfs(0,0)
dfs(0,1)
if len(ansp) == 0:
    print(0)
    exit(0)
print(max(ansp))

Submission status: Runtime Error

Solution code:
def f():
    N = int(input())
    A = []
    
    for n in range(N):
        templist = []
        for a in range(int(input())):
            templist.extend(list(map(int, input().split())))
        A.append(templist)
    
    print(A)
    
    maxlen = len(str(bin(2**len(A)-1).replace('0b','')))
    for j in reversed((range(2**len(A)))):
        tempb = str(bin(j).replace('0b',''))
        for i in range(maxlen - len(tempb)):
            tempb = '0'+tempb
        # ここでパターン仮置き確定
        tempj = list(map(int, list(tempb)))
        counter = 0
        for jj in range(len(tempj)):
            if tempj[jj] == 1: # 正直者の場合
                if tempj[A[jj][0]-1] != A[jj][1]:# 本当は違う
                    break
                else:
                    counter += 1
            else:
                if tempj[A[jj][0]-1] == A[jj][1]:# 本当はあってる
                    break
                else:
                    counter += 1
        if counter == len(A):
            return print(tempj.count(1))
            
    return print(tempj.count(1))
    
f()

Submission status: Runtime Error

Solution code:
N = int(input())
lst = []
for i in range(N):
  for j in range(int(input())):
    lst.append(list(map(int,input().split())))
ans = 0
for i in range(2**N):
  flag = True
  bin_lst = list(bin(i)[2:].zfill(N))
  for idx,j in enumerate(bin_lst):
    if (j == '1'):
      for v, w in zip(lst[idx][:-1],lst[idx][1:]):
        if (bin_lst[v-1] != str(w)):
          flag = False
  if (flag):
    ans = max(ans,bin_lst.count('1'))
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys

n = int(input())
mat = np.ones((n, n))
for i in range(n):
    tmp_a = int(input())
    for j in range(tmp_a):
        tmp_x, tmp_y = map(int, input().split())
        if tmp_y == 0:
            mat[i][tmp_x-1] = 0
          
#bit全探索

ans = 0
for k in range(2**n):
    bit_list = [0] * n
    for l in range(n):
         if ((k >> l) & 1):
            bit_list[n-1-l] = 1
    
    mat_check = mat
    for m in range(n)[::-1]:
        if bit_list[m] == 0:
            mat_check = np.delete(mat_check, obj=m, axis=0)
            mat_check = np.delete(mat_check, obj=m, axis=1)
    if np.sum(mat_check) == sum(bit_list)**2:
        print(bit_list)
        if sum(bit_list)>=2:
            ans = sum(bit_list)
        else if sum(mat[m])==1:
            ans = sum(bit_list)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
if N == 1:
    k,l = map(int,input().split())
    if l == 1:
        print(1)
    else:
        print(0)
    exit()
A = [0 for _ in range(N+1)]
l = [0,1]
H = []
for i in range(2**N):
    S = str(bin(i)).zfill(N)
    H.append(S[2:].zfill(N))
#H = list(combinations_with_replacement(l, N))
IXY = []
for i in range(1,N+1):
    A[i] = int(input())
    for j in range(A[i]):
        x,y = map(int,input().split())
        IXY.append([i,x,y])
ANS = []
for h in H:
    for ixy in IXY:
        flg = True
        i,x,y = ixy[0]-1,ixy[1]-1,ixy[2]
        if h[i] == "1":
            if h[x] != str(y):
                flg = False
                break
    if flg:l.append(ANS.append(h))
ans = 0
for a in ANS:
    ans = max(a.count("1"),ans)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
test = []
count = 0
for i in range(0, n):
    num_test = int(input())
    for j in range(0, num_test):
        answer = input().split()
        a = answer[1]
        if a == '1':
            count += 1
        else:
            continue
print(count)
return 1

Submission status: Runtime Error

Solution code:
N = int(input())
table = [[-1]*(N+1) for i in range(N+1)]
for i in range(1,N+1):
    A = int(input())
    for j in range(A):
        x,y = map(int,input().split())
        table[i][x] = y
#print(table)
# table[i][x] 人iが人xを正直者;1,真偽不明:0,未言及:-1

ans = 0
for i in range(2**N):

    # hito = [0]*N
    # for j in range(N):
    #     if i >> j & 1:
    #         hito[j] = 1
    # print(hito)

    flag = True
    cnt = 0
    for j in range(N):
        if i >> j & 1:
            cnt += 1
            for k in range(N):
                if table[j+1][k+1] != -1:
                    #print(table[j+1][k+1])


                    if k == 0:
                    if table[j+1][k+1] ^ (i >> k):
                        # if j == 1 and k == 0:
                        #     print(i>>k)
                        #     print(table[j+1][k+1])
                        flag = False
                        #print(i,j,k)
    if flag:
        if cnt > ans:
            ans = cnt
print(ans)
# print(3 >> 0) # 3????
# print(1^3)

Submission status: Runtime Error

Solution code:

n=int(input())
a=[0]*n
g=[[0]*n for _ in range(n)]
for i in range(n):
    a[i]=int(input())
    for j in range(a[i]):
        x,y=map(int,input().split())
        g[i][x]=y
count=0
for i in range(n):
    for j in range(n):
        if i==j:
            break
        else:
            if g[i][j]==0 and g[j][i]==0:
                count+=1
print(count)

Submission status: Runtime Error

Solution code:
ans = 0
for i in range(n):
    a = int(input()) #何段の証言になるか
    for l in range(a):
        x,y = list(map(int,input().split()))
        b.append(x)  #矛先
        c.append(y)  #審議
#print(b)
#print(c)
for o in range(n):
    ans = 0
    for m in range(len(b)):
        if b[m] == o+1:
            if c[m] == 1:
                ans += 1
            else:
                ans -= 1
    d.append(ans)
print(d)
sorted(d)
z = set(d)
if len(set(d)) == 1:
    if z[0]< 0:
        print(len(set(d)))
    else:
        print(0)
else:
    print(len(set(d)))

Submission status: Runtime Error

Solution code:
n = int(input())
test = []
count = 0
for i in range(0, n):
    num_test = int(input())
    for j in range(0, num_test):
        answer = input().split()
        a = answer[1]
        if a == '1':
            count += 1
        else:
            continue
return 1

Submission status: Runtime Error

Solution code:
# c
import numpy as np
n = int(input())
a = {}
xy = {}
for i in range(n):
    a[i] = int(input())
    xy[i] = {}
    for j in range(a[i]):
        xy[i][j] = list(map(int,input().split()))

### 自分についての情報を付け加える
for s in range(n):
    xy[s][a[i]] = [s+1,1]

# pさんによる証言とqさんによる証言を比較する
pq_list = [[0 for inki in range(n)] for jinjin in range(n)]
for p in range(n):
    for q in range(n):
        for l in range(len(xy[p])):
            for m in range(len(xy[q])):
                if xy[p][l][0] == xy[q][m][0] and xy[p][l][1] != xy[q][m][1]:
                    pq_list[p][q] += 1

pq_list = np.array(pq_list)
count = 0
while np.sum(pq_list) >= 1:
    max_index = 0
    for i in range(len(pq_list)):
        if sum(pq_list[max_index]) <= sum(pq_list[i]):
            max_index = i
    if sum(pq_list[max_index]) == 0:
        break
    pq_list = np.delete(pq_list,max_index,0)
    pq_list = np.delete(pq_list, max_index, 1)
    count += 1
    
print(n-count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [-1 for i in range(n)]
x = [[-1 for i in range(n)] for i in range(n)]
y = [[-1 for i in range(n)] for i in range(n)]
result = 0
for i in range(n):
    a[i] = int(input())
    for j in range(a[i]):
        x[i][j], y[i][j] = map(int, input().split())

for state in range(2**n+1):
    b = [0]*3
    # 各人の性格を仮置きする
    for i in range(n):
        b[i] = (state >> i) & 1
    # 仮置きした性格と証言に矛盾がないかチェックする
    check = True
    for i in range(n):
        for j in range(a[i]):
            if b[i] == 1:
                if y[i][j] != b[x[i][j]-1]:
                    check = False
                    break
    if check:
        num = 0
        for i in range(n):
            num += b[i]
        if result < num:
            result = num

print(result)

Submission status: Runtime Error

Solution code:
n = int(input())
humanlist = []
a = []
unkind = []
for l in range(n):
    s = int(input())
    a.append(s)
    for i in range(s):
        humanlist.append(list(map(int, input().split())))
    unkind.append(humanlist)
    humanlist = []
truelist = []
falselist = []
deffalselist = []
deffalselist = [0]*n
truelist = [0]*n
falselist = [0]*n
for i in range(n):
    truelist[i] = 1

    truelen = 1
    truelen1 = 0
    while True:
        if truelen == truelen1:
            break
        truelen = truelen1
        nowtrue = unkind[i]
        for k in range(len(nowtrue)):
            if nowtrue[k][1] == 1:
                aa=int(nowtrue[k][0])
                truelist[aa-1] = 1
            else:
                falselist[aa-1] = 1
        truelen1 = len([i for i in truelist if i == 1])
    for j in range(n):
        if falselist[j] == 1 and truelist[j] == 1:
            deffalselist[i] = 1
        elif falselist[j] == 0 and truelist[j] == 0:
            truelist[j] = 1
            truelen = 1
            while True:
                if truelen == truelen1:
                    break
                truelen = truelen1
                nowtrue = unkind[i]
                for k in range(len(nowtrue)):
                    if nowtrue[k][1] == 1:
                        truelist[nowtrue[k][0]-1] = 1
                    else:
                        falselist[nowtrue[k][0]-1] = 1
                truelen1 = len([i for i in truelist if i == 1])
            for h in range(n):
                if falselist[h] == 1 and truelist[h] == 1:
                    deffalselist[h] = 1
    falselist = [0]*n
    truelist = [0]*n
print(n-len([i for i in deffalselist if i == 1]))

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
if N == 1:
    k,l = map(int,input())
    if l == 1:
        print(1)
    else:
        print(0)
A = [0 for _ in range(N+1)]
l = [0,1]
H = []
for i in range(2**N):
    S = str(bin(i)).zfill(N)
    H.append(S[2:].zfill(N))
#H = list(combinations_with_replacement(l, N))
IXY = []
for i in range(1,N+1):
    A[i] = int(input())
    for j in range(A[i]):
        x,y = map(int,input().split())
        IXY.append([i,x,y])
ANS = []
for h in H:
    for ixy in IXY:
        flg = True
        i,x,y = ixy[0]-1,ixy[1]-1,ixy[2]
        if h[i] == "1":
            if h[x] != str(y):
                flg = False
                break
    if flg:l.append(ANS.append(h))
ans = 0
for a in ANS:
    ans = max(a.count("1"),ans)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
A=[]
X=[]
Y=[]
x=[]
y=[]
l=[1]*n
for i in range(n):
  a=int(input())
  A.append(a)
  for j in range(a):
    x1,y1=[int(s) for s in input().split()]
    x.append(x1)
    y.append(y1)
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  for j in range(i, n):
    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())

a_tot = []
xy_tot =[]

for i in range(n):
    dict={}
    
    a = int(input())
    a_tot.append(a)
    for i in range(a):
        x, y = map(int, input().split())
        dict[x] = y
    xy_tot.append(dict)
print(xy_tot)
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 xy_tot[j]:
                if (xy_tot[j])[k] == li[k]:
                    pass
                else:
                    break
            else:
                continue
            break
    else:
            ma = max(ma, sum(li))
print(ma)

Submission status: Runtime Error

Solution code:
# 人の数(整数)の入力
N = int(input())

i = 1
q = 1

ans = []

while i <= N:
    a = int(input())
    while q  <= a:
        
        # スペース区切りの整数の入力
        x, y = map(int, input().split())
        
        x_i.append(x)
        y_i.append(y)
        
        q += 1
    
    q = 1
    i += 1

for j in range(len(x_i)):
    for k in range(len(x_i)):
        if x_i[j] == x_i[k]:
            if y_i[j] == y_i[k]:
                ans.append(1)

if sum(ans) == 0:
    print(1)
else:
    print(sum(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
true_list = [0]
false_list = []
for j in range(1, N+1):
  false_list.append(j)

a = [[] for _ in range(N)]
for i in range(N):
  A_i = int(input())
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))
    
while True:
  pre_true_list = true_list
  pre_false_list = false_list
  for i in true_list:
    for j in range(len(a[i])):
      kotoba = a[i][j][1]
      person = a[i][j][0]
      if kotoba:
        if false_list.count(person):
          false_list.remove(person)
          true_list.append(person)
      else:
        if true_list.count(person):
          true_list.remove(person)
          false_list.append(person)
        
  for i in false_list:
    for j in range(len(a[i])):
      kotoba = a[i][j][1]
      person = a[i][j][0]
      if not kotoba:
        if true_list.count(person):
          true_list.remove(person)
          false_list.append(person)
      else:
        if false_list.count(person):
          false_list.remove(person)
          true_list.append(person)
  if pre_true_list == true_list and pre_false_list == false_list:
    break
    
print(len(true_list))

Submission status: Runtime Error

Solution code:
ans = 0
for i in range(n):
    a = int(input()) #何段の証言になるか
    for l in range(a):
        x,y = list(map(int,input().split()))
        b.append(x)  #矛先
        c.append(y)  #審議
#print(b)
#print(c)
for o in range(n):
    ans = 0
    for m in range(len(b)):
        if b[m] == o+1:
            if c[m] == 1:
                ans += 1
            else:
                ans -= 1
    d.append(ans)
print(d)
sorted(d)

if len(set(d)) == 1:
    if sum(set(d)) < 0:
        print(len(set(d)))
    else:
        print(0)
else:
    print(len(set(d)))

Submission status: Runtime Error

Solution code:

n = int(input())
people = {}

for i in range(n):
    sentenses = int(input())
    if sentenses > 0:
        for j in range(sentenses):
            v = list(map(int, input().split()))
            if i in people.keys():
                people[i].append(v)
            else:
                people[i] = [v]
            
ans = 0

for i in range(2**n):
    speaker = []
    p_list = [0] * n
    for j in range(n):
        if ((i >> j) % 2) == 1:
            speaker.append(j)
            p_list[j] = 1

    continue_flag = True
    for s in speaker:
        if continue_flag:
            sentenses = people[s]
            for sent in sentenses:
                if p_list[sent[0]-1] == sent[1]:
                    p_list[sent[0]-1] = sent[1]
                else:
                    continue_flag = False
                    break
        else:
            break
        
    if continue_flag:
        temp_ans = len(speaker)
        ans = max(temp_ans, ans)

print(ans)

Submission status: Runtime Error

Solution code:
import copy

from sys import stdin
import itertools
n = int(stdin.readline().rstrip())
items = []
for i in range(n):
    a = int(stdin.readline().rstrip())
    tmp = []
    for i in range(a):
        (x, y) = list(map(int, stdin.readline().rstrip().split(' ')))
        tmp.append((x, y))
    items.append(tmp)
print(items)
max_cnt = 0

def helper(mapping, index):
    item = items[index][0]
    if index in mapping.keys():
        if mapping[index] != item[0]: # indexによって変化
            return -1
    mapping[item[0]-1] = item[1]

for item in items:
    mapping = {}
    for i in item:
        mapping[i[0]-1] = i[1]
    tmp = copy.copy(mapping)
    for key, value in tmp.items():
        if value == 1:
            res = helper(mapping, key)
            if res == -1:
                mapping = {}
                break
    max_cnt = max(len([item for item in list(mapping.values()) if item == 1]), max_cnt)

print(max_cnt)

Submission status: Runtime Error

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

for i in range(N):
  A = int(input())
  tempList = []
  for j in range(A):
    tempList.append(input.split())
    lst.append(tempList)
    
truthList = []
for i in range(len(lst)):
  tempList = []
  for j in range(len(lst[i])):
    tempList2 = []
    if lst[i][j][1] == '1':
      tempList2.append(lst[i][j][0])
      tempList2.append(True)
      tempList.append(tempList2)
    else:
      tempList2.append(lst[i][j][0])
      tempList2.append(False)
      tempList.append(tempList2)

boolList = []
for i in range(len(truthList)):
  for j in range(len(truthList[i])):
    boolList.append(truthList[i][j][1])
    
honest = sum(boolList)
unkind = len(boolList) - sum(boolList)

if honest == unkind:
  print(0)
elif honest == N:
  print(N)
elif unkind == N:
  print(N-1)
else:
  print(honest)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
A = [0 for _ in range(N+1)]
l = [0,1]
H = []
for i in range(2**N):
    S = str(bin(i)).zfill(N)
    H.append(S[2:].zfill(N))
IXY = []
for i in range(1,N+1):
    A[i] = int(input())
    for j in range(A[i]):
        x,y = map(int,input().split())
        IXY.append([i,x,y])
ANS = []
for h in H:
    for ixy in IXY:
        flg = True
        i,x,y = ixy[0]-1,ixy[1]-1,ixy[2]
        if h[i] == "1":
            if h[x] != str(y):
                flg = False
                break
    if flg:l.append(ANS.append(h))
ans = 0
for a in ANS:
    ans = max(a.count("1"),ans)
print(ans)

Submission status: Runtime Error

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

A = []

x = []
y = []

for i in range(N):
    temp = int(input())
    A.append(temp)
    temp3 = []
    temp4 = []
    for j in range(temp):
        temp1,temp2 = map(int,input().split())
        temp3.append(temp1)
        temp4.append(temp2)
    x.append(temp3)
    y.append(temp4)

allperson = set(range(N))

res = [0]

for i in range(N):
    honest = {i}
    dishonest = set()
    checked = set()
    temp1 = A[i]
    for j in range(temp1):
        if y[i][j] == 1:
            honest.add(x[i][j]-1)
        elif y[i][j] == 0:
            dishonest.add(x[i][j]-1)

    temp2 = honest
    isOK = True

    while isOK:
        for k in temp2:
            temp3 = A[i]
            for l in range(temp3):
                if y[k][l] == 1:
                    if x[k][l]-1 in dishonest:
                        isOK = False
                        break
                    else:
                        honest.add(x[k][l]-1)
                elif y[k][l] == 0:
                    if x[k][l]-1 in honest:
                        isOK = False
                        break
                    else:
                        dishonest.add(x[k][l]-1)
            if isOK == False:
                break
            checked.add(k)
        if checked == honest:
            isOK = True
            break
        else:
            temp2 = honest - checked

    if isOK == True:
        temp4 = len(honest)
        res.append(temp4)
        # print(i)
        # print(temp4)
        # print(honest)

print(max(res))

Submission status: Runtime Error

Solution code:
n = int(input())
people = {}

for i in range(n):
    sentenses = int(input())
    for j in range(sentenses):
        v = list(map(int, input().split()))
        if i in people.keys():
            people[i].append(v)
        else:
            people[i] = [v]
            
ans = 0

for i in range(2**n):
    speaker = []
    p_list = [0] * n
    for j in range(n):
        if ((i >> j) % 2) == 1:
            speaker.append(j)
            p_list[j] = 1

    continue_flag = True
    for s in speaker:
        if continue_flag:
            sentenses = people[s]
            for sent in sentenses:
                if p_list[sent[0]-1] == sent[1]:
                    p_list[sent[0]-1] = sent[1]
                else:
                    continue_flag = False
                    break
        else:
            break
        
    if continue_flag:
        temp_ans = len(speaker)
        ans = max(temp_ans, ans)

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
A=[]
X=[]
Y=[]
x=[]
y=[]
l=[1]*n
for i in range(n):
  a=int(input)
  A.append(a)
  for j in range(a):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  for j in range(i,n):
    if l[j]==0:continue
    for k in range(A[i]):
    　　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())
test = []
count = 0
for i in range(0, n):
    num_test = int(input())
    for j in range(0, num_test):
        answer = input().split()
        a = answer[1]
        if a == '1':
            count += 1
        else:
            continue
print(count)
Kong Panhabot

Submission status: Runtime Error

Solution code:
N = int(input())
Harray = []
for i in range(N):
    Aarray = []
    A = int(input())
    for j in range(A):
        xy = list(map(int,input().split()))
        Aarray.append(xy)
    Harray.append(Aarray)

carray = []

for Ai in Harray:
    honest = [Harray.index(Ai)]
    honestcont = [Ai]
    for ans in Ai:
        que = []
        if ans[1] == 1:
            honest.append(ans[0]-1)
            honestcon.append(Harray[ans[0]-1])
            que.append(ans[0]-1)
        while len(que) > 0:
            d = que[0]

            que.pop(0)
            
            e = 0
            for h in honestcon:
                if h[1] == 1:
                    h2 = [h[0], 0]
                else:
                    h2 = [h[0], 1]
                if h2 in Harray[d]:
                    e = 1
            
            for h4 in honest:
                if [h4,0] in Harray[d]:
                    e = 1
            
            if e == 0:
                for ans2 in Harray[d]:
                    if (ans2[1] == 1) and (ans2[0] not in honest):
                        que.append(ans2[0]-1)
            else:
                honest = []
                break
                    
    carray.append(len(honest))

print(max(carray))

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)