PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000285. Các tầng của tòa nhà (Skyscraper Floors)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Các tầng của tòa nhà (Skyscraper Floors)

Skyscraper Floors

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

A building has FF floors numbered from 00 through F−1F-1. You must move a piece of furniture from floor AA to floor BB, using only elevators, never the staircase.

There are EE elevators. Elevator ii first stops at floor YiY_i and then at all floors Yi+tXiY_i+tX_i, for nonnegative integers tt, as long as the floor is less than FF. Each elevator can travel in either direction between any two of its stops. You may transfer between elevators at any floor served by both.

Determine whether the furniture can reach floor BB from floor AA. If the floors coincide, no elevator ride is needed.

Input

  • The first line contains four integers F,E,A,BF,E,A,B: number of floors, number of elevators, start floor and destination floor.
  • The next EE lines each contain two integers Xi,YiX_i,Y_i: stop interval and starting floor of elevator ii.

Output

Print exactly one of the two lines:

  • It is possible to move the furniture. if the transfer is possible.
  • The furniture cannot be moved. otherwise.

Subtasks

  • Subtask 1 (20 points): 1≤F≤2001\le F\le 200; 1≤E≤81\le E\le 8; 0≤A,B<F0\le A,B<F; 1≤Xi≤5⋅1071\le X_i\le 5\cdot10^7; 0≤Yi≤5⋅1070\le Y_i\le 5\cdot10^7.
  • Subtask 2 (30 points): 1≤F≤1061\le F\le 10^6; 1≤E≤401\le E\le 40; 0≤A,B<F0\le A,B<F; 1≤Xi≤5⋅1071\le X_i\le 5\cdot10^7; 0≤Yi≤5⋅1070\le Y_i\le 5\cdot10^7.
  • Subtask 3 (50 points): 1≤F<5⋅1071\le F<5\cdot10^7; 1≤E<1001\le E<100; 0≤A,B<F0\le A,B<F; 1≤Xi≤5⋅1071\le X_i\le 5\cdot10^7; 0≤Yi≤5⋅1070\le Y_i\le 5\cdot10^7.

Examples

Input

22 4 0 6
3 2
4 7
13 6
10 0

Output

It is possible to move the furniture.

Explanation

One possible transfer sequence is 0 → 20 using the elevator stopping at multiples of 10, then 20 → 11 on the elevator starting at 2 with step 3, then 11 → 19 on the elevator starting at 7 with step 4, and finally 19 → 6 on the elevator starting at 6 with step 13. All transfer floors belong to both adjacent elevators.

Input

1000 2 500 777
2 0
2 1

Output

The furniture cannot be moved.

Explanation

The first elevator serves only even floors while the second serves only odd floors. Floor 500 belongs only to the first elevator and 777 belongs only to the second; they have no common stopping floor, hence transfer is impossible.