# -*- coding: utf-8 -*-
"""
Created on Sun Nov  4 17:22:42 2018
ABC080
@author: maezawa
"""
import itertools as itr

n = int(input())
f = []
for i in range(n):
    f.append(list(map(int, input().split())))
p = []
for i in range(n):
    p.append(list(map(int, input().split())))
    
#print(f)
#print(p)
profit = -10**8
for oph in itr.product([0,1], repeat=10):
    if oph == (0,0,0,0,0,0,0,0,0,0):
        continue
    c = [0]*n
    for i in range(n):
        c[i] = sum([f[i][j] for j in range(10) if oph[j]==1])
    pcurrent = sum([p[i][c[i]] for i in range(n+1)])
    if pcurrent > profit:
        profit = pcurrent
        #print(oph)

print(profit)