| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 80 | 38 | 23 | 40.351% |
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:
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.
3 4 8 3 2 10
3
3 4 5 6 2 1
3