CF1422D Returning Home

Description

Yura has been walking for some time already and is planning to return home. He needs to get home as fast as possible. To do this, Yura can use the instant-movement locations around the city. Let's represent the city as an area of $ n \times n $ square blocks. Yura needs to move from the block with coordinates $ (s_x,s_y) $ to the block with coordinates $ (f_x,f_y) $ . In one minute Yura can move to any neighboring by side block; in other words, he can move in four directions. Also, there are $ m $ instant-movement locations in the city. Their coordinates are known to you and Yura. Yura can move to an instant-movement location in no time if he is located in a block with the same coordinate $ x $ or with the same coordinate $ y $ as the location. Help Yura to find the smallest time needed to get home.

Input Format

N/A

Output Format

N/A

Explanation/Hint

In the first example Yura needs to reach $ (5, 5) $ from $ (1, 1) $ . He can do that in $ 5 $ minutes by first using the second instant-movement location (because its $ y $ coordinate is equal to Yura's $ y $ coordinate), and then walking $ (4, 1) \to (4, 2) \to (4, 3) \to (5, 3) \to (5, 4) \to (5, 5) $ .