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 C# (judge verdict: Accepted)

using System;

class Program{
  static void Main(){
    string[] s = Console.ReadLine().Split(' ');
    int[] a = new int[3];
    int ans = 0;
    for(int i = 0;i<a.Length;i++){
      a[i] = int.Parse(s[i]);
    }
    if(a[0]/2>=a[1]){                       // 1Lの水の500mLあたりの値段が
      while(a[2]>0){                        // 500mLの水の値段より大きければ
        a[2] -= 500;                        // 500mLの水のみを買う。
        ans += a[1];
      }
    }else{
      while(a[2]>0){
        if(a[2]>=1000){                     // 必要な水の量が1L以上あるときは
          ans += a[0];                      // 1Lの水を買う。
          a[2] -= 1000;
        }else if(a[2]<1000 && a[2]>500){    // 500mL < 必要な水の量 < 1000の時は、
          ans += a[0];                      // 1Lの水を買う。
          a[2] -= 1000;
        }else{                              // 必要な水の量が500mL以下で
          if(a[0]>a[1]){                    // 1Lの水の値段 > 500mLの水の値段の時、
            ans += a[1];                    // 500mLの水を買う。
            a[2] -= 500;
          }else{                            // 1Lの水のほうが安ければ、
            ans += a[0];                    // 1Lの水を買う。
            a[2] -= 1000;
          }
        }
      }
    }
    Console.WriteLine("{0}",ans);
  }
}