{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n div.illustration {\n float: right;\n padding-left: 20px;\n }\n div.illustration .illustration {\n width: 100%;\n border-radius: 4px;\n }\n pre {\n display: block;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n color: #333;\n word-break: break-all;\n word-wrap: break-word;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cp\u003eHypercube graphs are fascinatingly regular, hence you have\n devoted a lot of time studying the mathematics related to them.\n The vertices of a hypercube graph of dimension \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e are all binary strings of length\n \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e, and two vertices are\n connected if they differ in a single position. There are many\n interesting relationships between hypercube graphs and\n error-correcting code.\u003c/p\u003e\n\n \u003cp\u003eOne such relationship concerns the \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e-bit Gray Code, which is an\n ordering of the binary strings of length \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e, defined recursively as follows.\n The sequence of words in the \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e-bit code first consists of the\n words of the \u003cspan class\u003d\"tex2jax_process\"\u003e$(n-1)$\u003c/span\u003e-bit\n code, each prepended by a \u003cspan class\u003d\"tex2jax_process\"\u003e$0$\u003c/span\u003e, followed by the same words in\n reverse order, each prepended by a \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e. The \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e-bit Gray Code just consists of a\n \u003cspan class\u003d\"tex2jax_process\"\u003e$0$\u003c/span\u003e and a \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e. For example the \u003cspan class\u003d\"tex2jax_process\"\u003e$3$\u003c/span\u003e-bit Gray Code is the following\n sequence:\u003c/p\u003e\u003cspan class\u003d\"tex2jax_process\"\u003e\\[\n 000,001,011,010,110,111,101,100 \\]\u003c/span\u003e\n\n \u003cp\u003eNow, the \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e-bit Gray\n Code forms a Hamiltonian path in the \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e-dimensional hypercube, i.e., a\n path that visits every vertex exactly once (see\n Figure\u0026nbsp;1).\u003c/p\u003e\n\n \u003cdiv id\u003d\"fig:graycode\" class\u003d\"figure\"\u003e\n \u003ccenter\u003e\n \u003cimg src\u003d\"CDN_BASE_URL/851620ca2d680566444e06ff00c09b22?v\u003d1715021916\" alt\u003d\"\\includegraphics[width\u003d0.33\\textwidth ]{example-fig}\" style\u003d\"width:33.00%\"\u003e\n\n \u003cdiv class\u003d\"caption\"\u003e\n \u003cb\u003eFigure 1\u003c/b\u003e: The \u003cspan class\u003d\"tex2jax_process\"\u003e$3$\u003c/span\u003e-dimensional hypercube and\n the Hamiltonian path corresponding to the \u003cspan class\u003d\"tex2jax_process\"\u003e$3$\u003c/span\u003e-bit Gray Code.\n \u003c/div\u003e\n \u003c/center\u003e\n \u003c/div\u003e\n\n \u003cp\u003eYou wonder how many vertices there are between the vertices\n \u003cspan class\u003d\"tex2jax_process\"\u003e$0^ n$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e zeros) and \u003cspan class\u003d\"tex2jax_process\"\u003e$1^ n$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e ones) on that path. Obviously it\n will be somewhere between \u003cspan class\u003d\"tex2jax_process\"\u003e$2^{n-1}-1$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$2^ n-2$\u003c/span\u003e, since in general\n \u003cspan class\u003d\"tex2jax_process\"\u003e$0^ n$\u003c/span\u003e is the first\n vertex, and \u003cspan class\u003d\"tex2jax_process\"\u003e$1^ n$\u003c/span\u003e is\n somewhere in the second half of the path. After finding an\n elegant answer to this question you ask yourself whether you\n can generalise the answer by writing a program that can\n determine the number of vertices between two arbitrary vertices\n of the hypercube, in the path corresponding to the Gray\n Code.\u003c/p\u003e\n\n \u003ch2\u003eInput\u003c/h2\u003e\n\n \u003cp\u003eThe input consists of a single line, containing:\u003c/p\u003e\n\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eone integer \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e\n (\u003cspan class\u003d\"tex2jax_process\"\u003e$1 \\leq n \\leq 60$\u003c/span\u003e),\n the dimension of the hypercube\u003c/p\u003e\n \u003c/li\u003e\n\n \u003cli\u003e\n \u003cp\u003etwo binary strings \u003cspan class\u003d\"tex2jax_process\"\u003e$a$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$b$\u003c/span\u003e, both of length \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e, where \u003cspan class\u003d\"tex2jax_process\"\u003e$a$\u003c/span\u003e appears before \u003cspan class\u003d\"tex2jax_process\"\u003e$b$\u003c/span\u003e in the \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e-bit Gray Code.\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n\n \u003ch2\u003eOutput\u003c/h2\u003e\n\n \u003cp\u003eOutput the number of code words between \u003cspan class\u003d\"tex2jax_process\"\u003e$a$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$b$\u003c/span\u003e in the \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e-bit Gray Code.\u003c/p\u003e\n\n \u003ch2\u003eSample 1\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\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\u003e3 001 111\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e3\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n\n \u003ch2\u003eSample 2\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\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\u003e3 110 100\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n "}}]}