{-# OPTIONS_GHC -O #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

import Control.Monad
import Data.List
import Data.Bits ((.&.), popCount)
import qualified Data.ByteString.Char8 as B

main = do
    n <- readLn :: IO Int
    --
    ss <- replicateM n $ sum.zipWith (\p b -> b * p) (iterate (*2) 1).unfoldr (B.readInt.B.dropWhile(==' ')) <$> B.getLine
    --
    vs <- replicateM n $ unfoldr (B.readInt.B.dropWhile(==' ')) <$> B.getLine
    --
    print $ maximum $ map (f 0 ss vs) [1..1023]
    --
    where
        f a [] _ _ = a
        f a (s:ss) (v:vs) i = f (a + (v !! (popCount (s .&. i)))) ss vs i