import qualified Data.ByteString.Char8 as B
import qualified Data.Map as M
import Data.Maybe
import Data.List

mapKeyValue f g = M.fromDistinctAscList . map (\(k,v) -> (f k, g v)) . M.toList

main = do
  [x,y,z] <- map read . words <$> getLine
  abcs <- map (map (fst . fromJust . B.readInt) . B.words) . B.lines <$> B.getContents
  print (coins (x,y,z) abcs)

coins xyz = snd . M.findMin . foldr dp (M.singleton xyz 0)

dp [a,b,c] m = M.unionsWith max [mx,my,mz]
  where
    mx = mapKeyValue decx (+a) $ M.filterWithKey (\(x,_,_) _ -> x>0) m
    my = mapKeyValue decy (+b) $ M.filterWithKey (\(_,y,_) _ -> y>0) m
    mz = mapKeyValue decz (+c) $ M.filterWithKey (\(_,_,z) _ -> z>0) m

decx (x,y,z) = (x-1,y,z)
decy (x,y,z) = (x,y-1,z)
decz (x,y,z) = (x,y,z-1)