N = input()
F = []
P = []
for _ in xrange(N):
    F.append(map(int, raw_input().split()))
for _ in xrange(N):
    P.append(map(int, raw_input().split()))

calendar = [[]]
for _ in xrange(10):
    newCalendar = []
    for y in calendar:
        newCalendar.append(y + [0])
        newCalendar.append(y + [1])
    calendar = newCalendar
calendar.pop(0)

profits = []
for timeTable in calendar:
    currentProfit = 0
    for shopProfit, shopCalendar in zip(P, F):
        currentProfit += shopProfit[len([1 for (i, j) in zip(timeTable, shopCalendar) if i and j])]
    profits.append(currentProfit)
print max(profits)