ELEVTRBL  Elevator Trouble
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 elvator, you learn that it has only two buttons, marked "UP u" and "DOWN d". You conclude that the UPbutton takes the elevator u floors up (if there aren't enough floors, pressing the UPbotton does nothing, or at least so you assume), whereas the DOWNbutton 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 input f, s, g, u and d (floors, start, goal, up, down), find the shortest sequence of button presses you must press in order to get from s to g, given a building of floors, or output "use the stairs" if you cannot get from s to g by the given elevator.
Input
The input will consist of one line, namely f s g u d, where 1 <= s, g <= f <= 1000000 and 0 <= u, d <= 1000000. The floors are oneindexed, i.e. if there are 10 stories, s and g be in [1; 10].
Output
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 conguration of the elevator.
Example
Input: 10 1 10 2 1 Output: 6
Input: 100 2 1 1 0 Output: use the stairs
hide comments
tanny_123:
20170128 13:38:09
could someone check my solution ID = 18657999 

vanvinhbk94:
20161114 10:27:12
why runtime error (SIGSEGV) if use C++4.3.2 ... AC if use C++ 5.1 or C++ 14 ???


hung:
20161005 04:37:40
Note s == g


prakash:
20160923 17:24:11
some problems occur in size of array but finally solved it


flyingduchman_:
20160814 14:21:58
In BFS , you should set "visited" array size to a big value like bool visited[10000000] to handle corner cases. 

kunal todi:
20160805 10:48:05
Can anyone let me know why after running 12 test cases successfully, the judge gives me wrong answer 

Sachin Bisht :
20160423 09:29:21
I am trying to implement this problem in JAVA but getting TLE.


try2catch:
20160221 10:20:53
finally understood ! meaning of BFS. 

chin:
20150628 22:31:02
Finally AC..:D 

Aditya Joshi:
20141129 06:04:35
HINT:

Added by:  Krzysztof Lewko 
Date:  20111006 
Time limit:  1s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 
Resource:  Nordic programming contest 