output_description: 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.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N A B
attempt: import sys
  import time
  import random
  
  sys.setrecursionlimit(100000000)
  N, A, B = map(int, input().split())
  sTime = time.time()
  
  P = [-1] * N
  Q = [0] * (2**N)
  X = [0] * (2**N)
  X[0] = 1
  X[1] = 1
  Y = [1 << i for i in range(N)]
  Z = [0]
  
  
  def calc(k, l, M):
      aa = 0
      bb = 0
      done = [0] * N
      for i in range(M):
          # print("M, i, k,aa,Y=", M, i, k, aa, Y)
          while k & Y[aa] == 0:
              aa += 1
          while l & Y[bb] == 0:
              bb += 1
          P[aa] = bb
          done[bb] = 1
          aa += 1
          bb += 1
      j = 0
      # print(P)
      # print(done)
      for i in range(N):
          if P[i] >= 0:
              continue
          while done[j] == 1:
              j += 1
          P[i] = j
          j += 1
  
  
  def change(n):
      ret = 0
      for i in range(N):
          if n & (1 << i):
              ret += 1 << P[i]
      return ret
  
  
  def dc(n):
      return sum(map(int, list(bin(n)[2:])))
  
  
  def dfs(n, c):
      if time.time() - sTime > 1.75:
          return -1
      for i in range(N):
          m = n ^ Y[i]
          # print(n, i, m, c)
          if c == 2**N - 2 and m == 1:
              X[m] = 1
              Z.append(m)
              return 1
          if X[m] == 0 and m != 1:
              X[m] = 1
              Z.append(m)
              # print(Z)
              r = dfs(m, c + 1)
              if r:
                  return r
              if r < 0:
                  return -1
              X[m] = 0
              Z.pop()
      return 0
  
  
  if (dc(A) + dc(B)) % 2 == 0:
      print("NO")
  else:
      r = dfs(0, 0)
      for i in range(N):
          if Z[i] == A:
              Z = Z[i:] + Z[:i]
      # print(X, Y, Z)
      if r < 0:
          print("NO")
      else:
          # print("A", Z[:10], Z[-10:])
          mi = 99999
          while mi > 0:
              # for i in range(3, 2**N-1, 2):
              i = random.randrange(max(2**N - 1001, 1), 2**N - 1, 2)
              if Z[i - 1] ^ Z[-1] in Y:
                  Z = Z[:i] + Z[i:][::-1]
                  mi = abs(dc(Z[-1]) - dc(B))
          # print("A", Z[:10], Z[-10:])
          # print("(Z[-1], B, dc(B))", Z[-1], B, dc(B))
          calc(Z[-1], B, dc(B))
          # print("P=", P)
          for i in range(N):
              s = 1 << P[i]
              t = 1 << i
              for j in range(2**N):
                  if j & t:
                      Q[j] += s
          Z = [Q[z] for z in Z]
          # print(Z[:10], Z[-10:])
          print("YES")
          print(*Z)
  
problem_description: 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.
samples: [{"input": "2 1 3", "output": "YES\n    1 0 2 3\n    \n\nThe binary representation of P=(1,0,2,3) is (01,00,10,11), where any two\nadjacent elements differ by exactly one bit.\n\n* * *"}, {"input": "3 2 1", "output": "NO"}]