luogu#P8220. [WFOI - 02] I wanna win the race(比赛)
[WFOI - 02] I wanna win the race(比赛)
Background
best is yet to come
Kid accidentally entered online mode. He needs to clear the level faster than his opponent to win.
Problem Description
Kid enters a venue where several players are racing. The venue can be abstracted as a coordinate system.
The players need to run from to . If a player is currently at , then in the next step they can move to or . Note that they can only move in the first quadrant, meaning at all times.
All points are initially type . The organizer chooses a triple and changes all points satisfying and into type . Each time a player passes a type point it takes second, and each time they pass a type point it takes seconds. Please note that the starting point and the ending point are also included in the calculation.
Kid wants to win this race, and he wants to know the minimum number of seconds needed to reach the destination.
Please note that there are important constraints in the Constraints section.
Input Format
There are two lines. The first line contains an integer . The second line contains three integers .
Output Format
Output one integer, representing the minimum number of seconds Kid needs to clear the level.
5
2 4 3
9
Hint
Sample Explanation
The figure below shows one feasible plan. Purple points are type points, and red points are type points:

Constraints
This problem uses bundled tests.
For of the testdata, .
For of the testdata, .
Translated by ChatGPT 5