406787: GYM102556 C Riana and Commute

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Riana and Commutetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Riana is late for school! She is currently at block 1 of $$$N$$$ blocks along a straight line from left to right. She wants to go to Ateneo, located at block $$$A$$$. She can run leftwards or rightwards.

Additionally, there are $$$B$$$ bus stops scattered about, and Riana might come across one or more of these bus stops. Each bus stop is located at some block and always has a bus ready to take Riana to some other fixed, predetermined block, and nowhere else. (Passengers aren't allowed to get off the bus at any location other than the predetermined destination block.) All the bus stops are in different blocks. There is only a single destination for all buses that serve the same bus stop, but buses for different bus stops may have different destinations. Being the rich Atenean that she is, Riana always grabs the opportunity to ride these fancy buses (w/ aircon and free WiFi!) at every moment she comes across a bus stop. A destination block may have another bus stop. In this case, after getting off one bus, Riana immediately takes another bus to another destination block. Buses only take passengers towards higher-numbered blocks, so Riana can never take a bus to return to a bus stop that she just came from.

Given this, will Riana be able to get to Ateneo? If so, print YES. Otherwise, print NO.

Input

The first line contains three space-separated integers $$$N$$$, $$$A$$$, and $$$B$$$ — the number of blocks, the block where Ateneo is located, and the number of bus stops, respectively. $$$N$$$ and $$$A$$$ are guaranteed to be between $$$2$$$ and $$$100$$$ (inclusive), with $$$A$$$ $$$\leq$$$ $$$N$$$. $$$B$$$ is guaranteed to be between $$$1$$$ and $$$50$$$ (inclusive).

The next $$$B$$$ lines contain two space-separated integers $$$X$$$ and $$$Y$$$ — the location of a bus stop and its destination, respectively. Both of these values are guaranteed to be between $$$1$$$ and $$$100$$$ (inclusive). It is also guaranteed that $$$X$$$ $$$<$$$ $$$Y$$$.

It is guaranteed that the first numbers in each of the $$$B$$$ lines are distinct from each other.

Output

Single line containing YES or NO.

ExamplesInput
10 5 4
1 3
2 6
4 10
7 9
Output
YES
Input
8 3 2
2 6
4 7
Output
NO
Note

For Example 1, Riana takes a bus to block 3, then runs left towards block 2 and takes a bus to block 6, then she finally runs left to block 5.

加入题单

上一题 下一题 算法标签: