import Control.Monad (replicateM) import Data.Int (Int64) import qualified Data.Map.Strict as M type Count = Int type Counter a = M.Map a Count addElement :: Ord a => a -> Counter a -> Counter a addElement x = M.insertWith (+) x 1 buildCounter :: Ord a => [a] -> Counter a buildCounter = foldr addElement M.empty computeTotalCost :: Integral a => a -> a -> [a] -> a computeTotalCost p1 p2 rs = sum $ calcCost <$> M.elems ctr where ctr = buildCounter rs calcCost v = if v > 1 then fromIntegral (v - 1) * (p1 + p2) else 0 main :: IO () main = do p1 <- readLn :: IO Int64 p2 <- readLn :: IO Int64 n <- readLn :: IO Int rs <- replicateM n readLn :: IO [Int64] print $ computeTotalCost p1 p2 rs