#!/usr/bin/env python3
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]

cnt = [0] * N
for i in range(N):
    for j in range(10):
        if F[i][j] == 1:
            cnt[i] += 1

s = [0] * N
for i in range(N):
    for j in range(N):
        s[i] += max([x for x in ((P[j])[1:cnt[j] + 1] if (i == j) else (P[j])[:cnt[j] + 1])])

print(max(s))
