欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1185A.Ropewalkers
Ropewalkers
Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.
The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions , and respectively. At the end of the performance, the distance between each pair of ropewalkers was at least .
Ropewalkers can walk on the rope. In one second, only one ropewalker can change his position. Every ropewalker can change his position exactly by (i. e. shift by to the left or right direction on the rope). Agafon, Boniface and Konrad can not move at the same time (Only one of them can move at each moment). Ropewalkers can be at the same positions at the same time and can "walk past each other".
You should find the minimum duration (in seconds) of the performance. In other words, find the minimum number of seconds needed so that the distance between each pair of ropewalkers can be greater or equal to .
Ropewalkers can walk to negative coordinates, due to the rope is infinite to both sides.
Input
The only line of the input contains four integers , , , (). It is possible that any two (or all three) ropewalkers are in the same position at the beginning of the performance.
Output
Output one integer — the minimum duration (in seconds) of the performance.
Note
In the first example: in the first two seconds Konrad moves for 2 positions to the right (to the position ), while Agafon and Boniface stay at their positions. Thus, the distance between Agafon and Boniface will be , the distance between Boniface and Konrad will be and the distance between Agafon and Konrad will be . Therefore, all three pairwise distances will be at least , so the performance could be finished within 2 seconds.
Samples
5 2 6 3
2
3 1 5 6
8
8 3 3 2
2
2 3 10 4
3
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |