#K59607. Minimum Cake Purchasing Cost

    ID: 30902 Type: Default 1000ms 256MiB

Minimum Cake Purchasing Cost

Minimum Cake Purchasing Cost

You are given three integers \(M\), \(C\), and \(D\) representing the number of cakes to buy, the discount per cake, and the original price of a cake, respectively.

There are two discount plans:

  • Plan 1: Every third cake is free. In other words, you only pay for \(2\) out of every \(3\) cakes. The total cost under this plan is given by: \[ \text{cost}_1 = \left(\left\lfloor \frac{M}{3} \right\rfloor \times 2 + (M \bmod 3)\right) \times D \]</p>
  • Plan 2: You get a discount of \(C\) yen on each cake, so the cost per cake is \(D - C\). The total cost under this plan is: \[ \text{cost}_2 = M \times (D - C) \]</p> </ul>

    Your task is to compute the minimum cost among the two plans.

    inputFormat

    The input consists of a single line containing three space-separated integers \(M\), \(C\), and \(D\).

    \(M\) is the number of cakes, \(C\) is the discount per cake, and \(D\) is the original price of a cake.

    outputFormat

    Output a single integer — the minimum total cost to purchase \(M\) cakes using the best discount plan.

    ## sample
    9 5 20
    120