import numpy as np
from itertools import product

n = int(input())
f = [np.array(list(map(int, input().split())), dtype=bool) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

# print(n, f, p)

allcase = np.array(list(product([0, 1], repeat=10)), dtype=bool)

# print(allcase, allcase.shape)

ans = -(10 ** 7) - 100

for a in allcase:
    if sum(a) == 0:
        # print(a)
        continue
    profit = 0
    for shop in range(n):
        # idx = np.count_nonzero(np.logical_and(f[shop], a))
        idx = np.count_nonzero(np.logical_and(f[shop], a))

        profit += p[shop][idx]
    ans = max(ans, profit)

print(ans)
