from itertools import product
from operator import mul
def main():
    n = int(input())
    f = [tuple(map(int, input().split())) for _ in range(n)]
    p = [tuple(map(int, input().split())) for _ in range(n)]

    patterns = tuple(product([0,1], repeat=10))
    results = []
    for pate in patterns:
        if sum(pate) == 0:
            continue
        res = []
        flag = 0
        for i1, fe in enumerate(f):
            s = sum(tuple(map(mul, pate, fe)))
            if s != 0:
                flag = 1
                res.append(p[i1][s])
            if flag:
                results.append(sum(res))
    print(max(results))
if __name__ == '__main__':
    main()

