시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB104473139.744%

문제

A space station has docking ports labeled by distinct positive integers $1, 2, 3, \dots$ arranged in a straight line. Port $1$ is the leftmost, and the line extends infinitely to the right. Three labeled ships—Red ($R$), Green ($G$), and Blue ($B$)—are currently at different ports. Due to maintenance, traffic control must re-dock the three ships to newly assigned target ports. To keep clear sight lines and safe spacing during re-docking, the moving ship must pass over exactly one other ship—no more, no less. Specifically, traffic control wants to re-dock while satisfying these constraints:

  1. Each ship must end at its own target port.
  2. At any time, no two ships may occupy the same port.
  3. In one move, choose one ship and place it on an empty port so that exactly one of the other two ships has a port strictly between the old and new ports.

For example, suppose $R$, $G$, and $B$ are currently at ports $3$, $4$, $8$ and their target ports are $3$, $2$, $10$, respectively. In three moves - (1) move $G$ from $4$ to $9$ (passing $B$), (2) move $B$ from $8$ to $10$ (passing $G$), and (3) move $G$ from $9$ to $2$ (passing $R$) - all three ships reach their targets. See the figures below.

Given the current ports and target ports of the three ships, write a program to compute the minimum number of moves required to re-dock them to the target ports.

입력

Your program is to read from standard input. The input starts with a line containing three distinct integers, $r_1$, $g_1$ and $b_1$ ($1 ≤ r_1, g_1, b_1 ≤ 10^6$), which denote the positions of the current ports of $R$, $G$, and $B$, respectively. The following line contains three distinct integers, $r_2$, $g_2$ and $b_2$ ($1 ≤ r_2, g_2, b_2 ≤ 10^6$), which denote the positions of the target ports of $R$, $G$, and $B$, respectively.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the minimum number of moves required to re-dock them to the target ports.

예제 입력 1

3 4 8
3 2 10

예제 출력 1

3

예제 입력 2

3 4 5
6 2 1

예제 출력 2

3