Problem:
Score : 800 points

Problem Statement

You are given integers N,\ A and B.
Determine if there exists a permutation (P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the following conditions, and create one such permutation if it exists.

P_0=A

P_{2^N-1}=B

For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} differ by exactly one bit.

Constraints

1 \leq N \leq 17

0 \leq A \leq 2^N-1

0 \leq B \leq 2^N-1

A \neq B

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

If there is no permutation that satisfies the conditions, print NO.

If there is such a permutation, print YES in the first line.
Then, print (P_0,\ P_1,\ ...\ P_{2^N-1}) in the second line, with spaces in between.
If there are multiple solutions, any of them is accepted.

Sample Input 1

2 1 3

Sample Output 1

YES
1 0 2 3

The binary representation of P=(1,0,2,3) is (01,00,10,11), where any two adjacent elements differ by exactly one bit.

Sample Input 2

3 2 1

Sample Output 2

NO

Solution in JavaScript (node.js v5.12) (judge verdict: Wrong Answer)

!function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=15)}({0:function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{l(r.next(t))}catch(t){u(t)}}function a(t){try{l(r.throw(t))}catch(t){u(t)}}function l(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(i,a)}l((r=r.apply(t,e||[])).next())})},o=this&&this.__generator||function(t,e){var n,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(u){return function(a){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,r=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=e.call(t,i)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}},u=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}},i=this;e.__esModule=!0;var a=u(n(1));function l(t){var e,n;return o(this,function(r){switch(r.label){case 0:e=t.split(/\s+/).filter(function(t){return t.length>0}),n=0,r.label=1;case 1:return n<e.length?[4,e[n]]:[3,4];case 2:r.sent(),r.label=3;case 3:return n++,[3,1];case 4:return[2]}})}e.readInput=function(){return new Promise(function(t,e){a.default.readFile("/dev/stdin","utf8",function(n,r){n?e(n):t(r)})})},e.getFoolIterator=l,e.getFoolNextInt=function(){return r(i,void 0,void 0,function(){var t,n;return o(this,function(r){switch(r.label){case 0:return[4,e.readInput()];case 1:return t=r.sent(),n=l(t),[2,function(){return parseInt(n.next().value)}]}})})},e.getChottoMashinaNext=function(){return r(i,void 0,void 0,function(){var t,n;return o(this,function(r){switch(r.label){case 0:return[4,e.readInput()];case 1:return t=r.sent(),n=function(){var e,n,r;return o(this,function(o){switch(o.label){case 0:e=-1,n=0,o.label=1;case 1:return n<=t.length?" "!==t[n]&&"\n"!==t[n]&&n!==t.length?[3,5]:-1!==e?[3,2]:[3,6]:[3,7];case 2:return r=t.substring(e,n),e=-1,[4,r];case 3:o.sent(),o.label=4;case 4:return[3,6];case 5:-1===e&&(e=n),o.label=6;case 6:return n++,[3,1];case 7:return[2]}})}(),[2,function(){return n.next().value}]}})})},e.getChottoMashinaNextInt=function(){return r(i,void 0,void 0,function(){var t;return o(this,function(n){switch(n.label){case 0:return[4,e.getChottoMashinaNext()];case 1:return t=n.sent(),[2,function(){return parseInt(t())}]}})})}},1:function(t,e){t.exports=require("fs")},15:function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{l(r.next(t))}catch(t){u(t)}}function a(t){try{l(r.throw(t))}catch(t){u(t)}}function l(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(i,a)}l((r=r.apply(t,e||[])).next())})},o=this&&this.__generator||function(t,e){var n,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(u){return function(a){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,r=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=e.call(t,i)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}},u=this;e.__esModule=!0;var i=n(0);r(u,void 0,void 0,function(){var t,e,n,r,u,a,l,c,s,f,h,p,b,d;return o(this,function(o){switch(o.label){case 0:return[4,i.getChottoMashinaNextInt()];case 1:if(t=o.sent(),e=t(),n=t(),r=t(),1!==function(t,n){for(var r=0,o=0;o<e;o++)(t&1<<o)!=(n&1<<o)&&r++;return r}(n,r))return console.log("NO"),[2];if(u=function(t,e){for(var n=new Array(2*t.length),r=0;r<t.length;r++)n[r]=t[r];var o=t.length-1;for(r=t.length;r<n.length;r++)n[r]=t[o--]+(1<<e);return n},a=function(t,e){for(var n=0;n<e.length;n++)if(e[n]===t)return n;return-1},l=function(t){for(var e=[0,1],o=1;o<t;o++){if((n&1<<o)!=(r&1<<o)){for(var i=n&(1<<o)-1,l=function(t){return(t-1+e.length)%e.length},c=[],s=l(a(i,e));e[s]!==i;s=l(s))c.push(e[s]);c.push(i),e=c}e=u(e,o)}return e}(e),c=a(n,l),f=function(t){return(t-1+l.length)%l.length},h=(s=function(t){return(t+1)%l.length})(c),p=f(c),l[h]===r){for(b=[],d=c;d!==h;d=f(d))b.push(l[d]);b.push(r),console.log("YES"),console.log(b.join(" "))}else if(l[p]===r){for(b=[],d=c;d!==p;d=s(d))b.push(l[d]);b.push(r),console.log("YES"),console.log(b.join(" "))}else console.log("NO");return[2]}})})}});