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:
import itertools
n=int(input())
M=[[] for _ in range(n)]
for i in range(n):
  m=int(input())
  for j in range(m):
    x,y=map(int,input().split())
    M[i].append([x-1,y])
    
def isT(x,y):
  f=0
  if y==0:
    f=-1
  else:
    f=1
  if T[x]!=0 and T[x]!=f:
    return False
  else:
    T[x]=f
  return True
    
def isF(x,y):
  f=0
  if y==0:
    f=1
  else:
    f=-1
  if T[x]!=0 and T[x]!=f:
    return False
  else:
    T[x]=f
  return True

ans=0
for num in range(1,n+1):
  for h in itertools.combinations(range(n),num):
    nh=set([i for i in range(n) if i not in h])
    h=set(h)
    T=[0]*n
    check=True
    for i in h:
      for j in M[i]:
        f=isT(j[0],j[1])
        check= check and f
    for i in nh:
      for j in M[i]:
        f=isF(j[0],j[1])
        check= check and f
    if check==True:
      ans=max(ans,T.count(1))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = []
for i in range(n):
  a = int(input())
  li_2 = [list(map(int, input().split())) for _ in range(a)]
  li.append(li_2)
def judge(bit): 
  b =1
  """正直者と嘘つきの決め方を一つ固定"""
  for i in range(n):
    if bit & (1<<i) == False:
      continue
    else:
      for xy in li[i]:
        x = xy[0]
        y = xy[1]
        if y == 1 and bit & (1<<x)==False:
          b = 0
        if y == 0 and bit & (1<<x):
          b = 0
      if b == 1:
        return True
      else:
        return False
res = 0
for bit in range(n):
  if judge(bit):
    count = 0
    for i in range(n):
      if bit & (1<<i):
        count += 1
    res = max(res,count)
print(res)

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
T,L=[[] for _ in range(n)],[[] for _ in range(n)]
for i in range(n):
  m=int(input())
  for j in range(m):
    x,y=map(int,input().split())
    if y==1:
      T[i].append(x-1)
    else:
      L[i].append(x-1)
ans=0

for num in range(1,n+1):
  for honest in itertools.combinations(range(n),num):
    honest=list(honest)
    nothonest=[i for i in range(n) if i not in honest]
    t1=list(itertools.chain.from_iterable([T[i] for i in honest]))
    l1=list(itertools.chain.from_iterable([L[i] for i in honest]))
    t2=list(itertools.chain.from_iterable([L[i] for i in nothonest]))
    l2=list(itertools.chain.from_iterable([T[i] for i in nothonest]))
    t=set(t1)&set(t2)
    l=set(l1)&set(l2)
    h=all(i in t for i in honest) and all(i not in l for i in honest)
    if h==True:
      ans=max(ans,num)

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy
from itertools import combinations

def main():
  n = int(input())
  remarks = numpy.full((n, n), 0)
  As = []
  for i in range(n):
    As.append(int(input()))
    for _ in range(As[-1]):
      x, y = map(int, input().strip().split())
      remarks[i, x-1] = 1 if y==1 else -1
  ids = list(range(n))
  for nn in ids[::-1]:
    for ihonests in combinations(ids, nn):
      honests = remarks.take(ihonests, axis=0)
      if all(map(lambda honest: all(honest <= 0) or all(honest >= 0), honests)):
        print(nn)
        return

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy
from itertools import combinations

def main():
  n = int(input())
  remarks = numpy.full((n, n), 0)
  As = []
  for i in range(n):
    As.append(int(input()))
    for _ in range(As[-1]):
      x, y = map(int, input().strip().split())
      remarks[i, x-1] = 1 if y==1 else -1
  ids = list(range(n))
  for nn in ids[::-1]:
    for ihonests in combinations(ids, nn):
      honests = remarks.take(ihonests, axis=0)
      if numpy.sum(honests <= 0) == numpy.multiply.reduce(honests.shape) \
          or numpy.sum(honests >= 0) == numpy.multiply.reduce(honests.shape):
        print(nn)
        return

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())

T=[[] for _ in range(n)]
L=[[] for _ in range(n)]

for i in range(n):
  m=int(input())
  for j in range(m):
    x,y=map(int,input().split())
    if y==1:
      T[i].append(x-1)
    else:
      L[i].append(x-1)

ans=0

for num in range(1,n+1):
  for honestman in itertools.combinations(range(n),num):
    honestman=list(honestman)
    t=list(itertools.chain.from_iterable([T[i] for i in honestman]))
    l=list(itertools.chain.from_iterable([L[i] for i in honestman]))
    if len(set(t)&set(l))==0:
      ans=max(ans,num)
      
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
g = [[-1 for j in range(n)] for i in range(n)]

for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        g[i][x - 1] = y
        
ans = 0
for s in range(2**n):
    ok = True
    for i in range(n):
        k = 0
        if (s >> i & 1) == 1:
            k += 1
            for j in range(n):
                if g[i][j] == -1:
                    continue
                if (s >> j & 1) != g[i][j]:
                    ok = False
    if ok:
        ans = max(ans, k)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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


def is_honest(people, number):
    return (bool)(people & (1 << number))


ans = 0
for assumption in range(2 ** n):
    contradicted = False
    for i in range(n):
        for x, y in testimonies[i]:
            if not is_honest(assumption, i):
                y ^= 1
            if is_honest(assumption, x) ^ y:
                contradicted = True
    if not contradicted:
        ans = max(ans, bin(assumption).count('1'))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
count = 0
ans = 0
L = [[] for i in range(n)]
OK = [['1','1','1'],['1','0','0'],['0','1','0'],['0','0','1']]
NG = [['1','1','0'],['1','0','1'],['0','1','1'],['0','0','0']]
while count < n:
  t = int(input())
  for i in range(t):
    a,b = map(int,input().split())
    L[count].append([a,b])
  count += 1
def Base_10_to_two(X,two):
  if (int(X/two)):
      return Base_10_to_two(int(X/two), n)+str(X%two)
  return str(X%two)
for i in range(2**n):
  b = Base_10_to_two(i,2).zfill(n)
  flag = True
  for j in range(n):
    for k in range(len(L[j])):
      if [b[j],str(L[j][k][1]),b[L[j][k][0]-1]] in NG:
        flag = False
        break
  cur = 0
  if flag:
    for j in range(n):
      if b[j] == '1':
        cur += 1
    ans = max(ans,cur)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    G = [[-1 for _ in range(N)] for _ in range(N)]
    for i in range(N):
        a = Scanner.int()
        for _ in range(a):
            x, y = Scanner.map_int()
            x -= 1
            G[i][x] = y
    print(G)
    ans = 0
    for i in range(1 << N):
        V = [0 for _ in range(N)]
        for j in range(N):
            if (i >> j) & 1:
                V[j] = 1
        isOk = True
        for j in range(N):
            for k in range(N):
                if V[k] == 0:
                    continue
                if G[k][j] == -1:
                    continue
                if G[k][j] != V[j]:
                    isOk = False
        if isOk:
            ans = max(ans, V.count(1))
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def sub():
    m = int(input())
    flag = False
    if m == 0:
        return flag
    for _ in range(m):
        i,j = map(int,input().split(' '))
        if j == 0:
            flag = True
    return flag

def main():
    n = int(input())
    count = 0
    for _ in range(n):
        if not sub():
            count += 1
    print(count)

main()

Submission status: Wrong Answer

Solution code:

def sub():
    m = int(input())
    flag = False
    if m == 0:
        return flag
    for _ in range(m):
        i,j = map(int,input().split(' '))
        if j == 0:
            flag = True
    return flag

def main():
    n = int(input())
    count = 0
    for _ in range(n):
        if sub():
            count += 1
    print(n - count)

main()

Submission status: Wrong Answer

Solution code:

def sub():
    m = int(input())
    flag = False
    if m == 0:
        return True
    for _ in range(m):
        i,j = map(int,input().split(' '))
        if j == 0:
            flag = True
    return flag

def main():
    n = int(input())
    count = 0
    for _ in range(n):
        if sub():
            count += 1
    print(n - count)

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
num = []
for i in range(N):
    a = int(input())
    for j in range(a):
        b = [int(i) for i in input().split()]
        num.append(b)
#ここまで入力
ans = [[0 for i in range(2)] for i in range(N)]
for i in num:
    if i[1]==1:
        ans[i[0]-1][1] += 1
    else:
        ans[i[0]-1][0] += 1
ans1 = 0
count = 0
for i in ans:
    if i[0]>0 and i[1]>0:
        ans1 += min(i)
        
    elif i[1]==0:
        count += 1
if count ==N:
    ans1 = N-1
print(N-ans1)

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())

L = list(product([0,1], repeat=N))#2^N通りの全仮説

T = [[]for i in range(N)]#証言
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        T[i].append((x, y))

#print(L,T)

ans= 0

for l in L:
  F  = True
  for i,k in enumerate(l):
    if k == 1:
      for j in T[i]:
        if j[0]-1 != k:
          F = False  
  if F:
    ans = max(ans,sum(l))
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())

L = list(product([0,1], repeat=N))

T = [[]for i in range(N)]#証言
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        T[i].append((x, y))

#print(L,T)

ans= 0

for l in L:
  F  = True
  for i,k in enumerate(l):
    for j in T[i]:
      if j[0]-1 != k:
        F = False  
  if F:
    ans = max(ans,sum(l))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    x=int(input())
    xx=[[int(i) for i in input().split()]for i in range(x)]
    a.append(xx)
#print(a)

maxi=0
for i in range(2**n):
    status=[True]*n
    check=[None]*n
    flag=True
    for j in range(n):
        if (i>>j)&1:
            status[j]=False
    
    for ind,aa in enumerate(a):
        if status[ind]==True:
            for b in aa:
                if b[1]==1 and status[b[0]-1]==True and (check[b[0]-1]==None or check[b[0]-1]==True):
                    check[b[0]-1]=True
                elif b[1]==0 and (check[b[0]-1]==True or status[b[0]-1]==True):
                    flag=False
    if flag==True:
        cnt=check.count(True)
        #print(status,check,cnt)
        maxi=max(maxi,cnt)
print(maxi)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

a = []
for i in range(N):
	A = INT()
	a.append([LIST() for _ in range(A)])

maxv = 0
for i in range(2**N):
	s = "{:0" + str(N) + "b}"
	F = [int(i) for i in s.format(i)]
	flag = 0
	for j in range(N):
		if F[j] == 1:
			for k in range(len(a[j])):
				if a[j][k][1] == 1:
				 	if F[a[j][k][0] - 1]*a[j][k][1] == 0:
				 		flag = 1
					 	break
				else:
					if F[a[j][k][0] - 1]*a[j][k][1] == 0:
						flag = 1
						break

	if flag == 1:
		continue

	wa = sum(F)
	if maxv < wa:
		maxv = wa

print(maxv)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [[-1 for i in range(N)] for i in range(N)]
for i in range(N):
    m = int(input())
    for i in range(m):
        x,y = map(int,input().split())
        A[i][x-1] = y
ans = 0
for i in range(1<<N):
    honets = [0 for i in range(N)]
    for j in range(N):
        if (i>>j) & 1:
            honets[j] = 1
    ok = True
    for j in range(N):
        if honets[j] == 1:
            for k in range(N):
                if A[j][k] == -1: continue
                if A[j][k] != honets[k]: ok = False
    if ok:
        ans = max(ans, honets.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import numpy as np
input = sys.stdin.readline

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

ans = 0
for i in itertools.product((True,False), repeat=N):
	ch = True
	i = np.array(i)
	for ee in e[i]:
		print(ee)
		for j in range(N):
			if(ee[j]!=-1):
				if(ee[j] != i[j]):
					ch = False
					continue
	if(ch):
		ans = np.count_nonzero(i == True)
		break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [[-1for _ in range(n)]for _ in range(n)]

ans = 0

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

for i in range(2**n):
  #bit全探索
  #d:正直者と仮定してる人
  d = []
  p = len(bin(i))
  q = bin(i)
  for j in range(p-2):
    q = bin(i>>j)
    if int(q[len(q)-1]) == 1:
      d.append(j)
  print(d)

  res = True
  for j in d:
    for k in range(n):
      #jさんがkさんの事を正直者だと思ってた時
      if a[j][k] == 1:
        if k not in d:
          res = False
      #jさんがkさんのことを不親切な人と思ってた時
      elif a[j][k] == 0:
        if k in d:
          res = False
  if res:
    ans = max(ans,len(d))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [[-1for _ in range(n)]for _ in range(n)]

ans = 0

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

for i in range(2**n):
  #bit全探索
  #d:正直者と仮定してる人
  d = []
  p = len(bin(i))
  q = bin(i)
  for j in range(p-2):
    q = bin(i>>j)
    if int(q[len(q)-1]) == 1:
      d.append(j)
  
  res = True
  for j in d:
    for k in range(n):
      #jさんがkさんの事を正直者だと思ってた時
      if a[j][k] == 1:
        if k not in d:
          res = False
      #jさんがkさんのことを不親切な人と思ってた時
      elif a[j][k] == 0:
        if k in d:
          res = False
    if res:
      ans = max(ans,len(d))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())

# user_dic = {user_id:{user_id: user_condition}}
user_dic = {}
for i in range(1, n+1):
    words_num = int(input())
    words_dic = {}
    for t in range(words_num):
        word = list(map(int, input().split()))
        words_dic[word[0]] = word[1]
    user_dic[i] = words_dic

max_num = 0

# 全てのパターンについて探索
for i in range(2 ** n):
    # 矛盾があるならFalseにする
    flag = True

    # パターンを2進数化
    bin_num = str(bin(i))[2:].zfill(n)

    # ユーザーごとの証言を考える
    for member, words in user_dic.items():
        # 正しい人か否か判断

        # 正しいなら
        if int(bin_num[-1 * member]) == 1:
            # 証言1つずつに対して考える
            for idx, cond in words.items():
                if  int(bin_num[-1 * idx]) != cond:
                    flag = False 

        # 正しくないなら
        else:
            # 証言1つずつに対して考える
            for idx, cond in words.items():
                if  int(bin_num[-1 * idx]) == cond:
                    flag = False 
    
    # 矛盾がない場合
    if flag:
        # 正直者をカウントし, 結果を比較し更新
        true_num = bin(i).count("1")
        if max_num < true_num:
            max_num = true_num

print(max_num)

sys.exit()

Submission status: Wrong Answer

Solution code:
import collections as c
ip = lambda : map(int, input().split())
mod = 10**9+7
# ##############
N = int(input())
l = []
for i in range(N):
    a = int(input())
    l1 = []
    for j in range(a):
        l1.append(list(ip()))
    l.append(l1)
ans=0
for i in range(2**N):
    # print(i)
    tmp = [0]*N
    t = 0
    for j in range(N):
        # print(j)
        if i>>j & 1:
            tmp[j]=1
            t+=1
            for k in l[j]:
                x,y = k
                if x-1 < j and tmp[x-1]!=y:
                    break
                elif y==1:
                    tmp[x-1]=1
            else:
                continue
            break
        elif tmp[j] ==1:
            break
    else:
        # print('t',t)
        if t > ans:
            # print('aaaa')
            ans = t
    continue
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = []
for i in range(n):
    a = int(input())
    xy.append([])
    for j in range(a):
        xy[-1].append([int(i) for i in input().split()])
for p in sorted([[i >> j & 1 for j in range(n)] for i in range(2**n)], key=lambda _x: -sum(_x)):
    flag = True
    for xi, ti in enumerate(xy):
        for x, y in ti:
            flag &= not p[xi] ^ p[x - 1] == y
    if flag:
        print(sum(p))
        break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def logic_check(hon, hon_, man):
    for i in b[man]:
        if i[0]-1 in hon:
            if i[1] == 0:
                return 0
        elif i[0]-1 in hon_:
            if i[1] == 1:
                return 0
        else:
            if i[1] == 0:
                hon_.append(i[0]-1)
            else:
                hon.append(i[0]-1)
    return 1

n = int(input())
a = []
b = []
for i in range(n):
    a.append(int(input()))
    b.append([[int(i) for i in input().split(" ")] for j in range(a[-1])])
max_hone = 0
for i in range(n):
    hon = [i]
    hon_ = []
    flag = 0
    ind = 0
    while True:
        if len(hon) <= ind:
            break
        if logic_check(hon, hon_, hon[ind]) == 0:
            flag = 1
            break
        else:
            ind += 1
    if flag == 0:
        max_hone = max(max_hone, len(hon))
print(max_hone)

Submission status: Wrong Answer

Solution code:
def main():
	N=int(input())
	shougen = [0b0]*N
	for i in range(N):
		J = int(input())
		bit=(1<<i)
		for j in range(J):
			x, y = map(int, input().split())
			bit = bit | (y<<x-1)
		shougen[i] = bit
	
	anslis = [0]*2**N
	for bit in range(1,2**N):
		bbb = [shougen[i] for i in range(N) if (bit & (1<<i))]
		ans = 2**N-1
		for i in bbb:
			ans = ans & i
		if bit == ans:
			anslis[bit] = ans
	for i,v in enumerate(anslis):
		anslis[i] = bin(v)[2:].count('1')
	print(max(anslis))


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
List = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
  num_evidence = int(input())
  for j in range(num_evidence):
    darega, doushita = map(int,input().split())
    List[i][darega - 1] = doushita * 2 - 1
  
# print(List)

def is_inconsistent(all_evidence, honest_or_unkind):
  for i in range(n):
    if honest_or_unkind[i] == 1:
      for j in range(n):
        if honest_or_unkind[j] * all_evidence[i][j] == -1:
          return True
  return False

max_honest = 0
for i in range(n**2 - 1):
  temp = format(i, '0'+str(n)+'b')
  honest_or_unkind = [int(temp[i]) * 2 - 1 for i in range(n)]
  # print(honest_or_unkind)
  # print(is_inconsistent(List, honest_or_unkind))
  if not is_inconsistent(List, honest_or_unkind):
    max_honest = max(max_honest, honest_or_unkind.count(1))

print(max_honest)

Submission status: Wrong Answer

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




def main():
    # Failed to predict input format
    N = int(input())
    x = [ [] for i in range(N+1)]
    for i in range(N):
        a = int(input())
        for j in range(a):
            x[i].append(list(map(int, input().split())))

    # print(x)
    ans = 0
    for i in range(1<<N):
        y = [[] for k in range(N+1)]
        for j in range(N):
            if (i>>j) &1:
                for k in range(len(x[j])):
                    a, b = x[j][k]
                    # print(a-1, b)
                    y[a].append(b)

        if all([j == [] or j.count(1) == len(j) or j.count(0) == len(j) for j in y[1:]]):
            # print('{:05b}'.format(i), y)
            # if all([(i>>idx)&1 for idx, k in enumerate(y[1:], 1) if k.count(1) == len(k)]):
            #     ans = max(ans, bin(i).count('1'))
            #     print(bin(i), y, 'ok')
            # f = True
            # for idx, k in enumerate(y[1:], 1):
            #     if k.count(0) == len(k):
            #         if not (i>>(idx-1))&0:
            #             f = False
                        

            #     elif k.count(1) == len(k):
            #         if not (i>>(idx-1))&1:
            #             f = False
            #         else:
            #             print('t')
            # if f:
            #     ans = max(ans, '{:05b}'.format(i).count('1'))
            f = True
            for idx, k in enumerate(y[1:], 1):
                if k != [] and k[0] == 0 and not i>>(idx-1):
                    # print('{:05b}'.format(i), y, 'ok')
                    continue
                elif k != [] and k[0] == 1 and i>>(idx-1)&1:
                    # print('{:05b}'.format(i), y, 'ok')
                    continue
                elif k == []:
                    continue
                else:
                    f = False
            if f:
                # print('{:05b}'.format(i), y, 'ok')
                ans = max(ans, '{:05b}'.format(i).count('1'))
                





    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

def is_ok(state):
    true_numbers = [i for i in range(n) if state & (1 << i)]

    for number in true_numbers:
        for av in al[number]:
            if state & (1 << (av[0] - 1)) != av[1]:
                return 0
    return sum(true_numbers)

print(max(is_ok(state) for state in range(2**n)))

# for state in range(2**n):
#     # print(f"%0{n}d" % int(bin(state)[2:]))
#     print(is_ok(state))
#
# # pass
# # state = int('010', 2)
# # print(is_ok(state))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

def is_ok(state):
    true_numbers = [i for i in range(n) if state & (1 << i)]

    for number in true_numbers:
        for av in al[number]:
            if state & (1 << (av[0] - 1)) != av[1]:
                return 0
    return sum(true_numbers)

print(sum(is_ok(state) for state in range(2**n)))

# for state in range(2**n):
#     # print(f"%0{n}d" % int(bin(state)[2:]))
#     print(is_ok(state))
#
# # pass
# # state = int('010', 2)
# # print(is_ok(state))

Submission status: Wrong Answer

Solution code:
N = int(input())
 
testimony = [[] for _ in range(N)]
 
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])
 
honest = 0
for i in range(1, 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
                    print(flag)
                    break
    if flag == 0: 
        honest = max(honest, bin(i)[2:].count('1')) 
print(honest)

Submission status: Wrong Answer

Solution code:
N = int(input())
 
testimony = [[] for _ in range(N)]
 
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])

honest = 0
for i in range(0, 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
                    print(flag)
                    break
    if flag == 0: 
        honest = max(honest, bin(i)[0:].count('1')) 
print(honest)

Submission status: Wrong Answer

Solution code:
A=int(input())
B=int(input())
C=[1,2,3]

for i in range(3):
  if C[i]!=A and C[i]!=B:
    print(C[i])

Submission status: Wrong Answer

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

N = int(input())
tf = [[] for _ in range(N)]
pl = []
for i in range(N):
    p = int(input())
    pl.append(p)
    for j in range(p):
        tf[i].append(list(map(int, input().split())))

import itertools
for flags in itertools.product([1, 0], repeat=N):
    f = True
    for i in range(N):
        for j in range(pl[i]):
            if flags[i] == 1:
                if flags[tf[i][j][0] - 1] != tf[i][j][1]:
                    f = False
            else:
                if flags[tf[i][j][0] - 1] == tf[i][j][1]:
                    f = False
        if not f:
            break
    if f:
        print(sum(flags))
        exit()
print(0)

Submission status: Wrong Answer

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

N = int(input())
tf = [[] for _ in range(N)]
pl = []
for i in range(N):
    p = int(input())
    pl.append(p)
    for j in range(p):
        tf[i].append(list(map(int, input().split())))

import itertools
for flags in itertools.product([1, 0], repeat=N):
    f = False
    for i in range(N):
        for j in range(pl[i]):
            if flags[i] == 1:
                if tf[i][j][1] != flags[tf[i][j][0] - 1]:
                    f = True
            else:
                if flags[tf[i][j][0] - 1] == tf[i][j][1]:
                    f = True
        if f:
            break
    if not f:
        print(sum(flags))
        exit()
print(0)

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)
        check = [0 for _ in range(N)]
        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:
                        check[i] = 1
                else:
                    if now[x-1] != y:
                        pass
                    else:
                        check[1] = 1
            
        if sum(check)==0:
            ans = max(ans,sum(now))
            
    print(ans)


if __name__ == '__main__':
    main()