{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n\u003cstyle type\u003d\"text/css\"\u003e\nh1,h2,h3,h4,h5,h6{margin-bottom:0;}\ndiv.textBG p{margin: 0 0 0.0001pt;}\n\u003c/style\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003ccenter\u003e\n \u003ch1\u003e\u003cb\u003e\u003ci\u003e ZigZagville \u003c/i\u003e\u003c/b\u003e\u003c/h1\u003e\n\u003c/center\u003e\n\u003cp\u003e\n In the city of ZigZagville, there stands a renowned railway hub. This country boasts\nincredibly rugged terrain. Erected during the previous century, the railway station\nfaced severe budget constraints. Consequently, only a ground-level track could be\nestablished. Additionally, due to space limitations, the station could only function as a\nterminal station (see illustration). Regrettably, the available area could accommodate\njust a single track.\n\u003c/p\u003e\n\u003cimg src\u003d\"https://media.cheggcdn.com/media/37c/37c4f9e3-dc69-4875-a3fd-669623c7f4ea/php7LIBKV.png\"\u003e\n\u003cp\u003e\nA unique local custom dictates that every incoming train from direction A must be\nreconfigured before proceeding in direction B. When a train arrives from direction A,\nit comprises N ≤ 1000 coaches numbered in ascending order from 1 to N . The train\nreconfiguration manager must ascertain the feasibility of rearranging the coaches for\ntheir onward journey in direction B, adhering to the order \u003ci\u003ea\u003csub\u003e1\u003c/sub\u003e, a\u003csub\u003e2\u003c/sub\u003e, . . . , a\u003csub\u003eN\u003c/sub\u003e\u003c/i\u003e. Your task\nis to design a program that determines whether such a rearrangement is achievable.\nIt’s important to note that individual coaches can be detached from the train prior\nto entering the station. These coaches are capable of self-propulsion until they reach\nthe track in direction B. Furthermore, it’s assumed that any number of coaches can\nbe stationed at the station simultaneously. However, once a coach enters the station,\nit cannot return to the track in direction A. Similarly, once a coach departs from the\nstation in direction B, it cannot return.\n\u003c/p\u003e\n\u003ch4\u003e\u003cI\u003eInput\u003c/i\u003e\u003c/h4\u003e\n\u003cp\u003e\n The input file consists of blocks of lines. Each block except the last describes one\ntrain and possibly more requirements for its reorganization. In the first line of the\nblock there is the integer N described above. In each of the next lines of the block\nthere is a permutation of 1, 2, . . . , N . The last line of the block contains just ‘0’.\n\u003c/p\u003e\n\u003cp\u003e\n The last block consists of just one line containing ‘0’.\n\u003c/p\u003e\n\u003ch4\u003e\u003cI\u003eOutput\u003c/i\u003e\u003c/h4\u003e\n\u003cp\u003e\n The output file contains the lines corresponding to the lines with permutations in\nthe input file. A line of the output file contains ‘Yes’ if it is possible to marshal the\ncoaches in the order required on the corresponding line of the input file. Otherwise,\nit contains ‘No’. In addition, there is one empty line after the lines corresponding to one block of the input file. There is no line in the output file corresponding to the\nlast “null” block of the input file.\n\u003c/p\u003e\n\n\u003c/body\u003e\n\u003c/html\u003e\n"}},{"title":"","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e5\n1 2 3 4 5\n5 4 1 2 3\n0\n6\n6 5 4 3 2 1\n0\n0\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eYes\nNo\n\nYes\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}