import Control.Monad
import Control.Applicative
import Data.List
import Data.Array
strToInts  :: IO [Int]
strToInts  = map read . words <$> getLine

main = do
    n <- readLn :: IO Int
    fs <- replicateM n strToInts
    ps <- replicateM n strToInts
    let cd = [0,1]
    let css = [[c0,c1,c2,c3,c4,c5,c6,c7,c8,c9]|c0 <- cd , c1 <- cd , c2 <- cd , c1 <- cd , c3 <- cd , c1 <- cd , c4 <- cd , c5 <- cd , c6 <- cd , c7 <- cd , c8 <- cd , c9 <- cd ,[c0,c1,c2,c3,c4,c5,c6,c7,c8,c9] /= [0,0,0,0,0,0,0,0,0,0] ]
    let ans = [profit fs ps cs n | cs <- css]
    print (maximum ans)
    
profit fs ps cs n  = sum [profita fs ps cs i | i <- [1..n]]
profita fs ps cs i = (ps !! (i-1)) !! n
                     where n = count (fs !! (i-1)) cs 0


count :: [Int] -> [Int] -> Int -> Int
count [] bn n = n
count (a:an) (b:bn) n = if (a==1) && (b==1)
                        then 1 + (count an bn n)
                        else (count an bn n)