atcoder#PANASONIC2020F. Fractal Shortest Path
Fractal Shortest Path
Score : points
Problem Statement
For a non-negative integer , we define a fractal of level as follows:
- A fractal of level is a grid with just one white square.
- When , a fractal of level is a grid. If we divide this grid into nine subgrids:- The central subgrid consists of only black squares.
- Each of the other eight subgrids is a fractal of level .
- The central subgrid consists of only black squares.
- Each of the other eight subgrids is a fractal of level .
For example, a fractal of level is as follows:
In a fractal of level , let denote the square at the -th row from the top and the -th column from the left.
You are given quadruples of integers . For each quadruple, find the distance from to .
Here the distance from to is the minimum integer that satisfies the following condition:
- There exists a sequence of white squares satisfying the following conditions:-
- For every , and share a side.
- For every , and share a side.
Constraints
- and are white squares.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the distance from to .
2
4 2 7 4
9 9 1 9
5
8