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:
n = int(input())
lst = [[-1 for _ in range(n)] for _ in range(n)]
for _ in range(n):
    c = int(input())
    for c1 in range(c):
        x, y = map(int, input().split())
        x -= 1
        lst[_][x] = y
        
ans = 0
for bit in range(n**2-1):
    flg = True
    for a in range(n):
        if (bit >> a) & 1:
            for x in range(n):
                if lst[a][x] != -1:
                    if ((bit >> x) & 1) != lst[a][x]:
                        flg = False
                        break
    if flg:
        ans = max(ans, bin(bit)[2:].count('1'))
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
b = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)
    b[x - 1][y].add(i)


fail = lambda x: (not any(a[i][0].isdisjoint(x) and a[i][1] < x for i in x)
                  or any(x & y and x & z for y, z in b))

while n and all(map(fail, map(set, combinations(r, n)))):
  n -= 1
print(n)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
b = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)
    b[x - 1][y].add(i)


fail = lambda x: (not any(a[i][0].isdisjoint(x) and a[i][1] < x for i in r)
                  or any(x & y and x & z for y, z in b))

while n and all(map(fail, map(set, combinations(r, n)))):
  n -= 1
print(n)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
b = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)
    b[x - 1][y].add(i)


fail = lambda x: (not any(y.isdisjoint(x) and z <= x for y, z in a)
                  or any(x & y and x & z for y, z in b))

while n and all(map(fail, map(set, combinations(r, n)))):
  n -= 1
print(n)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
b = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)
    b[x - 1][y].add(i)


fail = lambda x: (not any(y.isdisjoint(x) and z < x for y, z in a)
                  or any(x & y and x & z for y, z in b))

while n and all(map(fail, map(set, combinations(r, n)))):
  n -= 1
print(n)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [[-1 for _ in range(n)] for _ in range(n)]
for _ in range(n):
    c = int(input())
    for c1 in range(c):
        x, y = map(int, input().split())
        x -= 1
        lst[_][x] = y
        
ans = 0
for bit in range(n**2-1):
    flg = True
    for a in range(n):
        if (bit >> a) & 1:
            for x in range(n):
                if lst[a][x] != -1:
                    if ((bit >> x) & 1) != lst[a][x]:
                        flg = False
                        break
    if flg:
        ans = max(ans, bin(bit).count('1'))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [[-1 for _ in range(n)] for _ in range(n)]
for _ in range(n):
    c = int(input())
    for c1 in range(c):
        x, y = map(int, input().split())
        x -= 1
        lst[_][x] = y

ans = 0
for bit in range(n**2):
    flg = True
    for a in range(n):
        if (bit >> a) & 1:
            for x in range(n):
                if lst[a][x] != -1:
                    if ((bit >> x) & 1) != lst[a][x]:
                        flg = False
                        break
    if flg:
        ans = max(ans, bin(bit).count('1'))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[[list(map(int,input().split()))for _ in'_'*int(input())]for _ in'_'*n]
m=0
for i in range(2**n):
  *s,=map(int,bin(i)[2:].zfill(n))
  f=1
  for j,t in enumerate(a):
    g=s[~j]^1
    for x,y in t:f&=s[-x]==y^g
  m=max(m,sum(s)*f)
print(m)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[[list(map(int,input().split()))for _ in'_'*int(input())]for _ in'_'*n]
m=0
for i in range(2**n):
  *s,=map(int,bin(i)[2:].zfill(n))
  f=1
  for j,t in enumerate(a):
    g=i&2**j<1
    for x,y in t:f&=s[-x]==y^g
  m=max(m,sum(s)*f)
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [[-1 for _ in range(n)] for _ in range(n)]
for _ in range(n):
    c = int(input())
    for c1 in range(c):
        x, y = map(int, input().split())
        x -= 1
        lst[_][x] = y
        
ans = 0
for bit in range(n**2 - 1):
    flg = True
    for a in range(n):
        if (bit >> a) & 1:
            for x in range(n):
                if lst[a][x] != -1:
                    if (bit >> x) & lst[a][x] or (bit >> x) == lst[a][x]:
                        pass
                    else:
                        flg = False
    if flg:
        ans = max(ans, bin(bit).count('1'))
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3




def main():
    N = int(input())
    A = []
    X = []
    for i in range(N):
        a = int(input())
        A.append(a)
        x = []
        for i in range(a):
            x.append(list(map(int, input().split())))

        X.append(x)

    # print(A)
    # print(X)
    # print(X[0][0])

    ans = 0
    for i in range(1<<N):
        m = [[] for k in range(N+1)]
        n = [0] * (N+1)
        c = [0] * (N+1)
        for j in range(N):

            if (i>>j) & 1:
                n[j+1] = 1
                for l in range(A[j]):
                    s,t = X[j][l]
                    # print(s, t)
                    m[s].append(t)

        # print(m)
        for k in range(1, N+1):
            if m[k] == []:
                c[k] = 2
            
            elif all(m[k]):
                c[k] = m[k][0]

            # elif 0 in m[k] and 1 in m[k]:
            else:
                continue
            
        tans = 0
        for j in range(1, N+1):
            if (n[j] == 1 and c[j] == 0) or (n[j] == 0 and c[j] == 1):
                tans = -10000
            if c[j] != 0 and n[j] != 0:
                tans += 1
        
        # print(n)
        # print(c)
        # print(tans)
        # print('---')

        ans = max(ans, tans, 0)

    print(ans)



                

    
        

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3




def main():
    N = int(input())
    A = []
    X = []
    for i in range(N):
        a = int(input())
        A.append(a)
        x = []
        for i in range(a):
            x.append(list(map(int, input().split())))

        X.append(x)

    # print(A)
    # print(X)
    # print(X[0][0])

    ans = 0
    for i in range(1<<N):
        m = [[] for k in range(N+1)]
        n = [0] * (N+1)
        c = [0] * (N+1)
        for j in range(N):

            if (i>>j) & 1:
                n[j+1] = 1
                for l in range(A[j]):
                    s,t = X[j][l]
                    # print(s, t)
                    m[s].append(t)

        # print(m)
        for k in range(1, N+1):
            if m[k] == []:
                c[k] = 2
            
            elif all(m[k]):
                c[k] = m[k][0]

            # elif 0 in m[k] and 1 in m[k]:
            else:
                continue
            
        tans = 0
        for j in range(1, N+1):
            if (n[j] == 1 and c[j] == 0) or (n[j] == 0 and c[j] == 1):
                tans = -10000
            if c[j] != 0 and n[j] != 0:
                tans += 1
        
        # print(n)
        # print(c)
        # print(tans)
        # print('---')

        ans = max(ans, tans)

    print(ans)



                

    
        

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(n):
    a = int(input())
    x.append([])
    y.append([])
    for j in range(a):
        u, v = map(int, input().split())
        x[i].append(u)
        y[i].append(v)
ans = 0
for i in range(2 ** n):
    jdg = [False] * n
    used = [False] * n
    end = False
    for j in range(n):
        if ((i >> j) & 1):
            jdg[j] = True
    for j in range(n):
        for k in range(n):
            if ((not jdg[k]) or used[k]):
                continue
            used[k] = True
            for l in range(len(x[k])):
                if (y[k][l] == 1):
                    jdg[x[k][l] - 1] = True
                elif (jdg[x[k][l] - 1]):
                    end = True
                    break
            if (end):
                break
        if (end):
            break
    if (end):
        continue
    ans = max(sum(jdg), ans)

print(ans)

Submission status: Wrong Answer

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)
  

c=0
for i in range(n):
  l=[1]*n
  for j in range(i,n-i):
    if l[j]==0:continue
    for k in range(len(X[j])):
      b=X[j][k]
      l[b-1]*=Y[j][k]
  if c < l.count(1):
    c=l.count(1) 
  
        
  
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
Ans = []
for i in range(n):
    Ai = int(input())
    a = []
    for j in range(Ai):
        x,y = map(int,input().split())
        a.append((x,y))
    Ans.append(a)
Honest = 0
TT = [bin(i)[2:].zfill(n) for i in range(2**n)]
for truth in TT:
    truth = str(truth)
    people = [-1]*n
    for i in range(n):
        flag = True
        tt = truth[i]
        answers = Ans[i]
        if tt == "1":
            for x,v in answers:
                if v:
                    if people[x-1] == -1 or people[x-1] == 1:
                        people[x-1] = 1
                    else:
                        flag = False
                else:
                    if people[x-1] == -1 or people[x-1] == 0:
                        people[x-1] = 0
                    else:
                        flag = False
        else:#tt = "0"
            for x,v in answers:
                if v == 0:
                    if people[x-1] == -1 or people[x-1] == 1:
                        people[x-1] = 1
                    else:
                        flag = False
                else:
                    if people[x-1] == -1 or people[x-1] == 0:
                        people[x-1] = 0
                    else:
                        flag = False
    if flag:
        #print(truth)
        for i in range(len(people)):
            if people[i] == -1:
                people[i] = 0
        #print(*people)
        Honest = max(Honest,sum(people))
print(Honest)

Submission status: Wrong Answer

Solution code:
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x=[0]*a
    y=[0]*a
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  

c=0
for i in range(n):
  l=[1]*n
  for j in range(i,n-i):
    if l[j]==0:continue
    for k in range(A[j]):
      b=X[j][k]
      #l[b] *= Y[j][k]

if c < l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
Ans = []
for i in range(n):
    Ai = int(input())
    a = []
    for j in range(Ai):
        x,y = map(int,input().split())
        a.append((x,y))
    Ans.append(a)
Honest = 0
TT = [bin(i)[2:].zfill(n) for i in range(2**n)]
for truth in TT:
    truth = str(truth)
    people = [-1]*n
    for i in range(n):
        flag = True
        tt = truth[i]
        answers = Ans[i]
        if tt == "1":
            for x,v in answers:
                if v:
                    if people[x-1] == -1 or people[x-1] == 1:
                        people[x-1] = 1
                    else:
                        flag = False
                else:
                    if people[x-1] == -1 or people[x-1] == 0:
                        people[x-1] = 0
                    else:
                        flag = False
        else:#tt = "0"
            for x,v in answers:
                if v == 0:
                    if people[x-1] == -1 or people[x-1] == 1:
                        people[x-1] = 1
                    else:
                        flag = False
                else:
                    if people[x-1] == -1 or people[x-1] == 0:
                        people[x-1] = 0
                    else:
                        flag = False
    if flag:
        #print(*people)
        Honest = max(Honest,sum(people))
print(Honest)

Submission status: Wrong Answer

Solution code:
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x=[0]*a
    y=[0]*a
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  

c=0
for i in range(n):
  l=[1]*n
  for j in range(i,n-i):
    if l[j]==0:continue
    for k in range(A[j]):
      b=2
      #b=X[j][k]
      #l[b] *= Y[j][k]

if c < l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  

c=0
for i in range(n):
  l=[1]*n
  for j in range(i,n-i):
    if l[j]==0:continue
    for k in range(A[j]):
      b=2
      #b=X[j][k]
      #l[b] *= Y[j][k]

if c < l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
info = [[] for i in range(n)]
for i in range(n):
    a = int(input())
    info[i] = [tuple(map(int, input().split())) for _ in range(a)]

ans = 0
for bit in range(1 << n):
    flag = True
    cnt = 0
    for i in range(n):
        if (bit >> i) & 1:
            t = 0
            cnt += 1
        else:
            t = 1
        for x, y in info[i]:
            b = (bit >> (x - 1)) & 1
            if b != abs(t - y):
                flag = False
                break
        if not flag:
            break
    if flag:
        ans = max(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list()
xy = list()
for i in range(n):
  A = int(input())
  XY = [tuple(map(int,input().split())) for i in range(A)]
  a.append(A)
  xy.append(XY)
ans = 0
for i in range(2 ** n-1,-1,-1):
  mini_ans = 0
  honest = []
  for j in range(n):
    honest.append(i % 2)
    i = i // 2
  for k,v in enumerate(honest):
    if v:
      mini_ans += 1
      for x,y in xy[k]:
        x -= 1
        if honest[x] != y:
          break
        else:
          continue
        break
    else:
      ans = max(ans,mini_ans)
      continue
print(ans)

Submission status: Wrong Answer

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

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

cand = [0] * N
ans = 0
def func(pos):
    global ans
    if pos == N:
        possible = 0
        flag = True
        for i in range(N):
            test = collect[i]
            for x, y in test:
                if cand[x] != y:
                    if cand[i] == 1:
                        return
                    flag = False
            if flag:        
                possible += 1
        ans = max(ans, possible)
        return

    cand[pos] = 0
    func(pos+1)
    cand[pos] = 1
    func(pos+1)
    return

func(0)
print(ans)

Submission status: Wrong Answer

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

if c < l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Wrong Answer

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

if c < l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Wrong Answer

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

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

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

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

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


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

from queue import PriorityQueue as pq

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

from operator import mul
from functools import reduce

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

import random

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


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

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

                    elif ll_xy[j][k][1] == 1:
                        if check(p,1,bin_str):
                            pass
                        else:
                            failure_flag=1
        if failure_flag==0:
            cnt+=1
            ans_temp=0
            for x in bin_str:
                if x==1:
                    ans_temp+=1
            ans=max(ans_temp,ans)
    print(ans)
    return
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

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

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


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

from queue import PriorityQueue as pq

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

from operator import mul
from functools import reduce

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

import random

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


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

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

                    elif ll_xy[j][k][1] == 1:
                        if check(p,1,bin_str):
                            pass
                        else:
                            failure_flag=1
        if failure_flag==0:
            cnt+=1
            ans_temp=0
            for x in bin_str:
                if x==1:
                    ans_temp+=1
            ans=max(ans_temp,ans)
    print(ans)
    return
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())

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

# print(a)
# print(xy)

num = [x for x in range(n)]
res = 0

for i in reversed(range(1, n + 1)):
    combi = list(itertools.combinations(num, i))
    # print('combi', combi)
    for c in combi:
        ans = [1] * n
        for j in range(len(c)):
            ans[c[j]] = 0

        # print('ans', ans)

        flag = True

        for p in range(n):
            for q in range(len(xy[p])):
                x = int(xy[p][q][0]) - 1
                y = int(xy[p][q][1])
                s = ans[p]
                # print(x + 1, y, s + 1)
                if s == 1:
                    if ans[x] != y:
                        # print('ng1')
                        flag = False
                        break
                if s == 0:
                    if ans[x] == y:
                        # print('ng2')
                        flag = False
                        break
        if flag:
            # print('ok')
            res = max(res, sum(ans))
            # print('sum', res)

# print('result', max(res, 0))
print(res)

Submission status: Wrong Answer

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

if c < l.count(1):
  c=l.count(1) 
  
        
  
print(c)

Submission status: Wrong Answer

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

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

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

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

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


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

from queue import PriorityQueue as pq

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

from operator import mul
from functools import reduce

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

import random

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


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

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

                    elif ll_xy[j][k][1] == 1:
                        if check(p,"1",bin_str):
                            pass
                        else:
                            failure_flag=1
        if failure_flag==0:
            cnt+=1
            ans_temp=0
            for x in bin_str:
                if x=="1":
                    ans_temp+=1
            ans=max(ans_temp,ans)
    print(ans)
    return
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())

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

# print(a)
# print(xy)

num = [x for x in range(n)]
res = 0

for i in reversed(range(1, n + 1)):
    combi = list(itertools.combinations(num, i))
    # print('combi', combi)
    for c in combi:
        ans = [1] * n
        for j in range(len(c)):
            ans[c[j]] = 0

        # print('ans', ans)

        flag = True

        for p in range(n):
            for q in range(len(xy[p])):
                x = int(xy[p][q][0]) - 1
                y = int(xy[p][q][1])
                s = ans[p]
                # print(x + 1, y, s + 1)
                if s == 1:
                    if ans[x] != y:
                        # print('ng1')
                        flag = False
                        break
                if s == 0:
                    if ans[x] == y:
                        # print('ng2')
                        flag = False
                        break
        if flag:
            # print('ok')
            res = max(res, sum(ans))
            # print('sum', res)

# if not flag:
#    print('result', 0)

# print('result', max(res, 0))
print(max(res, 0))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
l = []
for i in range(n):
    a = int(input())
    for j in range(a):
        a1, a2 = map(int, input().split())
        l.append([i, a1-1, a2])
ans = 0
for i in range(1 << n):
    uso = False
    # print(i)
    for ll in l:
        # ll[0]が正直なのかをチェック]
        # print(ll)
        if i >> ll[0] & 1:  # 正直
            if ((i >> ll[1]) & 1) == ll[2]:
                pass
            else:
                uso = True
                break
        else:  # 嘘
            if ((i >> ll[1]) & 1) == ll[2]:
                uso = True
                break
    if uso == False:
        # print(bin(i))
        ans = max(ans, len(str(bin(i)).replace('0b', "").replace('0', "")))
print(ans)