Problem: 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?

Submission attempts (in order):
#

#
import sys
from io import StringIO
import unittest
import copy


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 5
0 1 0 1 0
1 0 0 0 1"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 6
1 0 0 0 1 0
1 1 1 0 1 0
1 0 1 1 0 1"""
        output = """15"""
        self.assertIO(input, output)


def resolve():
    R, C = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(R)]
    A_rev = [[1 - v for v in a] for a in A]

    ans = 0
    for bit in range(1 << R):
        num = 0
        T = copy.deepcopy(A)
        for i, t in enumerate(T):
            if 1 << i & bit:
                T[i] = A_rev[i]

        T = list(zip(*T))
        for t in T:
            num += max(t.count(0), t.count(1))
        ans = max(ans, num)

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


#
# abc147 c
#
import sys
from io import StringIO
import unittest
from collections import deque


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
1
2 1
1
1 1
1
2 0"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """2
1
2 0
1
1 0"""
        output = """1"""
        self.assertIO(input, output)


def resolve_bit():
    N = int(input())
    C = []
    for i in range(N):
        a = int(input())
        C.append([list(map(int, input().split())) for j in range(a)])

    ans = 0
    for bit in range(1 << N):
        f = True
        for i in range(N):
            if bit & (1 << i):
                for c in C[i]:
                    if bit & (1 << c[0]-1) != (1 << c[0]-1)*c[1]:
                        f = False
                        break
        if f == True:
            ans = max(ans, bin(bit).count("1"))
    print(ans)


def resolve():
    global N, C
    N = int(input())
    C = []
    for i in range(N):
        a = int(input())
        C.append([list(map(int, input().split())) for j in range(a)])

    V = deque()
    print(dfs(0, V))


def dfs(n, V):
    if n == N:
        count = 0
        for v in V:
            if count == -1:
                break
            for c in C[v-1]:
                if (c[0] in V and c[1] == 0) or (c[0] not in V and c[1] == 1):
                    count = -1
                    break
            else:
                count += 1
        if count == -1:
            return 0
        else:
            return count

    ans = 0
    V.append(n+1)
    ans = max(ans, dfs(n+1, V))
    V.pop()
    ans = max(ans, dfs(n+1, V))

    return ans


if __name__ == "__main__":
    # unittest.main()
    resolve()


Verdicts: Runtime Error

Accepted