Road to SPC
InterviewTime limit1sMemory limit1024 MB
Given home, venue, and one blocked point, find the fewest turns in an axis-parallel walk from home to the venue.
- Level
Easy3 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
SPC (Sogang Programming Contest) is a programming festival that any student of Sogang University can join. Seungho leaves home today to go to the SPC venue.
The SPC venue and Seungho's home are on a two-dimensional coordinate plane. Seungho's home is at , and the SPC venue is at . A fierce Geunsu is at , so Seungho cannot pass through that point. The positions of Seungho's home, the SPC venue, and Geunsu are all different.
Seungho can only walk straight in a direction parallel to the -axis or the -axis. A turn happens when the new direction differs from the previous one. When Seungho leaves home, he can choose any direction to start, and choosing the starting direction is not counted as a turn. Seungho gets dizzy easily, so he wants to reach the SPC venue from home with as few turns as possible. Find the minimum number of turns Seungho needs.
Input
The first line contains two integers and , the position of Seungho's home.
The second line contains two integers and , the position of the SPC venue.
The third line contains two integers and , the position of Geunsu.
Output
Print the minimum number of turns Seungho needs.
Hint
Seungho does not have to take the shortest path to reach the SPC venue.