import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = replicateM 6 readLn >>= print . solve

solve :: [Int] -> Int
solve (n : a : rs) = r + c + 4
    where
        x = min a $ minimum rs
        c 
            | m > 0 = 1
            | otherwise = 0
        (r, m) = n `divMod` x 


readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine