import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as B
import Data.Bits
import Data.Char

type Open = V.Vector (V.Vector Int)
type Prof = V.Vector (V.Vector Int)
type BitV = V.Vector Int
type OP = (V.Vector Int, V.Vector Int)

toBitV :: Int -> Int -> BitV
toBitV n l
    | l == 0 = V.empty
    | otherwise = V.snoc (toBitV (shiftR n 1) (l - 1)) (n .&. 1)

solve :: Open -> Prof -> BitV -> Int
solve open prof bitv = loop
    where
        zss :: V.Vector OP
        zss = V.zip open prof
        loop :: Int
        loop = V.foldl' step 0 zss
        step :: Int -> OP -> Int
        step acc (op, pf) = acc + (pf V.! l)
            where
                l = V.length $ V.filter (==1) $ V.zipWith (*) op bitv

main = do
    n <- readLn :: IO Int
    fss <- V.replicateM n $ do
        xs <- V.unfoldrN 10 (B.readInt . B.dropWhile isSpace) <$> B.getLine
        return xs
    pss <- V.replicateM n $ do
        xs <- V.unfoldrN 11 (B.readInt . B.dropWhile isSpace) <$> B.getLine
        return xs
    print $ maximum $  [solve fss pss (toBitV i 10) | i <- [1..2^10-1]]