After facing numerous challenges, Majid succeeded in escaping from the matrix. Upon exiting the matrix, he finds himself in an elevator on the floor of a building with floors. Majid quickly realizes that this elevator is not an ordinary one. The elevator has only two buttons: Up
and Down
. By pressing these buttons, the elevator moves floors up or floors down.
Specifically:
Up
button, if , the elevator goes to floor . Otherwise, the elevator remains stationary.Down
button, if c-d \leq 1, the elevator goes to floor . Otherwise, the elevator remains stationary. The only way to exit the building is the floor. Since exiting the elevator shouldn’t be easy, each time Majid presses either the Up
or Down
button, he has to pay a high cost. Shocked by the conditions, Majid asks you to calculate the minimum cost for him to exit the building.In the only input line, you are given integers , , , , and separated by a space from left to right .
In the only line of output, print the minimum number of times Majid needs to press the elevator buttons to exit the building. If it is impossible to reach from floor to floor using the elevator, print use the stairs
.