欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF990A.Commentary Boxes
Commentary Boxes
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built commentary boxes. regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.
If is not divisible by , it is impossible to distribute the boxes to the delegations at the moment.
Organizers can build a new commentary box paying burles and demolish a commentary box paying burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.
What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by )?
Input
The only line contains four integer numbers , , and (, ), where is the initial number of the commentary boxes, is the number of delegations to come, is the fee to build a box and is the fee to demolish a box.
Output
Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by ). It is allowed that the final number of the boxes is equal to .
Note
In the first example organizers can build boxes to make the total of paying burles for the each of them.
In the second example organizers can demolish boxes to make the total of paying burles for the each of them.
In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get boxes.
Samples
9 7 3 8
15
2 7 3 7
14
30 6 17 19
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |