# 写経



n = int(eval(input()))

lst_F = [list(map(int, input().split())) for _ in range(n)]

lst_P = [list(map(int, input().split())) for _ in range(n)]





ans = -float("INF")

for b in range(1, 2**10):

    tmp = 0

    for i in range(n):

        c = 0

        for k in range(10):

            if b&(1<<k) and lst_F[i][k]:

                c += 1

        tmp += lst_P[i][c]

    ans = max(tmp, ans)





print(ans)
N = int(eval(input()))

lst_F = [list(map(int, input().split())) for _ in range(N)]

lst_P = [list(map(int, input().split())) for _ in range(N)]

n_timetable = 10

lst_joisino = [None] * n_timetable





def score(src, F, P):

    cnt = 0

    for i, j in zip(src, F):

        if i == j == 1:

            cnt += 1

    return P[cnt]





def dfs(pos):

    if pos == n_timetable:

        ret = 0

        for i in range(N):

            if lst_joisino == [0] * n_timetable:

                return -float("INF")

            p = score(lst_joisino, lst_F[i], lst_P[i])

            ret += p

        return ret

    lst_joisino[pos] = 0

    ret0 = dfs(pos + 1)

    lst_joisino[pos] = 1

    ret1 = dfs(pos + 1)

    return max(ret0, ret1)





print((dfs(0)))
# 写経
n = int(eval(input()))
lst_F = [list(map(int, input().split())) for _ in range(n)]
lst_P = [list(map(int, input().split())) for _ in range(n)]
ans = -float("INF")
for b in range(1, 2**10):
    tmp = 0
    for i in range(n):
        c = 0
        for k in range(10):
            if b & (1 << k) and lst_F[i][k]:
                c += 1
        tmp += lst_P[i][c]
    ans = max(tmp, ans)
print(ans)

N = int(eval(input()))
lst_F = [list(map(int, input().split())) for _ in range(N)]
lst_P = [list(map(int, input().split())) for _ in range(N)]
n_timetable = 10
lst_joisino = [None] * n_timetable


def score(src, F, P):
    cnt = 0
    for i, j in zip(src, F):
        if i == j == 1:
            cnt += 1
    return P[cnt]


def dfs(pos):
    if pos == n_timetable:
        ret = 0
        for i in range(N):
            if lst_joisino == [0] * n_timetable:
                return -float("INF")
            p = score(lst_joisino, lst_F[i], lst_P[i])
            ret += p
        return ret
    lst_joisino[pos] = 0
    ret0 = dfs(pos + 1)
    lst_joisino[pos] = 1
    ret1 = dfs(pos + 1)
    return max(ret0, ret1)


print((dfs(0)))

-# 写経 -n = int(eval(input())) -lst_F = [list(map(int, input().split())) for _ in range(n)] -lst_P = [list(map(int, input().split())) for _ in range(n)] -ans = -float("INF") -for b in range(1, 2**10): -    tmp = 0 -    for i in range(n): -        c = 0 -        for k in range(10): -            if b & (1 << k) and lst_F[i][k]: -                c += 1 -        tmp += lst_P[i][c] -    ans = max(tmp, ans) -print(ans) +N = int(eval(input())) +lst_F = [list(map(int, input().split())) for _ in range(N)] +lst_P = [list(map(int, input().split())) for _ in range(N)] +n_timetable = 10 +lst_joisino = [None] * n_timetable + + +def score(src, F, P): +    cnt = 0 +    for i, j in zip(src, F): +        if i == j == 1: +            cnt += 1 +    return P[cnt] + + +def dfs(pos): +    if pos == n_timetable: +        ret = 0 +        for i in range(N): +            if lst_joisino == [0] * n_timetable: +                return -float("INF") +            p = score(lst_joisino, lst_F[i], lst_P[i]) +            ret += p +        return ret +    lst_joisino[pos] = 0 +    ret0 = dfs(pos + 1) +    lst_joisino[pos] = 1 +    ret1 = dfs(pos + 1) +    return max(ret0, ret1) + + +print((dfs(0)))