100 atcoder#ABC184C. [ABC184C] Super Ryuma

[ABC184C] Super Ryuma

Score : 300300 points

Problem Statement

There is an infinite two-dimensional grid, and we have a piece called Super Ryuma at square (r1,c1)(r_1, c_1). (Ryu means dragon and Ma means horse.) In one move, the piece can go to one of the squares shown below:

More formally, when Super Ryuma is at square (a,b)(a, b), it can go to square (c,d)(c, d) such that at least one of the following holds:

  • a+b=c+da + b = c + d
  • ab=cda - b = c - d
  • ac+bd3|a - c| + |b - d| \le 3

Find the minimum number of moves needed for the piece to reach (r2,c2)(r_2, c_2) from (r1,c1)(r_1, c_1).

Constraints

  • All values in input are integers.
  • 1r1,c1,r2,c21091 \le r_1, c_1, r_2, c_2 \le 10^9

Input

Input is given from Standard Input in the following format:

r1r_1 c1c_1

r2r_2 c2c_2

Output

Print the minimum number of moves needed for Super Ryuma to reach (r2,c2)(r_2, c_2) from (r1,c1)(r_1, c_1).

1 1
5 6
2

We need two moves - for example, (1,1)(5,5)(5,6)(1, 1) \rightarrow (5, 5) \rightarrow (5, 6).

1 1
1 200001
2

We need two moves - for example, $(1, 1) \rightarrow (100001, 100001) \rightarrow (1, 200001)$.

2 3
998244353 998244853
3

We need three moves - for example, $(2, 3) \rightarrow (3, 3) \rightarrow (-247, 253) \rightarrow (998244353, 998244853)$.

1 1
1 1
0