# coding = SJIS

n = int(input())

f = []
p = []
ans = -99999999

def int_to_bin(n):
    a = str(bin(n)[2:])
    for i in range(10 - len(a)):
        a = "0" + a
    return a

def money(joi, open, yen):
    kai = 0
    for i in range(10):
        if joi[i] == str(open[i]) and joi[i] == "1":
            kai += 1
    return yen[kai]

for i in range(n):
    f.append(list(map(int, input().split())))

for i in range(n):
    p.append(list(map(int, input().split())))

for k in range(1023):
    mon = 0
    for l in range(n):
        mon += money(int_to_bin(k + 1), f[l], p[l])
    ans = max(ans, mon)

print(ans)