import           Control.Monad
import qualified Data.Array.IO         as IO
import qualified Data.Array.Unboxed    as A
import           Data.Bits
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

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

main = do
  n <- getInt

  f <- replicateM n getIntList

  p' <- IO.newArray ((1,0),(n,10)) (0::Int) :: IO (IO.IOUArray (Int, Int) Int)
  forM_ [1..n] $ \i -> do
    ps <- getIntList
    forM_ [0..10] $ \j -> IO.writeArray p' (i, j) $ ps !! j
  p <- IO.freeze p' ::  IO (A.UArray (Int, Int) Int)

  let b2a   :: Int -> [Int]
      b2a b = fmap (\i -> 1 .&. (b `shiftR` i)) [0..9]

      calc b = let a = b2a b
                   c i = sum $ zipWith (.&.) (f !! (i-1)) a
               in
                 sum $ fmap (\i -> p A.! (i, c i)) [1..n]

      solve b m | b == 0 = m
                | otherwise =
                  let m' = max m (calc b)
                  in
                    solve (b-1) m'

  print $ solve 1023 (-1000000001)