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 C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0];
		var A = (uint)I[1];
		var B = (uint)I[2];
		if (BitCount(A ^ B) % 2 == 0) { WriteLine("NO"); return; }
		WriteLine("YES");
		var l = Generate(N, A, B);
		WriteLine(string.Join(" ", l));
	}
	List<uint> Generate(int N, uint A, uint B)
	{
		if (N == 1) return new List<uint> { A, B };
		B ^= A;
		var cnt = BitCount(B);
		var perm = new int[N];
		var one = N - 1;
		var zero = 0;
		for (var i = 0; i < N; i++) perm[i] = (B & (1u << i)) != 0 ? one-- : zero++;
		var iperm = new int[N];
		for (var i = 0; i < N; i++) iperm[perm[i]] = i;
		B = ((1u << cnt) - 1) << (N - cnt);
		var ans = new List<uint>();
		var lim = 1u << (N - 1);
		for (var i = 0u; i < lim; i++) ans.Add(i ^ (i >> 1));
		foreach (var i in Generate(N - 1, 1u << (N - 2), B ^ lim)) ans.Add(i ^ lim);
		for (var i = 0; i < ans.Count; i++)
		{
			var s = 0u;
			for (var j = 0; j < N; j++) if ((ans[i] & (1u << j)) != 0) s |= 1u << iperm[j];
			ans[i] = s ^ A;
		}
		return ans;
	}
	public static int BitCount(uint n)
	{
		n = (n & 0x55555555) + ((n >> 1) & 0x55555555);
		n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
		n = (n & 0x0f0f0f0f) + ((n >> 4) & 0x0f0f0f0f);
		n = (n & 0x00ff00ff) + ((n >> 8) & 0x00ff00ff);
		return (int)((n & 0x0000ffff) + ((n >> 16) & 0x0000ffff));
	}
}