import Control.Monad

solve n f' p = maximum $ map calc $ replicateM 10 [False,True] where
  calc op
    | or op = sum $ zipWith (cal op) f p
    | otherwise = -(10^10)
  cal op f = (!! length (filter id (zipWith (&&) op f)))
  f = map (map (== 1)) f'

main = do
  n <- readLn
  f <- replicateM n readWords
  p <- replicateM n readWords
  print $ solve n f p

readWords = map read . words <$> getLine