Codeforces Round #562 (Div. 2) A - Circle Metro

博客围绕 Roflanpolis 地铁环线展开,该环线有两条平行路线,两蟾蜍 Daniel 和 Vlad 分别在不同路线不同站点出发并前往不同终点。通过输入站点数及两蟾蜍的起止站点,模拟行程判断它们是否会在同一时刻处于同一站点,思路是直接模拟行程看是否相遇。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Circle Metro

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The circle line of the Roflanpolis subway has n

stations.

There are two parallel routes in the subway. The first one visits stations in order 1→2→…→n→1→2→…

(so the next stop after station x is equal to (x+1) if x<n and 1 otherwise). The second route visits stations in order n→(n−1)→…→1→n→(n−1)→… (so the next stop after station x is equal to (x−1) if x>1 and n otherwise). All trains depart their stations simultaneously, and it takes exactly 1

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 a

and will exit the subway when his train reaches station x

.

Coincidentally, Vlad is currently in a train of the second route at station b

and he will exit the subway when his train reaches station y

.

Surprisingly, all numbers a,x,b,y

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 n

, a, x, b, y (4≤n≤100, 1≤a,x,b,y≤n, all numbers among a, x, b, y

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).

Examples

Input

Copy

5 1 4 3 2

Output

Copy

YES

Input

Copy

10 2 1 9 10

Output

Copy

NO

Note

In the first example, Daniel and Vlad start at the stations (1,3)

. One minute later they are at stations (2,2)

. 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 (2,9)
  • ,
  • after 1
  • minute (3,8)
  • ,
  • after 2
  • minutes (4,7)
  • ,
  • after 3
  • minutes (5,6)
  • ,
  • after 4
  • minutes (6,5)
  • ,
  • after 5
  • minutes (7,4)
  • ,
  • after 6
  • minutes (8,3)
  • ,
  • after 7
  • minutes (9,2)
  • ,
  • after 8
  • minutes (10,1)
  • ,
  • after 9
  • minutes (1,10)
    • .

    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.

    思路:直接模拟,看他们会不会相遇

  • #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<math.h>
    #include<string.h>
    #define ll long long
    #define mod 1000000007
    using namespace std;
    int main()
    {
        int n,a,x,b,y;
        while(scanf("%d %d %d %d %d",&n,&a,&x,&b,&y)!=EOF)
        {
            int flag=0;
            for(int i=0;;i++)
            {
                int a1,b1;
                a1=a+i;if(a1>n) a1-=n;
                b1=b-i;if(b1<1) b1+=n;
                if(a1==b1)
                {
                    flag=1;
                    //printf("a1=%d i=%d a=%d b=%d",a1,i,a,b);
                    break;
                }
                if(a1==x||b1==y) break;
            }
            if(flag==1) printf("YES\n");
            else printf("NO\n");
        }
    }

     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值