module Main where

import Control.Applicative
import Control.Monad
import Data.List

f :: [[Int]] -> [[Int]] -> [Int] -> Int
f fss pss as = sum $ zipWith3 g fss pss (repeat as)
  where
    g fs ps xs = ps !! (sum $ zipWith (*) fs xs)

main :: IO ()
main = do
    n <- readLn
    fss <- replicateM n $ fmap read . words <$> getLine :: IO [[Int]]
    pss <- replicateM n $ fmap read . words <$> getLine :: IO [[Int]]
    let ass = tail $ sequence $ replicate 10 [0, 1]
    let ans = maximum $ fmap (f fss pss) ass
    print ans