# -*- coding: utf-8 -*-

n = int(input())
F = [list(map(int, input().split())) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
ans = -1e9

for sister in range(1, 1024):
    count = 0
    for i in range(n):
        cost_list = list('{:b}'.format(int(''.join(map(str, F[i])), 2) & sister))
        cost = 0
        for j in range(len(cost_list)):
            cost += int(cost_list[j])
        count += P[i][cost]
    ans = max(ans, count)

print(ans)
