Problem:
Heat Stroke

　
We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower.

Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required.

Input

The input is given in the following format.

$A$ $B$ $X$

The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters.

Output

Output the total price.

Sample Input 1

180 100 2400

Sample Output 1

460

Sample Input 2

200 90 2018

Sample Output 2

450

Solution in Kotlin (judge verdict: Accepted)

/**
 * Created by karayuu on 2019/06/17
 */
fun main(args: Array<String>) {
  var (A, B, x) = readLine()!!.split(" ").map { it.toInt() }
  if (x % 500 != 0) {
    //500の倍数に切り上げる
    x += (500 - x % 500)
  }

  /**
   * 1000mLが500mLより安かったら,1000mLを多く使う方が良い
   * 500mL * 2が1000mLより安かったら,500mLを多く使う方が良い
   * それ以外は1000mLを限界まで使って,500mLを残りで払えば良い
   */
  //1000mLを買う個数
  var a = 0
  //500mLを買う個数
  var b = 0

  if (A < B) {
    //1000mLを限界まで買う
    a = x / 1000
    //余ってたらもう一本買う
    if (x % 1000 > 0) {
      a++
    }
  } else if (A > B * 2) {
    b = x / 500
    //xは500の倍数にしているので,これが余ることはない
  } else {
    //1000mLで限界まで買って,500mLを残り買う
    a = x / 1000
    x %= 1000
    b = x / 500
  }

  //出力
  println(A * a + B * b)
}