A Baker's Dozen

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

When ordering a quantity of pastries, a baker's dozen is considered to be 13. At TSS Bakery, you are charged the cost of a dozen pastries when you purchase a baker's dozen, effectively giving you 1 for free. In addition to a separate cost for a dozen, there is another cost for individual pastries below a dozen. Given the costs as well as the number of pastries purchased, determine the final amount of the bill.

Input Specification

The first line of input is an integer b (1 \le b \le 10^5) representing the cost of a baker's dozen pastries.
The second line of input is an integer d (1 \le d \le 10^5) representing the cost of 12 (or a dozen) pastries.
The third line of input is an integer i (1 \le i \le 10^5) representing the cost of a single pastry.
The last line is an integer n (1 \le n \le 10^5) representing the number of pastries purchased.

When calculating the total amount, the cost for a baker's dozen is charged first until the amount of pastries unpaid is less than 13. If the amount remaining is 12, the cost for a dozen is charged. If the amount remaining is less than 12, the remaining cost is the individual cost multiplied by the number of pastries remaining.

Output Specification

Output a single integer, the cost of n pastries.

Sample Input

10
9
3
41

Sample Output

36

Comments

There are no comments at the moment.