import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Array

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    fs <- replicateM n getIntList
    ps <- array ((1,0),(n,10)) . zip [(i,j) | i <- [1..n], j <- [0..10]] . concat <$> replicateM n getIntList
    let result = maximum [calc fs ps open|open <- replicateM 10 [0,1], any (== 1) open]
    print result

calc fs ps open = sum . map (ps !) . zip [1..] $ map (sum . zipWith (*) open) fs