SP8129 SKY - Sky Lift
Description
We can represent a grid of skyscrapers by an NxN matrix of their positive heights. A skyscraper is made out of square blocks, and you may travel through them using a special elevator that can move as any other, but also sideways (four possible directions on a fixed floor). They may move anywhere as long as they don't exit the skyscrapers. In other words, if the elevator is inside a skyscraper, it may move to the neighboring skyscraper only if its height is greater or equal to the current level the elevator is at.
Moving sideways (in one of the 4 directions, that is, N, E, S, W...) is done for free when using this elevator, but moving one floor up or down costs exactly one unit.
Given the positions of two skyscrapers, find the cost of moving from the **top block** of the first to the **top block** of the second using the described elevator.
Input Format
The first line of input contains a single integer N ( 1
Output Format
To the first and only line of input output the solution.