Velociraptors 301

When you go out from the toilet to go back to class you discover that a group of velociraptors has entered to the classroms and has devoured your classmates. The corridor where you are is closed: running away is impossible. Velociraptors, inside the classroms digesting, will go out at any moment to finish with you. Oh, well! It is known that this kind of things happen sometimes.

The corridor of your high school is represented by a segment of the real line from 00 to 2n22n-2, with nn doors of nn classroms, placed over the points 0,2,4,,2n20, 2, 4, \ldots, 2n-2 of the line. The toilet where you are going out from is placed at the point kk with 0k2n20\leq k \leq 2n-2 and even kk. You as well as the velociraptors take 1 second to cover a distance unit over the line (velociraptors are already satisfied and they are not going to run for a miserable desert).

You are asked to, assuming that you know which velociraptors will go out from the classroms to devour you and the moments of time tit_i that they will do it, and also assuming that these ones will head for you (wherever you are) as soon as they go out, say how many seconds you can extend your (brief but intense) life time making the right movements.

image

We consider that will be very useful to think in space-time diagrams as the one on the right, where it is illustrated a possible situaton for k=6k=6 and n=11n=11, where 3 velociraptors go out from the classroms placed in the points 2, 4 and 14 at the moments 6, 10 and 8 respectively. The correct answer to this case is 1313.

Input

A test data contains various cases. Each case starts with three naturals nn, mm and kk, with 0k2n20\leq k\leq 2n-2, 1n1081\leq n\leq 10^8 and 1m100001\leq m \leq 10000, where nn and kk are as it is describe in the wording and mm is the number of velociraptors. The next mm lines of the input contain a pair of numbers cic_i, tit_i, where cic_i is the classroom that has devoured the ii-th velociraptor and tit_i is the moment of time that it will go out for its desert. It is fulfilled that 0ai2n20\leq a_i\leq 2n-2 and 0ti1090\leq t_i\leq 10^9 for any ii, that cic_i and tit_i are even, and that all the cic_i are different.

Output

For each case, your program must print in a line the time that you can extend your life. As times tit_i and classrooms are even numbers it is fulfilled that the answer will always be an integer.

Scoring

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:16:28.387Z

© Jutge.org, 2006–2026.
https://jutge.org