import itertools
import numpy as np
from collections import Counter
N = int(input())
F = np.array([list(map(int, input().split())) for _ in range(N)])
P = [list(map(int, input().split())) for _ in range(N)]
benefit = -10^(8)

for i in itertools.product((0, 1), repeat=10):
    if sum(i) != 0:
        C = np.array(list(i)) + F
        pre_benefit = 0
        for j in range(N):
            count = len(np.where(C[j]==2)[0])
            pre_benefit += P[j][count]
        if benefit < pre_benefit:
            benefit = pre_benefit
print(benefit)
