eolymp
bolt
Try our new interface for solving problems
Problems

Shot at a target

Shot at a target

Time limit 1 second
Memory limit 128 MiB

Agent Johnny English decided to practice shooting. To do this, he decided to do exactly n shots. His pistol has a magazine with m cartridges, which, of course, is not initially loaded.

Johnny English can fully reload his pistol in a seconds or add one cartridge to the chamber in b seconds. One shot takes exactly one second. Help him to find the minimum amount of time Agent Johnny English can make exactly n shots. Of course, he cannot fire an empty pistol and cannot put a new cartridge into an already full magazine.

Input data

The first line contains four integers n, m, a and b~(1 \le n, m, a, b \le 10^4) — the number of shots to be fired, the size of the pistol magazine, the time it takes to fully reload the magazine and the time to load one cartridge.

Output data

Print one number — the minimum time it will take for the agent to fire exactly n shots.

Examples

During the test, Johnny had to fully load the pistol once, fire twice, then insert one cartridge and fire.

Input example #1
3 2 1 1
Output example #1
5
Source 2018 Цикл Интернет-олимпиад для школьников, первая командная олимпиада сезона, October 14, Problem А