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: Wrong Answer)

using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var N = cin.ReadInt;
            var A = cin.ReadInt;
            var B = cin.ReadInt;
            var a = new int[N];
            var b = new int[N];
            var dif = new bool[N];
            var count = 0;
            var tmpA = A;
            var tmpB = B;
            for(int i = 0; i < N; i++)
            {
                a[i] = A % 2;
                b[i] = B % 2;
                A /= 2;
                B /= 2;
            }
            for(int i = 0; i < N; i++)
            {
                if(a[i] != b[i])
                {
                  dif[i] = true;
                  count++;
                }
                else
                {
                  dif[i] = false;
                }
            }
            if(count > N)
            {
                Console.WriteLine("NO");
                return;
            }
            else
            {
                Console.WriteLine("YES");
                var ans = tmpA.ToString() + " ";
                var x = 0;
                var flag = false;
                for(int i = 0; i < N; i++)
                {
                    if(flag)
                    {
                        if(x%2 == 0)
                        {
                            x++;
                        }
                        else
                        {
                            x--;
                        }
                        flag = true;
                    }
                    else
                    {
                        x = 0;
                        
                        for(int j = 0; j < N; j++)
                        {
                            if(dif[j] && !flag){
                                x += (1 - a[j]) * (int)Pow(2, j);
                                dif[j] = false;
                                a[j] = 1 - a[j];
                                flag = true;
                            }
                            else
                            {
                                x += a[j] * (int)Pow(2, j);
                            }
                        }
                                                
                        if(!flag)
                        {
                            if(x % 2 == 0)
                            {
                                x++;
                            }
                            else
                            {
                                x--;
                            }
                            flag = true;
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                    ans += x.ToString() + " ";
                }
                ans += tmpB.ToString();
                Console.WriteLine(ans);
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}