atcoder#ARC104C. [ARC104C] Fair Elevator

[ARC104C] Fair Elevator

Score : 600600 points

Problem Statement

There is a building with 2N2N floors, numbered 1,2,,2N1, 2, \ldots, 2N from bottom to top.

The elevator in this building moved from Floor 11 to Floor 2N2N just once.

On the way, NN persons got on and off the elevator. Each person ii (1iN)(1 \leq i \leq N) got on at Floor AiA_i and off at Floor BiB_i. Here, 1Ai<Bi2N1 \leq A_i < B_i \leq 2N, and just one person got on or off at each floor.

Additionally, because of their difficult personalities, the following condition was satisfied:

  • Let Ci(=BiAi1)C_i (= B_i - A_i - 1) be the number of times, while Person ii were on the elevator, other persons got on or off. Then, the following holds:- If there was a moment when both Person ii and Person jj were on the elevator, Ci=CjC_i = C_j.
  • If there was a moment when both Person ii and Person jj were on the elevator, Ci=CjC_i = C_j.

We recorded the sequences AA and BB, but unfortunately, we have lost some of the records. If the record of AiA_i or BiB_i is lost, it will be given to you as 1-1.

Additionally, the remaining records may be incorrect.

Determine whether there is a pair of AA and BB that is consistent with the remaining records.

Constraints

  • 1N1001 \leq N \leq 100
  • Ai=1A_i = -1 or 1Ai2N1 \leq A_i \leq 2N.
  • Bi=1B_i = -1 or 1Bi2N1 \leq B_i \leq 2N.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 B1B_1

A2A_2 B2B_2

::

ANA_N BNB_N

Output

If there is a pair of AA and BB that is consistent with the remaining records, print Yes; otherwise, print No.

3
1 -1
-1 4
-1 6
Yes

For example, if B1=3,A2=2B_1 = 3, A_2 = 2, and A3=5A_3 = 5, all the requirements are met.

In this case, there is a moment when both Person 11 and Person 22 were on the elevator, which is fine since C1=C2=1C_1 = C_2 = 1.

2
1 4
2 3
No

There is a moment when both Person 11 and Person 22 were on the elevator. Since C1=2,C2=0C_1 = 2, C_2 = 0, some of the information is incorrect.

2
4 1
2 4
No

The records are seemingly intact but clearly are incorrect.