eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Elevator Trouble

Elevator Trouble

Лимит времени 1 секунда
Лимит использования памяти 64 MiB

You are on your way to your first job interview as a program tester, and you are already late. The interview is in a skyscraper and you are currently in floor s, where you see an elevator. Upon entering the elevator, you learn that it has only two buttons, marked "UP u" and "DOWN d". You conclude that the UP-button takes the elevator u floors up (if there aren't enough floors, pressing the UP-button does nothing, or at least so you assume), whereas the DOWN-button takes you d stories down (or none if there aren't enough). Knowing that the interview is at floor g, and that there are only f floors in the building, you quickly decide to write a program that gives you the amount of button pushes you need to perform. If you simply cannot reach the correct floor, your program halts with the message "use the stairs".

Given f, s, g, u and d (floors, start, goal, up, down), and the shortest sequence of button presses you must press in order to get from s to g, given a building of f floors, or output "use the stairs" if you cannot get from s to g by the given elevator.

Входные данные

Consist of one line, namely f s g u d, where 1s, gf10^6 and 0u, d10^6. The floors are one-indexed, i.e. if there are 10 stories, s and g be in [1, 10].

Выходные данные

You must reply with the minimum numbers of pushes you must make in order to get from s to g, or output use the stairs if it is impossible given the configuration of the elevator.

Пример

Входные данные #1
10 1 10 2 1
Выходные данные #1
6
Входные данные #2
100 2 1 1 0
Выходные данные #2
use the stairs
Источник 2011 Nordic Collegiate Programming Contest, 1 Октября, Задача D