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

Solution (Python):
N = int(input())



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


max_count = 0
failed = False
for i in range(2 ** N):
    results = [-1] * N
    shoujiki = 0
    for j in range(len(testimony_list)):
        
        
        
        if i >> j & 1:
            shoujiki += 1
            
            array = testimony_list[j]
            for k in range(len(array)):
                
                
                
                
                if not (i >> k & 1) and array[k] == 1:
                    
                    failed = True
                    break
                elif (i >> k & 1) and array[k] == 0:
                    
                    failed = True
                    break
                if array[k] == -1:
                    continue
                if results[k] == -1:
                    results[k] = array[k]
                elif results[k] != array[k]:
                    
                    failed = True
                    break
        if failed is True:
            
            
            break
    if failed is True:
        failed = False
        continue
    
    
    
    
    
    
    
    if max_count < shoujiki:
        max_count = shoujiki
print(max_count)

Solution (Python):



import sys


from itertools import product

N = int(input())
A = [0] * N
x = []

for i in range(N):
    A[i] = int(input())
    d = []
    for j in range(A[i]):
        d.append(tuple(map(int, input().split())))
    x.append(d)



ans = 0
for case in list(product([0,1], repeat=N)):
    

    flg = [-1] * N
    cond = True
    for i in range(N):
        if not cond:
            continue
        if case[i] == 0:
            continue

        for a in range(A[i]):
            c, d = x[i][a]
            c = c-1

            
            if case[c] != d:
                cond = False
                
    if cond:
        ans = max(ans, sum(case))

print(ans)

Solution (Python):
n = int(input())
shougen=[[-1]*(n+1) for _ in range(n+2)]
for i in range(1,n+1):
  a = int(input())
  for j in range(a):
    x,y = map(int, input().split())
    
    shougen[i][x]=y

ans=0

for i in range(2**n):
  f=True
  for j in range(n):
    if i>>j & 1:
      for k,s in enumerate(shougen[j+1][1:],start=0):
        if s == 1 and not i>>k & 1:
          f=False
        if s == 0 and i>>k & 1:
          f=False
  else:
    if f:
      ans=max(ans, str(bin(i)).count("1"))

print(ans)

Solution (Python):
n = int(input())
test = []
for i in range(n):
  m = int(input())
  said = [list(map(int, input().split())) for _ in range(m)]
  test.append(said)
  
def NotContradict(i):
  lst = [0]*n
  for j in range(len(bin(i))):
    if (i >> j) & 1:
      lst[j] = 1
  for j in range(n):
    if lst[j]:
      for k in range(len(test[j])):
        if lst[test[j][k][0]-1] != test[j][k][1]: 
          return False
  return True

ans = 0
for i in range(2**n):
  if NotContradict(i):
    count = 0
    for j in range(len(bin(i))):
      if (i >> j) & 1:
        count += 1
    ans = max(ans, count)
        
print(ans)

Solution (Python):
n = int(input())
shogens = []

for i in range(n):
    a = int(input())
    shogens.append([])

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


def is_honest(i, j):
    return (i >> j) % 2 == 0


def honest_cnt(i):
    ans = 0
    for j in range(n):
        ans += is_honest(i, j)

    return ans


ans = 0
for i in range(1 << n):
    ok = True
    for j in range(n):
        if not is_honest(i, j):
            continue
        for x, y in shogens[j]:
            if y == 0 and is_honest(i, x):
                ok = False
            if y == 1 and not is_honest(i, x):
                ok = False

    if ok:
        ans = max(ans, honest_cnt(i))


print(ans)

Solution (Python):
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    query = [[] for _ in range(n)]
    for i in range(n):
        a = int(input())
        for _ in range(a):
            x, y = map(int, input().split())
            query[i].append([x - 1, y])

    res = 0
    for pattern in product([0, 1], repeat=n):
        for idx, p in enumerate(pattern):
            if p == 1:
                for x, y in query[idx]:
                    if pattern[x] != y:
                        break
                else:
                    continue
                break
        else:
            res = max(res, sum(pattern))

    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
n = int(input())
lst = []

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

ans = 0





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

Solution (Python):

def main():
  N = int(input())

  
  p = [[-1 for i in range(N)] for j in range(N)]

  ans = 0

  for i in range(N):
    A = int(input())

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


  for i in range(1 << N):
    d = [0] * N

    for j in range(N):
      
      
      if(i >> j & 1):
        d[j] = 1

    ok = True
    
    for j in range(N):
      if(d[j]):
        for k in range(N):
          if(p[j][k] == -1):
            continue
          if(p[j][k] != d[k]):
            ok = False

    if(ok):
      ans = max(ans, bin(i).count("1"))

  print(ans)

if __name__ == "__main__":
    main()

Solution (Python):

def main():
  N = int(input())

  
  p = [[] for _ in range(N)]

  ans = 0

  for i in range(N):
    A = int(input())

    for j in range(A):
      p[i].append(list(map(int, input().split())))

  for i in range(1 << N):
    d = [0] * N

    for j in range(N):
      
      
      if(i >> j & 1):
        d[j] = 1

    ok = True
    
    for j, _ in enumerate(p):
      
      
      if(d[j]):

        for k, _ in enumerate(p[j]):
          x, y = p[j][k]
          x -= 1
          if(d[x] != y):
            ok = False

    if(ok):
      
      ans = max(ans, bin(i).count("1"))

  print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import itertools
N = int(input())
dic = {}
cnt = 0
ok = []
for i in range(N):
  A = int(input())
  for j in range(A):
    x,y = (int(t) for t in input().split())
    dic[(i,x)] = y
for i in itertools.product([0,1],repeat=N):
  for k in dic.keys():
    if i[k[0]] == 0:
      continue
    if dic[k] != i[k[1]-1]:
      break
  else:
    ok += [i]
mm = 0
for i in ok:
  mm = max(mm,sum(i))
print(mm)

Solution (Python):
import itertools
def main():
    N = int(input())
    syougen = [None]
    for _i in range(N):
        A = int(input())
        aa = []
        for _j in range(A):
            aa.append(tuple(int(c) for c in input().split(' ')))
        syougen.append(aa)
    
    max_t = 0
    for baai in itertools.product([True, False], repeat=N):
        
        mujun = False
        for i in range(1, N+1):
            flag = baai[i-1]
            for x, y in syougen[i]:
                if flag:
                    if y==1 and baai[x-1]==False:
                        mujun=True
                        break
                    elif y==0 and baai[x-1]==True:
                        mujun=True
                        break
        if mujun:
            continue
        else:
            max_t = max(max_t, sum(baai))

    print(max_t)

if __name__ == "__main__":
    main()

Solution (Python):
import itertools
import numpy as np
n = int(input())
dic_ = {}
for i in range(n):
    m = int(input())
    for j in range(m):
        x, y = map(int, input().split())
        dic_[(i,x)] = y

ok = []
for i in itertools.product([0,1],repeat=n):
    for k in dic_.keys():
        if i[k[0]] == 0:
            continue
        if dic_[k] != i[k[1]-1]:
            break
    else:
        ok += [i]
mm = 0
for i in ok:
    mm = max(mm, sum(i))
print(mm)

Solution (Python):
n = int(input())
l = [[-1 for _ in range(n)] for _ in range(n)]
for i in range(n):
    m = int(input())
    for j in range(m):
        x,y = [int(i) for i in input().split()]
        l[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
    flg = 1
    for k in range(n):
        if honests[k]:
            for h in range(n):
                if l[k][h] == -1 : continue
                if l[k][h] != honests[h] : flg = 0
    
    if flg:
        ans = max(ans,sum(honests))
        
print(ans)

Solution (Python):

n=int(input())
a=[0]*n
x=[[]*n for i in range(n)]
for i in range(n):
    a[i]=int(input())
    for ii in range(a[i]):
        xi,yi=map(int,input().split())
        x[i].append([xi-1,yi])
        
import itertools
ans=0
for i in itertools.product([0,1], repeat=n):
    yn=""
    for j in range(n):

        if i[j]==1:
            for xx in x[j]:

                if i[xx[0]]!=xx[1]:
                    yn="No"
                    break

    if yn!="No":
        ans=max(ans,sum(i))

print(ans)

Solution (Python):
def make_bit(n):
    bit = []
    for i in range(2**n):
        bit.append(bin(i)[2::])
    i = 0
    while i < len(bit):
        while len(bit[i]) < len(bin(2**n-1)[2::]):
            bit[i] = "0" + bit[i]
        i += 1

    return bit

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



bit = make_bit(n)
ans = 0
for i in bit:
    tmp = [0 for _ in range(n)]
    NO = 0
    cnt = 0
    for j in range(n):
        if i[j] == "1":
            cnt += 1
            for x, y in xy_list[j]:
                if y and i[x-1] == "0":
                    NO = 1
                    break
                if not y and i[x-1] == "1":
                    NO = 1
                    break
        if NO:
            break

    if not NO:
        
        ans = max(ans, cnt)
print(ans)

Solution (Python):
import itertools


def main():
    N = int(input())
    
    testimony = [[[] for _ in range(2)] for _ in range(N)]
    for i in range(N):
        A = int(input())
        for _ in range(A):
            x, y = list(map(int, input().split(' ')))
            x -= 1
            testimony[i][y].append(x)
    
    max_honest = 0
    for pattern in itertools.product([0, 1], repeat=N):
        num_honest = sum(pattern)
        if max_honest > num_honest:
            continue
        is_valid = True
        for i, y in enumerate(pattern):
            
            if y == 0:
                
                continue
            for yy in [0, 1]:
                ith_testimony = testimony[i][yy]
                for j in ith_testimony:
                    if pattern[j] != yy:
                        is_valid = False
                        break
                if not is_valid:
                    break
            if not is_valid:
                break
        if is_valid:
            max_honest = sum(pattern)
    print(max_honest)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
shogen=[[]for _ in range(n)]
for i in range(n):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        shogen[i].append((x,y))

ans = 0
def dfs(i,tf):
    global ans
    if i == n:
        ok = True
        for j,a in enumerate(tf):
            if a == True:
                for x,y in shogen[j]:
                    if tf[x-1] == y:
                        pass
                    else:
                        ok = False
        if ok==True:
            ans = max(ans,tf.count(1))
        return
    else:
        dfs(i+1,tf+[True])
        dfs(i+1,tf+[False])

dfs(0,[])
print(ans)

Solution (Python):
N = int(input())
XY = [[] for _ in range(N)]
for i in range(N):
    c = int(input())
    XY[i] = [[int(j) for j in input().split()] for _ in range(c)]

"""
・N < 15
・O(N * 2^N)
"""


def popcnt(n):
    return bin(n).count('1')


def func(bits):
    for i in range(N):
        if (bits >> i) & 1 == 0:
            continue
        for x, y in XY[i]:
            x -= 1  
            if (bits >> x) & 1 != y:
                return False
    return True


ans = 0
for mask in range(1 << N):
    if func(mask):
        tmp = popcnt(mask)
        ans = max(ans, tmp)
print(ans)

Solution (Python):
from sys import stdin

N = int(input())
XY = [[] for _ in range(N)]
max_honest = 0

for i in range(N):
    A = int(input())
    for j in range(A):
        xy = list(map(int,stdin.readline().rstrip().split()))
        XY[i].append(xy)

for i in range(2**N):
    honest = True
    bin_list = list(format(i,'015b'))
    bin_list.reverse()
    for j in range(N):
        if bin_list[j] == '1':
            for p in XY[j]:
                if int(bin_list[p[0]-1]) != p[1]:
                    honest = False
    if honest:
        max_honest = max(max_honest,bin_list.count('1'))

print(max_honest)

Solution (Python):



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


pattern = []
for i in range(2**N):
    p = [0]*N
    for j in range(N):
        if (i>>j)&1==1:
            p[j] = 1
    pattern.append(p)
max_count = 0


for p in pattern:
    is_ok = True
    num_count = 0
    for i in range(N):
        
        if p[i]==1:
            num_count += 1
            shogen = shogen_list[i]
            if len(shogen)==0:
                continue
            else:
                for s in shogen:
                    x = s[0]
                    y = s[1]
                    if not p[x-1]==y:
                        is_ok = False
                        break
    if is_ok:
        max_count = max(max_count, num_count)


print(max_count)

Solution (Python):
N=int(input())
tlst=[]

for i in range(N):
    t=int(input())
    tlst.append([list(map(int,input().split())) for _ in range(t)])
ans=0
for i in range(2**N):
    bit=[0]*N
    cnt=0
    for j in range(N):
        if (i>>j)&1==1:
            bit[j]=1
            cnt+=1
    
    for j in range(N):
        if bit[j]==1:
            for xt,yt in tlst[j]:
                if bit[xt-1]!=yt:
                    cnt=-1
                    break
            
            if cnt==-1:
                break
    
    ans=max(ans,cnt)

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = []
xy = []
for i in range(N):
    a = int(input())
    A.append(a)
    temp = []
    for j in range(a):
        x,y= map(int,input().split())
        temp.append((x,y))
    xy.append(temp)

ans = 0
for i in range(2**N):
    b = bin(i)[2:].zfill(N)
    valid = True
    for i in range(N):
        if b[i] == '0':
            continue
        else:
            for x,y in xy[i]:
                if int(b[x-1]) != y:
                    valid = False
                    break
    if valid:
        ans = max(ans, b.count('1'))

print(ans)

Solution (Python):
n = int(input())
x = []
for i in range(n):
    a = int(input())
    tmp = [list(map(int, input().split())) for _ in range(a)]
    x.append(tmp)
    
max_ = 0
for bit in range(1 << n):

    flag = 0
    cnt = 0
    for i in range(n):
        if (bit & (1<<i)):

            cnt += 1
            for v in x[i]:
                if bool(bit & (1<<(v[0] - 1))) != bool(v[1]):

                    flag = 1
                    break
            if flag == 1:
                break

    if flag == 0:
        if max_ < cnt:

            max_ = cnt
print(max_)

Solution (Python):
n=int(input())
facts=[]
lies=[]
def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

for i in range(n):
    fact=0
    lie=0
    q=int(input())
    for j in range(q):
        x,y=map(int,input().split())
        if y==0:
            lie+=1<<(x-1)
        else:
            fact+=1<<(x-1)
    lies.append(lie)
    facts.append(fact)

ans=0
for i in range(1<<n):
    flag=True
    for j in range(n):
        if i&(1<<j):
            fact=facts[j]
            lie=lies[j]
            if (fact != (fact&i)) or (lie!=(lie&~i)):
                flag=False
                break
    if flag:
        ans=max(ans,popcnt(i))
print(ans)
"""
3
3
1 1
2 1
3 1
1
1 1
1
1 1

"""

Solution (Python):
def main():
    hatsugen_dic = {}
    inlis = []
    anslis = []

    n= int(input())
    for s in range(n):
        a = int(input())
        for _ in range(a):
            inlis.append(list(map(int, input().split())))
        hatsugen_dic[s] = inlis
        
        inlis = []
    

    for i in range(2**n - 1, -1, -1):   
        cnt = 0
        for j in range(n):              
            
            if ((i >> j) & 1):          
                hatsugen_j = hatsugen_dic[j]            
                for k in range(len(hatsugen_j)):        
                    if ((i>>(hatsugen_j[k][0]-1)) + hatsugen_j[k][1]) % 2 == 0:
                        
                        pass
                    else:
                        
                        
                        cnt += 1
        if cnt == 0:
            count = 0
            while i:
                count += i & 1
                i >>= 1
            
            anslis.append(count)
    print(max(anslis))




if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a = [0]*20
x=[[0 for i in range(20)]for j in range(20)]
y=[[0 for i in range(20)]for j in range(20)]
 
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())
		x[i][j]-=1
 
ans=0
for bits in range(1<<n):
	isok=True
	for i in range(n):
		if (bits>>i)&1 == 0:
			continue
		for j in range(a[i]):
			if y[i][j]^((bits>>x[i][j])&1):
				isok=False
	if isok:
		tmp=bits
		an=0
		while(tmp):
			if tmp&1:
				an+=1
			tmp//=2
		ans = max(ans,an)
print(ans)

Solution (Python):
N=int(input())

S=[ [] * 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())
    
    S[i].append([x-1,y])

ans=0
P=[0]*N

for i in range(2**N):
  tmp=0
  for j in range(N):
    if P[j]==0:
      P[j]=1
      break
    else:
      P[j]=0
  
  if sum(P)<=ans:
    continue
  flag=0
  for p in range(len(P)):
    if P[p]==1:
      for s in S[p]:
        if s[1]!=P[s[0]]:
          flag=1
  if flag==1:
    continue
  else:
    ans=sum(P)
print(ans)

Solution (Python):
ii = lambda:int(input())
li = lambda:list(map(int,input().split()))
lix = lambda x:list(li() for _ in range(x))

def main(n,a):
    res = 0
    ran = 2**n
    for tar in range(1,ran):
        check = True
        for i in range(n):
            if tar>>i & 1 and not isHonest(tar, a[i]):
                check = False
                break
        if check : res = max(res, count(tar,n))
    return res                

def count(tar, n):
    res = 0
    for i in range(n):
        if tar>>i & 1 : res += 1
    return res

def isHonest(tar, a):
    res = True
    for i in range(len(a)):
        x,y = a[i]
        if tar>>(x-1) & 1 != y : return False
    return True

n = ii()
a = []
for i in range(n):
    c = ii()
    a.append(lix(c))
print(main(n,a))

Solution (Python):
N = int(input())
List = [[] for _ in range(N)] 
for i in range(N):
  A = int(input())
  List[i] = [list(map(int, input().split())) for _ in range(A)]

ans = 0
for j in range(2**N):
  x = 0
  for k in range(N):
    if ((j >> k) & 1):
      for l in range(len(List[k])):
        if ((j >> (List[k][l][0]-1)) & 1) != List[k][l][1]:
          break
      else:
        x += 1
        continue
      break
  else:
    if ans < x:
      ans = x
print(ans)

Solution (Python):
n = int(input())
ls = []
for i in range(n):
    a = int(input())
    p = []
    for i in range(a):
        x,y = map(int,input().split())
        p.append([x-1,y])
    ls.append(p)

ans = 0

for i in range(2**n):
    flag = 0
    for j in range(n):
        if (i >> j)&1:
            for k in ls[j]:
                if (i >> k[0])&1 != k[1]:
                    flag = 1
                    break
    if flag == 0:
        ans = max(ans, bin(i)[2:].count('1'))
print(ans)

Solution (Python):
from itertools import product

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

ans = 0
for i in product([1, 0], repeat=n):
    s = True
    for j in data:
        if i[j[0]] == 1 and i[j[1]] != j[2]:
            s = False
            break
    if s:
        ans = max(ans, sum(i))
print(ans)

Solution (Python):
from itertools import product
N=int(input())
data=[]
for i in range(N):
    for j in range(int(input())):
        x,y=map(int,input().split())
        data.append((i,x-1,y))


ans=0
for i in product([1,0],repeat=N):
    
    s=True
    for k in data:
        if i[k[0]]==1 and i[k[1]]!=k[2]:
            s=False
            break
    if s:
        ans=max(ans,sum(i))
print(ans)

Solution (Python):

from itertools import*
I = input
n = int(I())
c = 0;z = []
for i in range(n):
    for j in range(int(I())):
        z += [[i] + list(map(int, I().split()))]
for j in product([0,1], repeat=n):
    if all(j[i] == 0 or j[x-1] - y == 0 for i, x, y in z):
        c = max(c, sum(j))
print(c)

Solution (Python):
n = int(input())
comments = []

for i in range(1, n+1):
  comment = []
  for _ in range(int(input())):
    comment.append(list(map(int, input().split())))
  comments.append(comment)
  
check_lists = []
ans = 0

for j in range(2**n):
  check_list = []
  index_list = []
  for k in range(n):
    if j & 1<<k:
      index_list.append(k)
      for comment_i in comments[k]:
        check_list.append(comment_i)
  
  case_result = True
  
  for check_list_i in check_list:
    ind, flg = check_list_i
    
    if ind-1 in index_list and flg==0:
      case_result = False
      break
    if ind-1 not in index_list and flg==1:
      case_result = False
      break
  
  if case_result:
    ans = max(ans, len(index_list))
    
print(ans)

Solution (Python):
def main():
    
    n = int(input())

    boolls = [[]]
    for i in range(n):
        tmpls = []
        for x in boolls:
            y = x.copy()
            x.append(True)
            y.append(False)
            tmpls.append(x)
            tmpls.append(y)
        boolls = tmpls

    boolls.sort(key=lambda _: _.count(True), reverse=True)

    xyls = []
    for i in range(n):
        ai = int(input())
        tuples = []
        for j in range(ai):
            x, y = map(int, input().split())
            tuples.append((x, y == 1))
        xyls.append(tuples)

    tmpTrueCnt = n
    max_cnt = 0
    for boolx in boolls:
        truecnt = boolx.count(True)
        if truecnt == 0:
            break
        if max_cnt > truecnt:
            break

        if tmpTrueCnt > truecnt:
            tmpTrueCnt = truecnt

        ok = True
        for i in range(len(boolx)):
            tf = boolx[i]
            if tf:
                for message in xyls[i]:
                    if boolx[message[0] - 1] != message[1]:
                        ok = False
                        break
            if not ok:
                break
        if ok:
            max_cnt = tmpTrueCnt
            break

    print(max_cnt)


main()

Solution (Python):
n=int(input())
a=[]
xy=[]
for i in range(n):
  a.append(int(input()))
  xy.append([list(map(int,input().split())) for _ in range(a[-1])])


def dfs(seen_,i):
  seen=seen_.copy()
  seen[i]=1 
  todo=[]
  todo.append(i)
  while len(todo)>0:
    b=todo.pop()
    if seen[b]==1:
      l=xy[b]
      for li in l:
        if seen[li[0]-1]==-1:
          seen[li[0]-1]=li[1]
          if li[1]==1:
            todo.append(li[0]-1)
        elif seen[li[0]-1]!=li[1]:
          seen_[i]=0
          return seen_
  return seen

ans=0
for i in range(n):
  seen=[-1]*n
  seen[i]=1
  seen=dfs(seen,i)
  
  while seen.count(-1)>0:
    j=[k for k,v in enumerate(seen) if v==-1][0]
    seen=dfs(seen,j)
  ans=max(ans,seen.count(1))
print(ans)

Solution (Python):
import math
import itertools





N = int(input())
ans = [[-1] * N for i in range(N)]


for person in range(N):
    A = int(input())
    for _ in range(A):
        x, y = map(int, input().split())
        x -= 1
        ans[person][x] = y


def is_ok(num):
    
    
    
    people = [-1] * N
    for i in range(N):
        
        if((num >> i) & 1):
            if(people[i] == 0):
                return False
            people[i] = 1
            for j in range(N):
                if(ans[i][j] == 1):
                    if(people[j] == 0):
                        return False
                    people[j] = 1
                if(ans[i][j] == 0):
                    if(people[j] == 1):
                        return False
                    people[j] = 0
        else:
            if(people[i] == 1):
                return False
            people[i] = 0

    return True


def countBit(num):
    ori = num
    count = 0
    while(num > 0):
        if(num & 1):
            count += 1
        num = num >> 1
    return count


out = 0

for i in range(1 << N):
    if(is_ok(i)):
        out = max(out, countBit(i))

print(out)

Solution (Python):
n = int(input())
alist = []
xy = [[] for i in range(n)]
ans = 0
for i in range(n):
    xy[i] =  []
for i in range(n):
    alist.append(int(input()))
    for j in range(alist[i]):
        a,b=input().split()
        xy[i].append([int(a), int(b)])
g = [[] for i in range(2**n-1)]
for i in range(1,2**n):
    for j in range(n):
        if list(format(i,'0b').zfill(n))[j] == '1':
            g[i-1].append(xy[j])
def lie(xy,p):
    z = list(format(p,'0b').zfill(n)) 
    for i in range(len(xy)):
        for j in range(len(xy[i])):
            if str(xy[i][j][1]) == z[xy[i][j][0]-1]:
                continue
            else:
                return 'No'
                break
    return 'Yes'
for k in range(2**n-1):
    if lie(g[k],k+1) == 'Yes':
        ans = max(ans,list(str(format(k+1,'0b'))).count('1'))
print(ans)

Solution (Python):

import collections
import itertools as it
import math

 
n  = int(input())



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



for i in range(2 ** n): 
    is_honest = [not(bool(int(s))) for s in list('{:015b}'.format(i)[-n:])]
    is_ok = True
    for i, h in enumerate(list(is_honest)): 
        for x, y in xy[i]: 
            if is_honest[i] == False:
                continue

            x = x - 1
            v = bool(int(y))
            
            
            if is_honest[x] == v:
                pass
            else:
                is_ok = False
    
    if is_ok:
        i
        print(sum(is_honest))
        break

Solution (Python):
n = int(input())
a,x = [],[]
for i in range(n):
    a.append(int(input()))
    xy=[list(map(int,input().split())) for _ in range(a[i])]
    x.append(xy)
ans = 0
for i in range(2**n):
    cnt = 0
    for j in range(n):
        if i&(1<<j):
            for k,l in x[j]:
                if (i>>(k-1))&1!=l:
                    cnt=1
                    break
    if cnt==0:
        ans = max(ans,bin(i).count("1"))

print(ans)

Solution (Python):

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

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

cnt = 0
for i in range(2**N):
    flag = True
    for j in range(N):
        if (i>>j)&1 == 1:
            for x,y in tes[j]:
                if (i>>x)&1 != y:
                    flag = False
                    break
    if flag:
        cnt = max(cnt,bin(i)[2:].count("1"))
print(cnt)

Solution (Python):
n = int(input())

def popcount(x):
    return bin(x).count('1')

g = [[-1 for j in range(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())
        x -= 1
        g[i][x] = y

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

print(ans)

Solution (Python):

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
tes = [[-1]*N for i in range(N)]
for i in range(N):
    A = int(readline())
    for j in range(A):
        x,y = map(int,readline().rstrip().split())
        tes[i][x-1] = y

cnt = 0
for i in range(2**N):
    hon = [0]*N
    for j in range(N):
        if (i>>j)&1:
            hon[j] = 1
    flag = True
    for j in range(N):
        if not flag:
            break
        if hon[j]:
            for k in range(N):
                if tes[j][k] == -1:
                    continue
                if tes[j][k] != hon[k]:
                    flag = False
                    break
            
    if flag:
        cnt = max(cnt,hon.count(1))
print(cnt)