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: Wrong Answer

Solution code:

def main():
    N = int(input())
    XY = []
    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)
        xy = []
        for _ in range(a):
            x,y = map(int,input().split())
            xy.append([x,y])
        XY.append(xy)
    ans = 0
    for i in range(2**N):
        now = []
        for j in range(N):
            if ((i>>j)&1):
                now.append(1)
            else:
                now.append(0)

        for i in range(N):
            for j in range(A[i]):
                x = XY[i][j][0]
                y = XY[i][j][1]

                if now[i] == 1:
                    if now[x-1] == y:
                        pass
                    else:
                        break
                else:
                    if now[x-1] != y:
                        pass
                    else:
                        break
            else:
                continue
            
            break
        else:
            ans = max(ans,sum(now))
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())
A = [0]*N
xy = []
for i in range(N):
    A[i] = int(input())
    xy_i = []
    for j in range(A[i]):
        xy_i.append([int(k) for k in input().split()])
    xy.append(xy_i)

ans = 0
for i in range(1, 2**N):
    nisin = str(bin(i))[2:].zfill(N)
    flag = False
    for j in range(N):
        if nisin[j] == '1':
            for k in range(A[j]):
                if ((xy[j][k][1] == 1 and nisin[xy[j][k][0]-1] == '1') or (xy[j][k][1] == 0 and nisin[xy[j][k][0]-1] == '0')):
                    flag = True
                else:
                    flag = False
                    break
        
            if (not flag):
                break
    if (flag):
        ans = max(ans, nisin.count('1'))

print(ans)

Submission status: Wrong Answer

Solution code:
'''input
3
1
2 1
1
1 1
1
2 0
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline




def make_dict(index):
	aux = dict()
	for i, j in data[index]:
		aux[i] = j 
	return aux

def check(truth, index):
	T = set()
	F = set()
	T.add(index)
	for i in truth:
		if truth[i] == 1:
			T.add(i - 1)
		else:
			F.add(i - 1)

	for i in range(n):
		if i != index and i in T:
			aux = data[i]
			for j in range(len(aux)):
				p, v = aux[j]
				p -= 1
				if v == 0:
					if p in T:
						return 0
					else:
						F.add(p)
				else:
					if p in F:
						return 0
					else:
						T.add(p)
	return len(T)

	
# main starts
n = int(input().strip())
data = []
for _ in range(n):
	k = int(input().strip())
	temp =[]
	for i in range(k):
		x, y = list(map(int, input().split()))
		temp.append([x, y])
	data.append(temp)
ans = 0

# assuming i to be true;
for i in range(n):
	truth = data[i]
	truth = make_dict(i)
	c = check(truth, i)
	ans = max(ans, c)

print(ans)

Submission status: Wrong Answer

Solution code:
'''input
3
1
2 1
1
1 1
1
2 0
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline




def make_dict(index):
	aux = dict()
	for i, j in data[index]:
		aux[i] = j 
	return aux

def check(truth, index):
	T = set()
	F = set()
	for i in truth:
		if truth[i] == 1:
			T.add(i - 1)
		else:
			F.add(i - 1)

	for i in range(n):
		if i != index and i in T:
			aux = data[i]
			for j in range(len(aux)):
				p, v = aux[j]
				p -= 1
				if v == 0:
					if p in T:
						return 0
					else:
						F.add(p)
				else:
					if p in F:
						return 0
					else:
						T.add(p)
	return len(T)


					




	
# main starts
n = int(input().strip())
data = []
for _ in range(n):
	k = int(input().strip())
	temp =[]
	for i in range(k):
		x, y = list(map(int, input().split()))
		temp.append([x, y])
	data.append(temp)

ans = 0

# assuming i to be true;
for i in range(n):
	truth = data[i]
	truth = make_dict(i)
	c = check(truth, i)
	ans = max(ans, c)

print(ans)

Submission status: Wrong Answer

Solution code:
import math

def resolve():
    N = int(input())
    A_list = []
    xy_list = []
    for i in range(N):
        A_list.append(int(input()))
        tmp_list = []
        for j in range(A_list[i]):
            tmp_list.append(tuple(int(i) for i in input().split()))
        xy_list.append(tmp_list)

    print(xy_list)
    answer = 0

    for bit in range(1<<N):
        pattern = []
        for j in range(N):
            if (bit & (1<<j)):
                pattern.append(j)
            
        print(pattern)

        for j in range(N):
            if check(j, pattern, xy_list) == 0:
                break
        else:
            answer = max(answer, len(pattern))

    print(answer)

# j : 調べている値
# pattern : pattern
# xy_list : 
# return - 0 : 
#        - 1 : 
def check(j, pattern, xy_list):
    if j in pattern:
        for x, y in xy_list[j]:
            if not y and (x-1 in pattern):
                return 0
            if y and (x-1 not in pattern):
                return 0
        return 1
            

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import math

def resolve():
    N = int(input())
    A_list = []
    xy_list = []
    for i in range(N):
        A_list.append(int(input()))
        tmp_list = []
        for j in range(A_list[i]):
            tmp_list.append(tuple(int(i) for i in input().split()))
        xy_list.append(tmp_list)

    answer = 0

    for bit in range(1<<N):
        pattern = []
        for j in range(N):
            if (bit & (1<<j)):
                pattern.append(j)

        for j in range(N):
            if check(j, pattern, xy_list) == 0:
                break
            else:
                answer = max(answer, len(pattern))

    print(answer)

# j : 1 <= j < N-1
# pattern : 
# xy_list : 
def check(j, pattern, xy_list):
    if j in pattern:
        for x, y in xy_list[j]:
            if not y and (x-1 in pattern):
                return 0
            if y and (x-1 not in pattern):
                return 0
        return 1
            

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
from itertools import product
n=int(input())
XY=[]
ans=0
for i in range(n):
    a=int(input())
    B=[]
    for _ in range(a):
        x,y=map(int,input().split())
        B.append([x-1,y])
    XY.append(B)
seigo = list(product([1,0],repeat=n))
for i in range(2**n):
    kumiawase = seigo[i]
    ninzu = sum(kumiawase)
    flag=0
    for j in range(n):#j+1人目のパターン
        if kumiawase[j]==1:
            for a, b in XY[j]:
                if not((b==1 and kumiawase[a]==1) or (b==0 and kumiawase[a]==0)):
                    flag=1
        else:
            for a,b in XY[j]:
                if not((b==1 and kumiawase[a]==0) or (b==0 and kumiawase[a]==1)):
                    flag=1
    if flag==0:
        ans=max(ans,ninzu)
print(ans)

Submission status: Wrong Answer

Solution code:
#1　正直
#0　不親切

import itertools
N=int(input())
B=[[] for i in range(N)]
for i in range(N):
    A=int(input())
    for j in range(A):
        x,y=map(int,input().split())
        B[i].append((x-1,y))
ans=0
#print(B)
for seq in itertools.product(range(2),repeat=N):
    flag=1
    for i in range(N):
        for r in B[i]:
            x,y=r
            if (seq[i]+seq[x]+y)%2==0:
                flag=0
                break
        if flag==0:
            break
    if flag==1:
        ans=max(ans,sum(seq))
print(ans)

Submission status: Wrong Answer

Solution code:
#1　正直
#0　不親切

import itertools
N=int(input())
B=[[] for i in range(N)]
for i in range(N):
    A=int(input())
    for j in range(A):
        x,y=map(int,input().split())
        B[i].append((x-1,y))
#print(B)
ans=0
for seq in itertools.product(range(2),repeat=N):
    flag=1
    for i in range(N):
        for r in B[i]:
            x,y=r
            if seq[i]==1 and seq[x]!=y:
                flag=0
                #print(1,seq,i,x,y)
                break
            if seq[i]==0 and seq[x]==y:
                flag=0
                #print(0,seq,i,x,y)
                break
        if flag==0:
            break
    if flag==1:
        ans=max(ans,sum(seq))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0]*n
xy = [[] for _ in range(n)]
for i in range(n):
    a[i] = int(input())
    xy[i] = [[int(j) for j in input().split()] for _ in range(a[i])]
ans = 0

for i in range(0,2**n+1):
    cnt = 0
    for j in range(len(a)):
        if i>>j & 1 == 0:
            continue
        st = True
        for k in range(a[j]):
            if i>>(xy[j][k][0]-1) & 1 != xy[j][k][1]:
                st = False
        if st == False:
            break
        cnt += 1
    ans = max(ans, cnt)
            
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
xy=[]
for i in range(n):
    a[i]=int(input())
    hoge=[]*a[i]
    for j in range(a[i]):
        hoge.append(tuple(int(i) for i in input().split()))
    xy.append(hoge)

ans=0
def check(j,pattarn):
    if j in pattarn:
        for x,y in xy[j]:
            if not y and (x-1 in pattarn):
                return 0
        return 1
    else:
        for x,y in xy[j]:
            if y and (x-1 not in pattarn):
                return 0
        return 1

for bit in range(1<<n):
    pattarn = []
    for j in range(n):
        if (bit & (1<<j)):
            pattarn.append(j)

    for j in range(n):
        if check(j,pattarn)==0:
            break
    else:
        ans=max(ans,len(pattarn))
print(ans)

Submission status: Wrong Answer

Solution code:
kinds = {}
N = int(input())
for i in range(N):
  A = int(input())
  for j in range(A):
    x,y = [int(s) for s in input().split()]
    if y == 1:
      kinds[x] = 1
      
print(sum(kinds.values()))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
N_mat = np.ones((N,N)) * -1
count = 0

for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        x -= 1
        if N_mat[i][x] == -1:
            N_mat[i][x] = y
        
        if N_mat[i][x] == N_mat.T[i][x]:
            count += N_mat[i][x] + 1

print(int(count))

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [[-1]*N for i in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        x,y = map(int,input().split())
        D[i][x-1] = y
ans = 0
for i in range(2*(N+1)):
    T = []
    n = i
    for j in range(N):
        T.append(n%2)
        n//=2
    res = 1
    for j in range(N):
        if T[j]==1:
            for k in range(N):
                if D[j][k]!=-1 and D[j][k]!=T[k]:res=0
    if res:ans = max(ans,T.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [[-1]*N for i in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        x,y = map(int,input().split())
        D[i][x-1] = y
ans = 0
for i in range(2*N+1):
    T = []
    n = i
    for j in range(N):
        T.append(n%2)
        n//=2
    res = 1
    for j in range(N):
        if T[j]==1:
            for k in range(N):
                if D[j][k]!=-1 and D[j][k]!=T[k]:res=0
    if res:ans = max(ans,T.count(1)) 
print(ans)

Submission status: Wrong Answer

Solution code:
#python3 
g = [[-1 for _ in range(15)] for _ in range(15)]

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

ans = 0
for i in range(1<<n):
  honests = [0 for _ in range(n)]
  for j in range(n):
    if (i>>j) &1:
      honests[j] = 1 
  ok = True
  for j in range(n):
    if honests[j]:
      for k in range(n):
        if g[j][k] == -1: continue
        if g[j][k] != honests[k]: ok = False
  if ok:
    ans = max(ans, honests.count('1'))

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
A=[[] for i in range(n)]
for i in range(n):
  r=int(input())
  for j in range(r):
    A[i].append(list(map(int,input().split())))
ans=0
L=list(itertools.product([0,1],repeat=n))
for i in L:
  T=[]
  for num,j in enumerate(i):
    if j==1:
      for k in A[num]:
        T.append(k)
if all(i[j[0]-1]==j[1] for j in T):
  ans=max(ans,sum(i))
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
a=[]
x=[]
y=[]
for i in range(n):
    a.append(int(input()))
    x.append([0]*a[i])
    y.append([0]*a[i])
    for j in range(len(x[i])):
        x[i][j],y[i][j]=map(int,input().split())
su=0
um=[]
#print(a,x,y)
um1=0
for k in range(n):
    um1=1<<(k+1)
    for j in range(a[k]):
        um1|(y[k][j]<<x[k][j])
    um.append(um1)
cnt=2**n-1
for i in range(len(um)):
    cnt=cnt&um[i]
ans=0
while cnt>1:
    cnt=cnt//2
    ans+=1
print(ans,um)

Submission status: Wrong Answer

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 (Y[i][j]+P[i]+1)%2 != X[i][j]:
                ok=False
    if ok:
        max_count=max(max_count,sum(P))
print(max_count)

Submission status: Wrong Answer

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[X[i][j]]!=(Y[i][j]+P[i]+1)%2:
                ok=False
    if ok and max_count<sum(P):
        max_count=sum(P)
print(max_count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    n2=int(input())
    a2=[[int(i) for i in input().split()] for i in range(n2)]
    a.append(a2)
maxi=0
for i in range(2**n):
    if i!=5:
        continue
    tf=[False]*n
    for j in range(n):
        if (i>>j)&1:
            tf[j]=True
    judge=[None]*n
    flag=True
    for x,a1 in enumerate(a):
        if flag==False:
            break
        if tf[x]==True:
            torf=True
        else:
            torf=False
        for a2 in a1:
            if torf==True:
                if judge[x]==True or judge[x]==None:
                    if judge[a2[0]-1]==None:
                        if a2[1]==1 and (tf[x]==True or tf[a2[0]-1]==None):
                            judge[a2[0]-1]=True
                        elif a2[1]==0 and (tf[x]==False or tf[a2[0]-1]==None):
                            judge[a2[0]-1]=False
                    elif judge[a2[0]-1]==True:
                        if a2[1]==1:
                            pass
                        else:
                            flag=False
                            break
                    else:
                        if a2[1]==0:
                            pass
                        else:
                            flag=False
                            break
                else:
                    flag=False
                    break
            else:
                if judge[x]==False or judge[x]==None:    
                    if judge[a2[0]-1]==None:
                        pass
                    elif judge[a2[0]-1]==True:
                        if a2[1]==0:
                            pass
                        else:
                            pass
                    else:
                        if a2[1]==1:
                            pass
                        else:
                            pass
                else:
                    flag=False
                    break
    if flag==True:
        maxi=max(maxi,judge.count(True))
print(maxi)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    n2=int(input())
    a2=[[int(i) for i in input().split()] for i in range(n2)]
    a.append(a2)
print(a)
maxi=0
for i in range(2**n):
    if i!=5:
        continue
    tf=[False]*n
    for j in range(n):
        if (i>>j)&1:
            tf[j]=True
    judge=[None]*n
    flag=True
    for x,a1 in enumerate(a):
        if flag==False:
            break
        if tf[x]==True:
            torf=True
        else:
            torf=False
        for a2 in a1:
            if torf==True:
                if judge[x]==True or judge[x]==None:
                    if judge[a2[0]-1]==None:
                        if a2[1]==1 and (tf[x]==True or tf[a2[0]-1]==None):
                            judge[a2[0]-1]=True
                        elif a2[1]==0 and (tf[x]==False or tf[a2[0]-1]==None):
                            judge[a2[0]-1]=False
                    elif judge[a2[0]-1]==True:
                        if a2[1]==1:
                            pass
                        else:
                            flag=False
                            break
                    else:
                        if a2[1]==0:
                            pass
                        else:
                            flag=False
                            break
                else:
                    flag=False
                    break
            else:
                if judge[x]==False or judge[x]==None:    
                    if judge[a2[0]-1]==None:
                        pass
                    elif judge[a2[0]-1]==True:
                        if a2[1]==0:
                            pass
                        else:
                            pass
                    else:
                        if a2[1]==1:
                            pass
                        else:
                            pass
                else:
                    flag=False
                    break
    if flag==True:
        maxi=max(maxi,judge.count(True))
        print(tf,judge,judge.count(True))
print(maxi)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    n2=int(input())
    a2=[[int(i) for i in input().split()] for i in range(n2)]
    a.append(a2)
maxi=0
for i in range(2**n):
    tf=[False]*n
    for j in range(n):
        if (i>>j)&1:
            tf[j]=True
    judge=[None]*n
    flag=True
    for x,a1 in enumerate(a):
        if flag==False:
            break
        if tf[x]==True:
            torf=True
        else:
            torf=False
        for a2 in a1:
            if torf==True:
                if judge[x]==True or judge[x]==None:
                    if judge[a2[0]-1]==None:
                        if a2[1]==1:
                            judge[a2[0]-1]=True
                        else:
                            judge[a2[0]-1]=False
                    elif judge[a2[0]-1]==True:
                        if a2[1]==1:
                            pass
                        else:
                            flag=False
                            break
                    else:
                        if a2[1]==0:
                            pass
                        else:
                            flag=False
                            break
                else:
                    flag=False
                    break
            else:
                if judge[x]==False or judge[x]==None:    
                    if judge[a2[0]-1]==None:
                        pass
                    elif judge[a2[0]-1]==True:
                        if a2[1]==0:
                            pass
                        else:
                            pass
                    else:
                        if a2[1]==1:
                            pass
                        else:
                            pass
                else:
                    flag=False
                    break
    if flag==True:
        maxi=max(maxi,judge.count(True))
print(maxi)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    n2=int(input())
    a2=[[int(i) for i in input().split()] for i in range(n2)]
    a.append(a2)

maxi=0
for i in range(2**n):
    tf=[False]*n
    for j in range(n):
        if (i>>j)&1:
            tf[j]=True
    judge=[None]*n
    flag=True
    for x,a1 in enumerate(a):
        if flag==False:
            break
        if tf[x]==True:
            torf=True
        else:
            torf=False
        for a2 in a1:
            if torf==True:
                if judge[x]==True or judge[x]==None:
                    if judge[a2[0]-1]==None:
                        if a2[1]==1:
                            judge[a2[0]-1]=True
                        else:
                            judge[a2[0]-1]=False
                    elif judge[a2[0]-1]==True:
                        if a2[1]==1:
                            pass
                        else:
                            flag=False
                            break
                    else:
                        if a2[1]==0:
                            pass
                        else:
                            flag=False
                            break
                else:
                    flag=False
                    break
    if flag==True:
        maxi=max(maxi,judge.count(True))

print(maxi)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    n2=int(input())
    a2=[[int(i) for i in input().split()] for i in range(n2)]
    a.append(a2)
maxi=0
for i in range(2**n):
    tf=[False]*n
    for j in range(n):
        if (i>>j)&1:
            tf[j]=True
    judge=[None]*n
    flag=True
    for x,a1 in enumerate(a):
        if flag==False:
            break
        if tf[x]==True:
            torf=True
        else:
            torf=False
        for a2 in a1:
            if torf==True:
                if judge[x]==True or judge[x]==None:
                    if judge[a2[0]-1]==None:
                        if a2[1]==1:
                            judge[a2[0]-1]=True
                        else:
                            judge[a2[0]-1]=False
                    elif judge[a2[0]-1]==True:
                        if a2[1]==1:
                            pass
                        else:
                            flag=False
                            break
                    else:
                        if a2[1]==0:
                            pass
                        else:
                            flag=False
                            break
                else:
                    flag=False
                    break
            else:
                if judge[x]==False or judge[x]==None:    
                    if judge[a2[0]-1]==None:
                        if a2[1]==1:
                            judge[a2[0]-1]=False
                        else:
                            judge[a2[0]-1]=True
                    elif judge[a2[0]-1]==True:
                        if a2[1]==0:
                            pass
                        else:
                            flag=False
                            break
                    else:
                        if a2[1]==1:
                            pass
                        else:
                            flag=False
                            break
                else:
                    flag=False
                    break
    if flag==True:
        maxi=max(maxi,judge.count(True))
print(maxi)

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
Tlist = deque([])
for i in range(N):
    list = []
    n = int(input())
    if n != 0:
        for i in range(n): #因数注意！
            o = input()    
            m = o.split()
            p = [int(j) for j in m] #1列の数列をリスト化
            list.append(p)
    Tlist.append(list)
max = 0
for i in range(2**N):
    p = format(i,'0'+str(N)+'b')
    print(p)
    ALL = True
    for j, value in enumerate(p):
        if value == '0':
            pass
        else:
            if len(Tlist[j]) == 0:
                pass
            else:
                for k in Tlist[j]:
                    if p[k[0]-1] == str(k[1]):
                        pass
                    else:
                        ALL = False
            if ALL:
                pass
            else:
                break
    else:
        new = p.count('1')
        if new > max:
            max = new

print(max)

Submission status: Wrong Answer

Solution code:
N = int(input())

ary = [[-1] * N for i in range(N)]
for i in range(N):
    for j in range(int(input())):
        x, y = map(int, input().split())
        ary[i][x - 1] = y
print(ary)

ret = 0
for a in range(2 ** N):
    flg = True
    for i in range(N):
        if (a >> i & 1) == 1:
            for j in range(N):
                if ary[i][j] == -1:
                    continue
                if (a >> j & 1) != ary[i][j]:
                    flg = False
                    break

    if flg:
        n = sum([a >> i & 1 for i in range(N)])
        ret = max(ret, n)

print(ret)

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
N = int(input())
testimony = [[] for _ in range(N)]
#print(testimony)
for i in range(N):
 num = int(input())
 for j in range(num):
  person, state = map(int, input().split())
  testimony[i].append([person-1, state])

#print(testimony)

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

print(honest)

Submission status: Wrong Answer

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(2 ** N):
    boolean = True
    for i, lis_item in enumerate(evidence):
        if not boolean:
            break
        if (1 << i) & n:
            for j in range(len(lis_item)):
                x, y = lis_item[j][0], lis_item[j][1]
                if ((n >> (x-1)) % 2) != y:
                    boolean = False
                    break
        else:
            for j in range(len(lis_item)):
                x, y = lis_item[j][0], lis_item[j][1]
                y = (y+1) % 2
                if ((n >> (x-1)) % 2) != y:
                    boolean = False
                    break
    if boolean:
        ones = Counter(bin(n))
        ans = max(ans, ones['1'])
print(ans)

Submission status: Wrong Answer

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)

ans = 0
for n in range(2 ** N):
    boolean = True
    tmp = 0
    for i, lis_item in enumerate(evidence):
        if not boolean:
            break
        if (1 << i) & n:
            for j in range(len(lis_item)):
                x, y = lis_item[j][0], lis_item[j][1]
                #print(x, y)
                (n >> (x-1)) % 2
                if (n >> (x-1)) % 2 == y:
                    boolean = True
                else:
                    boolean = False
                    break
        else:
            for j in range(len(lis_item)):
                x, y = lis_item[j][0], lis_item[j][1]
                y = (y+1) % 2
                if (n >> (x-1)) % 2 == y:
                    boolean = True
                else:
                    boolean = False
                    break
    if boolean:
        ones = Counter(bin(n))
        ans = max(ans, ones['1'])

print(ans)

Submission status: Wrong Answer

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

ans = 0
for n in range(2 ** N):
    boolean = True
    tmp = 0
    #print(bin(n))
    for i, lis_item in enumerate(evidence):
        if not boolean:
            break
        if (1 << i) & n:
            #print(i)
            for j in range(len(lis_item)):
                x, y = lis_item[j][0], lis_item[j][1]
                #print(x, y)
                (n >> (x-1)) % 2
                if (n >> (x-1)) % 2 == y:
                    boolean = True
                else:
                    boolean = False
                    break
        else:
            for j in range(len(lis_item)):
                x, y = lis_item[j][0], lis_item[j][1]
                y = (y+1) % 2
                if (n >> (x-1)) % 2 == y:
                    #print(x, y)
                    boolean = True
                else:
                    boolean = False
                    break
    if boolean:
        ones = 0
        for t in range(15, -1, -1):
            if n - 2 ** t >= 0:
                n -= 2 ** t
                ones += 1
            if n == 0:
                break
        ans = max(ans, ones)
        #print(ans)

print(ans)