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 Common Lisp (SBCL 1.1.14) (judge verdict: Wrong Answer)

;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (inline natural-to-gray))
(defun natural-to-gray (x)
  (declare (unsigned-byte x))
  (logxor x (ash x -1)))

(declaim (inline natural-to-gray))
(defun gray-to-natural (x)
  (declare (unsigned-byte x))
  (do ((pos (- (integer-length x) 2) (- pos 1)))
      ((< pos 0) x)
    (setf (ldb (byte 1 pos) x)
                 (logxor (ldb (byte 1 pos) x)
                         (ldb (byte 1 (+ pos 1)) x)))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (a (read))
         (b (read))
         (a^b (logxor a b))
         (upper-a^b (natural-to-gray (ash a^b -1)))
         (upper-bound (ash 1 (- n 1))))
    (declare (uint8 n)
             (uint31 a b))
    (when (evenp (logcount a^b))
      (write-line "NO")
      (return-from main))
    (write-line "YES")
    (labels ((get-original (upper lsb)
               (logxor a (+ lsb (ash (gray-to-natural upper) 1)))))
      (if (logbitp 0 a^b)
          (progn
            (loop for i below upper-a^b by 2
                  do (format t "~D " (get-original i 0))
                     (format t "~D " (get-original i 1))
                     (format t "~D " (get-original (+ i 1) 1))
                     (format t "~D " (get-original (+ i 1) 0)))
            (loop for i from upper-a^b below upper-bound
                  do (format t "~D " (get-original i 0)))
            (loop for i from (- upper-bound 1) above upper-a^b
                  do (format t "~D " (get-original i 1))
                  finally (format t "~D~%" (get-original upper-a^b 1))))
          (progn
            ;; #>upper-a^b
            (format t "~D " (get-original 0 0))
            (format t "~D " (get-original 0 1))
            (loop for i from 1 below upper-a^b by 2
                  do (format t "~D " (get-original i 1))
                     (format t "~D " (get-original i 0))
                     (format t "~D " (get-original (+ i 1) 0))
                     (format t "~D " (get-original (+ i 1) 1)))
            (loop for i from upper-a^b below upper-bound
                  do (format t "~D " (get-original i 1)))
            (loop for i from (- upper-bound 1) above upper-a^b
                  do (format t "~D " (get-original i 0))
                  finally (format t "~D~%" (get-original upper-a^b 0))))))))

#-swank(main)