N = int(input())
# F[y][x]: y行目、x文字目
F = [list(map(int, input().split())) for _ in range(N)]
# P[y][x]: y行目、x文字目
P = [list(map(int, input().split())) for _ in range(N)]

max_num = -10000001
sum = 0

for i in range(1024):
    if i == 0:
        continue
    b = bin(i)
    for n in range(N):
        f = F[n]
        s = ""
        for _n in range(10):
            s += str(f[_n])
        s = "0b" + s
        and_num = int(b, 0) & int(s, 0)
        match_nums = list(format(and_num, 'b'))
        match_num = 0
        for _n in match_nums:
            if int(_n) == 1:
                match_num += 1
        sum += P[n][match_num]
    if sum > max_num:
        max_num = sum
    sum = 0
print(max_num)
