Start

2015-12-02 20:15 CET

Onlinekvalet 2016

End

2015-12-06 22:15 CET
The end is near!
Contest is over.
Not yet started.
Contest is starting in -3276 days 16:42:59

Time elapsed

98:00:00

Time remaining

0:00:00

Problem E
Solnedgång

You are visiting a very warm country, and it happens to be a sizzling hot day. Luckily, you managed to find the shadow of a house to take cover in. You realize that you probably should head back to the hotel sometime soon, but you also realize that it’s too hot to walk in the sun. The city you are in consists of $N$ houses, placed in a grid, where every house occupies exactly one unit square.

Currently, each house has a shadow that is exactly one unit square long, and is located directly north of the house. Since the sun just started to set, this shadow will extend one more unit square north per time unit. You can walk from the shadow of one house to another one, if the shadows share an edge of length at least one (see figure). You cannot walk through houses.

The question is how long it will take before there exists a path to the hotel that does not involve getting burned by the sun. The hotel is house number $N$, and you are currently in the shadow of house number 1. Since the hotel entrence is at the north side of the house, that’s where you need to go. In the worst case you might have to wait until nightfall, which will occur in $K$ units of time.

\includegraphics[width=0.6\textwidth ]{skuggor.png}

The first line contains two space-separated integers $N$ and $K$ - the number of houses in the city and the number of time units before nightfall.

The next $N$ lines contains 2 integers $x y$ each, the coordinates of the houses. The first line contains the coordinates of the house which you take cover behind, and the last line contains the coordinate of the hotel.

It is guaranteed that every house has a shadow, i.e. no house is placed immediately south of another house.

Output

You should output a single integer, the time it takes before there exist a path to the hotell which goes entirely through the shadows, or "NATT" in case this time exceeds or equals $K$.

Scoring

Your solution will be tested on a number of test case groups. To get points for a group you have to solve all the test cases in that group.

For all groups it holds that $1 \le N, 0 \le K$.

Group

Points

Limits

1

19

$N, K \le 100, 0 \le x, y \le 100$

2

26

$N, K \le 1000, 0 \le x, y \le 1000$

3

17

$N, K \le 1000, 0 \le x, y \le 100000$

4

23

$N \le 20000, K \le 10^7, 0 \le x, y \le 10^7$

5

15

$N \le 300000, K \le 10^{18}, 0 \le x, y \le 10^{18}$

Sample Input 1 Sample Output 1
4 10
0 1
1 2
2 0
3 2
2
Sample Input 2 Sample Output 2
8 10
1 0
2 1
3 1
4 1
2 4
3 4
1 5
0 4
3
Sample Input 3 Sample Output 3
2 100
1 0
3 0
NATT