import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from itertools import permutations

def main():
    n = int(input().strip())
    f = [0] * n
    p = [[] for _ in range(n)]
    for i in range(n):
        tmp = list(map(int, input().strip().split()))
        for j in range(10):
            f[i] += tmp[9-j] << j
            # print('f[i]', f[i])
    for i in range(n):
        p[i] = list(map(int, input().strip().split()))
    
    ans = -INF
    b = 0
    for b in range(1, 2**10-1):
        m = 0
        for j in range(n):
            v = fun(f[j], b)
            # print('f: ', v)
            m += p[j][v]
        ans = max(ans, m)
    print(ans)

def fun(f, q):
    ans = 0
    # print(bin(f), bin(q))

    r = f & q
    # print(bin(r))
    for i in range(10):
        ans += (r >> i) & 0x1
    return ans



if __name__ == '__main__':
    main()
