# ABC080C - Shopping Street

import sys

input = sys.stdin.readline



def main():

    N = int(eval(input()))

    F = tuple(int(input().replace(" ", ""), 2) for _ in range(N))

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

    ans = []

    for i in range(1, 2 ** 10):

        cnt = sum(p[bin(i & f).count("1")] for f, p in zip(F, P))

        ans += [cnt]

    print((max(ans)))





if __name__ == "__main__":

    main()
# ABC080C - Shopping Street

# exhaustive search

import sys

input = sys.stdin.readline



def main():

    N = int(eval(input()))

    F = tuple(int(input().replace(" ", ""), 2) for _ in range(N))  # str -> bit -> int

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

    # set of sum of profit in each pattern (2^10)

    ans = {

        sum(p[bin(i & f).count("1")] for f, p in zip(F, P)) for i in range(1, 2 ** 10)

    }

    print((max(ans)))





if __name__ == "__main__":

    main()
# ABC080C - Shopping Street
import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    F = tuple(int(input().replace(" ", ""), 2) for _ in range(N))
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    ans = []
    for i in range(1, 2**10):
        cnt = sum(p[bin(i & f).count("1")] for f, p in zip(F, P))
        ans += [cnt]
    print((max(ans)))


if __name__ == "__main__":
    main()

# ABC080C - Shopping Street
# exhaustive search
import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    F = tuple(int(input().replace(" ", ""), 2) for _ in range(N))  # str -> bit -> int
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    # set of sum of profit in each pattern (2^10)
    ans = {
        sum(p[bin(i & f).count("1")] for f, p in zip(F, P)) for i in range(1, 2**10)
    }
    print((max(ans)))


if __name__ == "__main__":
    main()

+# exhaustive search -    F = tuple(int(input().replace(" ", ""), 2) for _ in range(N)) +    F = tuple(int(input().replace(" ", ""), 2) for _ in range(N))  # str -> bit -> int -    ans = [] -    for i in range(1, 2**10): -        cnt = sum(p[bin(i & f).count("1")] for f, p in zip(F, P)) -        ans += [cnt] +    # set of sum of profit in each pattern (2^10) +    ans = { +        sum(p[bin(i & f).count("1")] for f, p in zip(F, P)) for i in range(1, 2**10) +    }