{"trustable":false,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n #problem-body \u003e pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e \u003cem\u003e\u0026quot;Pandu and shruthi\u0026nbsp;are stuck in an elevator at a shopping complex.\u0026quot;\u003c/em\u003e\u003c/p\u003e \n\u003cp\u003e \u003cem\u003eBrammy,\u0026nbsp;the software engineer\u003c/em\u003e\u0026nbsp;is worried about shruthi. He wants to get her out ASAP. Currently the elevator is in floor \u003cstrong\u003e\u0027S\u0027\u003c/strong\u003e. Brammy somehow gets the duplicate controls of the elevator and quickly learns that it has only two buttons, marked UP and DOWN. He understands that the UP-button takes the elevator \u003cstrong\u003e\u0027U\u0027\u0026nbsp;\u003c/strong\u003efloors up (if there aren\u0027t enough floors, pressing the UP-button does nothing), whereas the DOWN-button takes the elevator\u0026nbsp;\u003cstrong\u003e\u0027D\u0027\u003c/strong\u003e floors down (or none if there aren\u0027t enough). Knowing that the safe exit floor is floor \u003cstrong\u003e\u0027G\u0027\u003c/strong\u003e, and that there are only \u003cstrong\u003e\u0027F\u0027 \u003c/strong\u003efloors in the building, brammy has to quickly write a program that gives him the minimum amount of button pushes he needs to perform. If he simply cannot reach the correct floor, the program halts with the message \u003cstrong\u003e\u0026quot;use the stairs\u0026quot;\u003c/strong\u003e.\u003c/p\u003e \n\u003cp\u003e Given input \u003cstrong\u003eF\u003c/strong\u003e, \u003cstrong\u003eS\u003c/strong\u003e, \u003cstrong\u003eG\u003c/strong\u003e, \u003cstrong\u003eU\u003c/strong\u003e and \u003cstrong\u003eD\u003c/strong\u003e (floors, start, goal, up, down), help brammy find the shortest sequence\u0026nbsp;of button presses he must press in order to get the elevator from \u003cstrong\u003eS\u003c/strong\u003e to \u003cstrong\u003eG\u0026nbsp;\u003c/strong\u003eor output \u0026quot;use the stairs\u0026quot; if he cannot get shruthi out.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003e The input will consist of one line, namely\u0026nbsp;\u003cstrong\u003eF\u003c/strong\u003e,\u0026nbsp;\u003cstrong\u003eS\u003c/strong\u003e,\u0026nbsp;\u003cstrong\u003eG\u003c/strong\u003e,\u0026nbsp;\u003cstrong\u003eU\u003c/strong\u003e\u0026nbsp;and\u0026nbsp;\u003cstrong\u003eD,\u003c/strong\u003e\u0026nbsp;where 1 \u0026lt;\u003d \u003cstrong\u003eS\u003c/strong\u003e; \u003cstrong\u003eG\u003c/strong\u003e \u0026lt;\u003d \u003cstrong\u003eF\u003c/strong\u003e \u0026lt;\u003d 1000000 and\u0026nbsp;0 \u0026lt;\u003d \u003cstrong\u003eU\u003c/strong\u003e; \u003cstrong\u003eD\u003c/strong\u003e \u0026lt;\u003d 1000000. The\u003cbr /\u003e floors are one-indexed, i.e. if there are 10 floors, \u003cstrong\u003eS\u003c/strong\u003e and \u003cstrong\u003eG\u003c/strong\u003e be in\u0026nbsp;[1; 10].\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003e You must reply with the minimum numbers of pushes brammy must make in order to get from\u0026nbsp;\u003cstrong\u003eS\u003c/strong\u003e to \u003cstrong\u003eG\u003c/strong\u003e, or output \u0026quot;use the stairs\u0026quot; (without quotes), if it is impossible given the configuation of the building.\u003c/p\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e\r\n10 1 10 2 1\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cp\u003e 6\u003c/p\u003e"}}]}