{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003eThe only difference between the easy and hard versions is the constraints on the number of queries.\u003c/span\u003e\u003c/p\u003e\u003cp\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003eThis is an interactive problem.\u003c/span\u003e\u003c/p\u003e\u003cp\u003eRidbit has a hidden array $$$a$$$ of $$$n$$$ integers which he wants Ashish to guess. Note that $$$n$$$ is a \u003cspan class\u003d\"tex-font-style-bf\"\u003epower of two\u003c/span\u003e. Ashish is allowed to ask three different types of queries. They are of the form \u003c/p\u003e\u003cul\u003e \u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003eAND\u003c/span\u003e $$$i$$$ $$$j$$$: ask for the \u003ca href\u003d\"https://en.wikipedia.org/wiki/Bitwise_operation#AND\"\u003ebitwise AND\u003c/a\u003e of elements $$$a_i$$$ and $$$a_j$$$ $$$(1 \\leq i, j \\le n$$$, $$$i \\neq j)$$$ \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003eOR\u003c/span\u003e $$$i$$$ $$$j$$$: ask for the \u003ca href\u003d\"https://en.wikipedia.org/wiki/Bitwise_operation#OR\"\u003ebitwise OR\u003c/a\u003e of elements $$$a_i$$$ and $$$a_j$$$ $$$(1 \\leq i, j \\le n$$$, $$$i \\neq j)$$$ \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003eXOR\u003c/span\u003e $$$i$$$ $$$j$$$: ask for the \u003ca href\u003d\"https://en.wikipedia.org/wiki/Bitwise_operation#XOR\"\u003ebitwise XOR\u003c/a\u003e of elements $$$a_i$$$ and $$$a_j$$$ $$$(1 \\leq i, j \\le n$$$, $$$i \\neq j)$$$ \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eCan you help Ashish guess the elements of the array?\u003c/p\u003e\u003cp\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003eIn this version, each element takes a value in the range $$$[0, n-1]$$$ (inclusive) and Ashish can ask no more than $$$n+2$$$ queries.\u003c/span\u003e\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of input contains one integer $$$n$$$ $$$(4 \\le n \\le 2^{16})$$$\u0026nbsp;— the length of the array. It is guaranteed that $$$n$$$ is a \u003cspan class\u003d\"tex-font-style-bf\"\u003epower of two\u003c/span\u003e.\u003c/p\u003e"}},{"title":"Interaction","value":{"format":"HTML","content":"\u003cp\u003eTo ask a query print a single line containing one of the following (without quotes) \u003c/p\u003e\u003cul\u003e \u003cli\u003e \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eAND i j\u003c/span\u003e\" \u003c/li\u003e\u003cli\u003e \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eOR i j\u003c/span\u003e\" \u003c/li\u003e\u003cli\u003e \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eXOR i j\u003c/span\u003e\" \u003c/li\u003e\u003c/ul\u003e where $$$i$$$ and $$$j$$$ $$$(1 \\leq i, j \\le n$$$, $$$i \\neq j)$$$ denote the indices being queried.\u003cp\u003eFor each query, you will receive an integer $$$x$$$ whose value depends on the type of query. If the indices queried are invalid or you exceed the number of queries however, you will get $$$x \u003d -1$$$. In this case, you should terminate the program immediately.\u003c/p\u003e\u003cp\u003eWhen you have guessed the elements of the array, print a single line \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e!\u003c/span\u003e \" (without quotes), followed by $$$n$$$ space-separated integers \u0026nbsp;— the elements of the array.\u003c/p\u003e\u003cp\u003eGuessing the array does \u003cspan class\u003d\"tex-font-style-bf\"\u003enot\u003c/span\u003e count towards the number of queries asked.\u003c/p\u003e\u003cp\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003eThe interactor is not adaptive.\u003c/span\u003e The array $$$a$$$ does not change with queries.\u003c/p\u003e\u003cp\u003eAfter printing a query do not forget to output the end of the line and flush the output. Otherwise, you will get \u003cspan class\u003d\"tex-font-style-tt\"\u003eIdleness limit exceeded\u003c/span\u003e. To do this, use:\u003c/p\u003e\u003cul\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003efflush(stdout)\u003c/span\u003e or \u003cspan class\u003d\"tex-font-style-tt\"\u003ecout.flush()\u003c/span\u003e in C++;\u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003eSystem.out.flush()\u003c/span\u003e in Java;\u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003eflush(output)\u003c/span\u003e in Pascal;\u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003estdout.flush()\u003c/span\u003e in Python;\u003c/li\u003e\u003cli\u003e see the documentation for other languages.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003eHacks\u003c/span\u003e\u003c/p\u003e\u003cp\u003eTo hack the solution, use the following test format:\u003c/p\u003e\u003cp\u003eOn the first line print a single integer $$$n$$$ $$$(4 \\le n \\le 2^{16})$$$\u0026nbsp;— the length of the array. It \u003cspan class\u003d\"tex-font-style-bf\"\u003emust\u003c/span\u003e be a power of 2. The next line should contain $$$n$$$ space-separated integers in the range $$$[0, n-1]$$$\u0026nbsp;— the array $$$a$$$.\u003c/p\u003e"}},{"title":"Examples","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\u003e4\n\n0\n\n2\n\n3\n\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eOR 1 2\n\nOR 2 3\n\nXOR 2 4\n\n! 0 0 2 3\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eThe array $$$a$$$ in the example is $$$[0, 0, 2, 3]$$$.\u003c/p\u003e"}}]}