import Control.Applicative ((<$>)) import Control.Monad import Data.List main :: IO () main = do p1 <- read <$> getLine p2 <- read <$> getLine n <- read <$> getLine solve p1 p2 <$> replicateM n (read <$> getLine) >>= print solve :: Int -> Int -> [Int] -> Int solve p1 p2 rs = (p1 + p2) * f rs where f = sum . map (\x -> length x - 1) . group . sort