欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1169A.Circle Metro
Circle Metro
The circle line of the Roflanpolis subway has stations.
There are two parallel routes in the subway. The first one visits stations in order (so the next stop after station is equal to if and otherwise). The second route visits stations in order $n \to (n-1) \to \ldots \to 1 \to n \to (n-1) \to \ldots$ (so the next stop after station is equal to if and otherwise). All trains depart their stations simultaneously, and it takes exactly minute to arrive at the next station.
Two toads live in this city, their names are Daniel and Vlad.
Daniel is currently in a train of the first route at station and will exit the subway when his train reaches station .
Coincidentally, Vlad is currently in a train of the second route at station and he will exit the subway when his train reaches station .
Surprisingly, all numbers are distinct.
Toad Ilya asks you to check if Daniel and Vlad will ever be at the same station at the same time during their journey. In other words, check if there is a moment when their trains stop at the same station. Note that this includes the moments when Daniel or Vlad enter or leave the subway.
Input
The first line contains five space-separated integers , , , , (, , all numbers among , , , are distinct) — the number of stations in Roflanpolis, Daniel's start station, Daniel's finish station, Vlad's start station and Vlad's finish station, respectively.
Output
Output "YES" if there is a time moment when Vlad and Daniel are at the same station, and "NO" otherwise. You can print each letter in any case (upper or lower).
Note
In the first example, Daniel and Vlad start at the stations . One minute later they are at stations . They are at the same station at this moment. Note that Vlad leaves the subway right after that.
Consider the second example, let's look at the stations Vlad and Daniel are at. They are:
- initially ,
- after minute ,
- after minutes ,
- after minutes ,
- after minutes ,
- after minutes ,
- after minutes ,
- after minutes ,
- after minutes ,
- after minutes .
After that, they both leave the subway because they are at their finish stations, so there is no moment when they both are at the same station.
Samples
5 1 4 3 2
YES
10 2 1 9 10
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |