#!/usr/bin/python

import re
import sys

def overlap(source, target):
    n = 0
    for s, t in zip(source, target):
        if s == 1 and s == t:
            n += 1
    return n

def main(argv):
    line = sys.stdin.readline()
    while line:
        n = int(line.rstrip("\n"))
        f = []
        for i in xrange(n):
            f.append(map(lambda x: int(x), 
              sys.stdin.readline().rstrip("\n").split(" ")))
        p = []
        for i in xrange(n):
            p.append(map(lambda x: int(x), 
              sys.stdin.readline().rstrip("\n").split(" ")))

        max_profit = -10**7 - 1
        for index in xrange(1, 2**10):
            profit = 0
            b = map(lambda x: int(x), bin(index)[2:].zfill(10))
            for i in xrange(n):
                c = overlap(b, f[i])
                profit += p[i][c]

            if profit > max_profit:
                max_profit = profit

        print max_profit
            
        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)