# ABC080C - Shopping Street

import sys

input = sys.stdin.readline



from itertools import product



def main():

    N = int(eval(input()))

    F = tuple(tuple(map(int, input().split())) for _ in range(N))

    P = tuple(tuple(map(int, input().split())) for _ in range(N))

    ans = []

    for b in tuple(product((0, 1), repeat=10))[1:]:

        cnt = 0

        for f, p in zip(F, P):

            opening = sum(b[i] == 1 and b[i] == f[i] for i in range(10))

            cnt += p[opening]

        ans += [cnt]

    print((max(ans)))





if __name__ == "__main__":

    main()
# ABC080C - Shopping Street

import sys

input = sys.stdin.readline



from itertools import product



def main():

    N = int(eval(input()))

    F = tuple(tuple(map(int, input().split())) for _ in range(N))

    P = tuple(tuple(map(int, input().split())) for _ in range(N))

    ans = []

    for b in tuple(product((0, 1), repeat=10))[1:]:

        cnt = 0

        for f, p in zip(F, P):

            opening = sum(i & j for i, j in zip(b, f))

            cnt += p[opening]

        ans += [cnt]

    print((max(ans)))





if __name__ == "__main__":

    main()
# ABC080C - Shopping Street
import sys

input = sys.stdin.readline
from itertools import product


def main():
    N = int(eval(input()))
    F = tuple(tuple(map(int, input().split())) for _ in range(N))
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    ans = []
    for b in tuple(product((0, 1), repeat=10))[1:]:
        cnt = 0
        for f, p in zip(F, P):
            opening = sum(b[i] == 1 and b[i] == f[i] for i in range(10))
            cnt += p[opening]
        ans += [cnt]
    print((max(ans)))


if __name__ == "__main__":
    main()

# ABC080C - Shopping Street
import sys

input = sys.stdin.readline
from itertools import product


def main():
    N = int(eval(input()))
    F = tuple(tuple(map(int, input().split())) for _ in range(N))
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    ans = []
    for b in tuple(product((0, 1), repeat=10))[1:]:
        cnt = 0
        for f, p in zip(F, P):
            opening = sum(i & j for i, j in zip(b, f))
            cnt += p[opening]
        ans += [cnt]
    print((max(ans)))


if __name__ == "__main__":
    main()

-            opening = sum(b[i] == 1 and b[i] == f[i] for i in range(10)) +            opening = sum(i & j for i, j in zip(b, f))