a = int(input())
ar = []
br = []
count = 0
for i in range(a):
    l = input().split(" ")
    ar.append(l)
for j in range(a):
    m = list(map(int,input().split(" ")))
    br.append(m)
max = 0
for n,r in enumerate(ar):
    for k in range(r.count("1")+1):
        if max < br[n][k]:
            max = br[n][k]
    count += max
    max = 0
print(count)