Problem A
Horse in Ambush
When Farmer Oskar doesn’t watch his cows closely enough,
they tend to wander off into the forest to hunt for horse
spies. To catch an enemy agent horse, the cows lure it into a
cow trail and set up fences at the endpoints of the trail,
which are
One particular horse (positioned
Horse chasing happens in
-
The cows choose to move either
or meters, in any direction. -
The horse jumps either
, , or meters in any direction. However, if a cow occupies the same position as the horse, she can only jump a single meter since she now must jump over the cow. -
If there is a cow in the same position as the horse, the cows capture her.
How long will it take for the horse to be captured, assuming both she and the cows move optimally?
Input
The first and only line of input contains four integers
The numbers
Output
A single integer, the number of minutes before the cows can catch the horse no matter how the horse moves.
Sample Input 1 | Sample Output 1 |
---|---|
5 4 3 2 |
3 |
Sample Input 2 | Sample Output 2 |
---|---|
5 4 2 3 |
3 |