Given a cycle of N people and two pointer distances, decide the minimum number of pointings before the two pointers collide, or report that they never meet.
Medium7MathNumber theoryGraphShortest pathNo attempts yetTime limit1sMemory limit512 MBEunha likes drinks, games, and drinking games. Her favorite drinking game is the "red ginseng game". N people sit around a table in a circle and play it by these rules.
After the contest the contestants went to a nearby bar for an after party, and Eunha led them into a red ginseng game. So many people had gathered that nobody could see who was pointing at whom, and the game stopped again and again. Eunha's friend Eunseo could not watch this any longer and proposed the "orderly red ginseng game", which changes the rules like this.
Thanks to Eunseo's proposal the contestants could enjoy the game in an orderly way. Eunha then kept the game running for hours, so the exhausted contestants decided to finish the game as quickly as possible no matter whom Eunha points at and no matter how she sets the two pointing distances. Rescue them from red ginseng hell.
For convenience, assume the participants are numbered 1 to N counterclockwise. That is, participant i−1 sits immediately to the left of participant i, and participant i+1 sits immediately to the right. As the exception, participant N sits immediately to the left of participant 1, and participant 1 sits immediately to the right of participant N.
The first line contains the number of participants of the orderly red ginseng game N (2≤N≤500000), the number A of the person Eunha pointed at first and the number B of the person she pointed at second (1≤A,B≤N, A=B), and the integers DA and DB that give the pointing distance of each pointer (1≤DA,DB≤N−1), separated by spaces and given in that order.
On the first line, print the smallest number of pointings needed to finish the given game as quickly as possible. If the game cannot be finished, print Evil Galazy. The two people Eunha points at in rule 1 do not count toward the number of pointings.
When N=6, A=5, B=1, DA=1 and DB=2, the following order finishes the game in three pointings.