n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
b = [list(map(int,input().split())) for _ in range(n)]
ans = []
for i in range(1,2**10):
    dp = [0]*n
    for j in range(10):
        if i >> j & 1:
            for k in range(n):
                dp[k] += a[k][j]
    ans.append(sum([b[x][y] for x,y in enumerate(dp)]))
print(max(ans))