import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
-- end of templete

bitCount :: Int -> Int
bitCount n = c4 .&. 0x0000ffff + (shiftR c4 16) .&. 0x0000ffff
  where
    c1 = n .&. 0x55555555 + (shiftR n 1) .&. 0x55555555
    c2 = c1 .&. 0x33333333 + (shiftR c1 2) .&. 0x33333333
    c3 = c2 .&. 0x0f0f0f0f + (shiftR c2 4) .&. 0x0f0f0f0f
    c4 = c3 .&. 0x00ff00ff + (shiftR c3 8) .&. 0x00ff00ff

b2i s = b2i' 0 s
  where
    b2i' r [] = r
    b2i' r ('0':ss) = b2i' (2*r) ss
    b2i' r ('1':ss) = b2i' (2*r+1) ss

main = do
    n <- getInt
    fs <- map (b2i . filter (/=' ')) <$> replicateM n getLine
    ps <- replicateM n getInts
    print $ maximum $ flip map [1..1023] $ (\i -> sum $ zipWith (\p c -> p!!c) ps $ map (bitCount . (.&.i)) fs)