import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Bits (popCount, (.&.))
import Data.Maybe (fromJust, listToMaybe)
import Data.Char (digitToInt)
import Numeric (readInt)

readBin :: Integral a => String -> Maybe a
readBin = fmap fst . listToMaybe . readInt 2 (`elem` "01") digitToInt

main :: IO ()
main = do
    n <- fst . fromJust . B.readInt <$> B.getLine
    fs <- replicateM n $
        fmap fromJust (readBin . B.unpack . foldl1 B.append) . B.words <$> B.getLine
    ps <- replicateM n $ map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    ans <- forM [1..1023 :: Int] $ \b ->
        return $ foldl (\x i -> x + (ps !! i) !! popCount ((fs !! i) .&. b)) 0 [0..n - 1]
    print $ maximum ans
