
def profit(xs, n, F, P):
    return sum([P[i][sum(map(lambda x: x[0]*x[1], zip(xs, F[i])))] for i in range(n)])


def vector(k):
    return [1 if k & 1 << i else 0 for i in range(10)]


def foo(n, F, P):
    return max([profit(vector(i), n, F, P) for pat in range(1, 1024)])


if __name__ == "__main__":
    n = int(input())
    F = {}
    P = {}
    for i in range(n):
        F[i] = list(map(int, input().split()))
    for i in range(n):
        P[i] = list(map(int, input().split()))
        
    print(foo(n, F, P))