🏡 index : github.com/captn3m0/codechef.git

---
{"category_name":"easy","problem_code":"MINMAXOR","problem_name":"Chef and Professor","problemComponents":{"constraints":"- $1 \\leq T \\leq 18$\n- $1 \\leq N \\leq 18$\n- Sum of $2^N$ over all test cases does not exceed $10^6$","constraintsState":true,"subtasks":"","subtasksState":false,"inputFormat":"- First-line will contain $T$, the number of test cases. Then the test cases follow.\n- The only line of each test case contains an integer $N$.\n","inputFormatState":true,"outputFormat":"- For each test case, print two lines of output. \n- In the first line, print the number of permutations modulo $(10^9+7)$, for which maximum bitwise xor of any even-length subarray is minimized. \n- In the next line, print $2^N$ space-separated numbers denoting any such permutation.\n","outputFormatState":true,"sampleTestCases":{"0":{"id":1,"input":"2\n1\n2\n","output":"2\n0 1\n8\n3 2 0 1\n","explanation":"**Test case $1$:** There are two optimal permutations: $[0,1]$ and $[1,0]$.\n\n**Test case $2$:** The maximum xor value of any even-sized subarray will be $2$ and there are $8$ such permutations.","isDeleted":false}}},"video_editorial_url":"https://youtu.be/wGWqITNwOl4","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":1,"source_sizelimit":50000,"problem_author":"utkarsh_adm","problem_tester":"","date_added":"25-08-2021","tags":{"0":"easy","1":"permutation","2":"start10","3":"utkarsh_adm"},"problem_difficulty_level":"Unavailable","best_tag":"","editorial_url":"https://discuss.codechef.com/problems/MINMAXOR","time":{"view_start_date":1630243800,"submit_start_date":1630243800,"visible_start_date":1630243800,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=MINMAXOR","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
Chef's professor gave him homework to find a permutation of length $2^N$ such that each integer from $0$ to $2^N  - 1$ appears **exactly once** in the permutation and the maximum [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of any **even length** subarray is minimized. 

Chef wonders how many such permutations are there. Help Chef to find out the number of permutations modulo $(10^9 + 7)$, satisfying the above conditions and also help him find one such permutation.
<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>