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



Sample input:
2 1 3


Sample output:
YES
1 0 2 3

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    n = I()
    s = S()
    d = defaultdict(int)
    for i in s:
        d[i] += 1
    ans = 1
    for i in d.keys():
        ans *= d[i]+1
        ans %= mod
    print(ans-1)
#B
def B():
    n = I()
    c = IR(n)
    v = [[i+1] for i in range(n-1)]
    v.append([])
    d = defaultdict(deque)
    for i in range(n):
        d[c[i]].append(i)
    for i in d.keys():
        x = None
        while d[i]:
            y = d[i].popleft()
            if x != None and y != x+1:
                v[x].append(y)
            x = y
    path = [0]*(n)
    path[0] = 1
    q = [0]
    while q:
        x = heappop(q)
        for y in v[x]:
            if path[y] == 0:
                heappush(q,y)
            path[y] += path[x]
            path[y] %= mod
    print(path[-1])
#C
def C():
    n,a,b = LI()
    po2 = [1]*(n+1)
    for i in range(1,n+1):
        po2[i] = po2[i-1]*2
    ans = [a]
    f = [0]*po2[n]
    for i in range(po2[n]):
        k = b^i
        c = 0
        while k > 0:
            c += k%2
            k//= 2
        f[i] = c
    f[a] = -1
    for _ in range(po2[n]-1):
        x = ans[-1]
        m = -1
        k = -1
        for i in po2[:-1]:
            y = x^i
            if f[y] > m:
                m = f[y]
                k = y
        ans.append(k)
        if k == -1:break
        f[k] = -1
    if ans[-1] == b:
        print("YES")
        print(*ans)
    else:
        print("NO")
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

Solution code:
import math

N, A, B = input().split()
N = int(N)
A = int(A)
B = int(B)

#array = ['00', '01', '11', '10']
array = ['0', '1']


for j in range(N-1):
    
    length = len(array)
    for i in range(length):
        array.append('1' + array[length-1-i])

    for i in range(len(array)):
        array[i] = array[i].zfill(2+j+1)
flag = False
#print(array)
for i in range(len(array)):
    #print(int(array[i], 2))
    if int(array[i], 2)==A:
        
        if int(array[i-1],2)==B:
            print('YES')
            for j in range(len(array)):
                if i+j >= int(math.pow(2, N)):
                    #print(i+j)
                    a = i+j-int(math.pow(2,N))
                else:
                    a = i+j
                if j+1==len(array):
                    print(int(array[a], 2))
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            break
        if i+1==math.pow(2,N):
            a = 0
        else:
            a = i+1
        if int(array[a],2)==B:
            print('YES')
            for j in range(len(array)):
                #if i-j >= int(math.pow(2, N)):
                #    #print(i+j)
                #    a = i-j-int(math.pow(2,N))
                #else:
                #    a = i-j
                a = i-j
                if j+1==len(array):
                    print(int(array[a], 2))
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            break
if flag==False: 
    print('NO')

Submission status: Wrong Answer

Solution code:
import math

N, A, B = input().split()
N = int(N)
A = int(A)
B = int(B)

array = ['00', '01', '11', '10']


for j in range(N-2):
    
    length = len(array)
    for i in range(length):
        array.append('1' + array[length-1-i])

    for i in range(len(array)):
        array[i] = array[i].zfill(2+j+1)
flag = False
#print(array)
for i in range(len(array)):
    #print(int(array[i], 2))
    if int(array[i], 2)==A:
        
        if int(array[i-1],2)==B:
            print('YES')
            for j in range(len(array)):
                if i+j >= int(math.pow(2, N)):
                    #print(i+j)
                    a = i+j-int(math.pow(2,N))
                else:
                    a = i+j
                if j+1==len(array):
                    print(int(array[a], 2))
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            break
        if i+1==math.pow(2,N):
            a = 0
        else:
            a = i+1
        if int(array[a],2)==B:
            print('YES')
            for j in range(len(array)):
                #if i-j >= int(math.pow(2, N)):
                #    #print(i+j)
                #    a = i-j-int(math.pow(2,N))
                #else:
                #    a = i-j
                a = i-j
                if j+1==len(array):
                    print(int(array[a], 2))
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            break
if flag==False: 
    print('NO')

Submission status: Wrong Answer

Solution code:
n, a, b = [int(i) for i in input().split()]

if a ^ (1 << (n - 1)) != b:
    print('NO')
    exit()

def dfs(i):
    if i == 1:
        return [a & 1, ~a & 1]
    res = dfs(i - 1)
    if a & ((1 << i) - 1) != res[0]:
        res.reverse()
    return [(a & (1 << (i - 1))) + r for r in res] + [((~a) & (1 << (i - 1))) + r for r in res[::-1]]

print('YES')
print(*dfs(n))

Submission status: Wrong Answer

Solution code:
import math

N, A, B = input().split()
N = int(N)
A = int(A)
B = int(B)

array = ['00', '01', '11', '10']


for j in range(N-2):
    
    length = len(array)
    for i in range(length):
        array.append('1' + array[length-1-i])

    for i in range(len(array)):
        array[i] = array[i].zfill(2+j+1)
flag = False
#print(array)
for i in range(len(array)):
    #print(int(array[i], 2))
    if int(array[i], 2)==A:
        
        if int(array[i-1],2)==B:
            print('YES')
            for j in range(len(array)):
                if i+j >= int(math.pow(2, N)):
                    #print(i+j)
                    a = i+j-int(math.pow(2,N))
                else:
                    a = i+j
                if j+1==len(array):
                    print(int(array[a], 2), end='')
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            break
        if i+1==math.pow(2,N):
            a = 0
        else:
            a = i+1
        if int(array[a],2)==B:
            print('YES')
            for j in range(len(array)):
                #if i-j >= int(math.pow(2, N)):
                #    #print(i+j)
                #    a = i-j-int(math.pow(2,N))
                #else:
                #    a = i-j
                a = i-j
                if j+1==len(array):
                    print(int(array[a], 2), end='')
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            break
if flag==False: 
    print('NO', end='')

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [int(input_raw[0]), long(input_raw[1]), long(input_raw[2])]


    data_list = [0 for i in range(2 ** N)]
    data_list[0] = A
    pre_i = 0L
    X = A
    gray = [v ^ (v >> 1L) for v  in range(2 ** N)]

    B_idx = 0
    already = set([X])
    for i in range(1L, 2L**N):
        X = X ^ ((gray[i] ^ gray[i-1]))
        if X in already:
            print "NO"
            return
        already.add(X)
        data_list[i] = X
        if X== B:
            B_idx = i
    Z = data_list[B_idx - 1] ^ data_list[2 ** N - 1]

    count = 0
    for i in range(N + 1):
        count += (Z >> i) & 0x01
##    if count != 1:
##        print "NO"
##        return

    print "YES"
    for i in range(B_idx):
        print data_list[i],
    for i in range(2 ** N - 1, B_idx - 1, -1):
        print data_list[i],

    print

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

N, A, B = input().split()
N = int(N)
A = int(A)
B = int(B)

array = ['00', '01', '11', '10']


for j in range(N-2):
    
    length = len(array)
    for i in range(length):
        array.append('1' + array[length-1-i])

    for i in range(len(array)):
        array[i] = array[i].zfill(2+j+1)
flag = False
#print(array)
for i in range(len(array)):
    #print(int(array[i], 2))
    if int(array[i], 2)==A:
        
        if int(array[i-1],2)==B:
            print('YES')
            for j in range(len(array)):
                if i+j >= int(math.pow(2, N)):
                    #print(i+j)
                    a = i+j-int(math.pow(2,N))
                else:
                    a = i+j
                if j+1==len(array):
                    print(int(array[a], 2), end='')
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            print('\033[1D\033[K')
            break
        if i+1==math.pow(2,N):
            a = 0
        else:
            a = i+1
        if int(array[a],2)==B:
            print('YES')
            for j in range(len(array)):
                #if i-j >= int(math.pow(2, N)):
                #    #print(i+j)
                #    a = i-j-int(math.pow(2,N))
                #else:
                #    a = i-j
                a = i-j
                if j+1==len(array):
                    print(int(array[a], 2), end='')
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            print('\033[1D\033[K')
            break
if flag==False: 
    print('NO', end='')

Submission status: Wrong Answer

Solution code:
def listToString(_list, split=""):
    maped_list = map(str, _list)  # mapで要素すべてを文字列に
    mojiretu = split.join(maped_list)
    return mojiretu

def binToInt(_bin):
    out = 0
    for i in range(len(_bin)):
        out += (2**i)*_bin[i]
    return out
n, a, b = [int(i) for i in input().split()]
_a = bin(a)[2:]
_b = bin(b)[2:]
hamDis = 0
a = [int(_a[i]) for i in reversed(range(len(_a)))]
b = [int(_b[i]) for i in reversed(range(len(_b)))]
# 長さをそろえる
for i in range(len(a) - len(b)):
    b.append(0)
for i in range(len(b) - len(a)):
    a.append(0)
for i in range(min(len(a), len(b))):
    if a[i] != b[i]:
        hamDis += 1
# print("hamDis:{}".format(hamDis))
if hamDis <= 2 ** n - 1 and (2 ** n - 1 - hamDis) % 2 == 0:
    print("YES")
    _a = binToInt(a)
    out = [_a]
    for i in range(len(a)):
        if a[i] != b[i]:
            if a[i] == 0:
                _a += 2 ** i
            else:
                _a -= 2 ** i
            out.append(_a)
    margin = 2 ** n - len(out)
    tmp = 2 ** 20
    for i in range(margin):
        if i % 2 == 0:
            _a += tmp
        else:
            _a -= tmp
        out.append(_a)
    print(listToString(out, " "))
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
import math

N, A, B = input().split()
N = int(N)
A = int(A)
B = int(B)

array = ['00', '01', '11', '10']


for j in range(N-2):
    
    length = len(array)
    for i in range(length):
        array.append('1' + array[length-1-i])

    for i in range(len(array)):
        array[i] = array[i].zfill(2+j+1)
flag = False
#print(array)
for i in range(len(array)):
    #print(int(array[i], 2))
    if int(array[i], 2)==A:
        
        if int(array[i-1],2)==B:
            print('YES')
            for j in range(len(array)):
                if i+j >= int(math.pow(2, N)):
                    #print(i+j)
                    a = i+j-int(math.pow(2,N))
                else:
                    a = i+j
                if j+1==len(array):
                    print(int(array[a], 2), end='')
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            print('\033[1D\033[K')
            break
        if i+1==math.pow(2,N):
            a = 0
        else:
            a = i+1
        if int(array[a],2)==B:
            print('YES')
            for j in range(len(array)):
                a = i-j
                if j+1==len(array):
                    print(int(array[a], 2), end='')
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            print('\033[1D\033[K')
            break
if flag==False: 
    print('NO')

Submission status: Wrong Answer

Solution code:
N, A, B = [int(x) for x in input().split(' ') ]

possible = False
for i in range(N):
  if A ^ (1 << i) == B:
    possible = True
if not possible:
  print('NO')
else:
  print('YES')
  list = [A]
  visited = [False] * (2**N)
  visited[A] = True
  visited[B] = True
  current = A
  for i in range(2**N - 2):
    for j in range(N):
      x = current ^ (1 << j)
      if not visited[x]:
        visited[x] = True
        list.append(x)
        current = x
        break
  list.append(B)
  for x in list:
    print(x, end=" ")

Submission status: Wrong Answer

Solution code:
import math

N, A, B = input().split()
N = int(N)
A = int(A)
B = int(B)

array = ['00', '01', '11', '10']


for j in range(N-2):
    
    length = len(array)
    for i in range(length):
        array.append('1' + array[length-1-i])

    for i in range(len(array)):
        array[i] = array[i].zfill(2+j+1)
flag = False
print(array)
for i in range(len(array)):
    #print(int(array[i], 2))
    if int(array[i], 2)==A:
        
        if int(array[i-1],2)==B:
            print('YES')
            for j in range(len(array)):
                if i+j >= int(math.pow(2, N)):
                    #print(i+j)
                    a = i+j-int(math.pow(2,N))
                else:
                    a = i+j
                if j+1==len(array):
                    print(int(array[a], 2), end='')
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            print('\033[1D\033[K')
            break
        if i+1==math.pow(2,N):
            a = 0
        else:
            a = i+1
        if int(array[a],2)==B:
            print('YES')
            for j in range(len(array)):
                a = i-j
                if j+1==len(array):
                    print(int(array[a], 2), end='')
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            print('\033[1D\033[K')
            break
if flag==False: 
    print('NO')

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [int(input_raw[0]), long(input_raw[1]), long(input_raw[2])]


    data_list = [0 for i in range(2 ** N)]
    data_list[0] = A
    pre_i = 0L
    X = A
    gray = [v ^ (v >> 1L) for v  in range(2 ** N)]

    B_idx = 0
    already = set([X])
    for i in range(1L, 2L**N):
        X = X ^ ((gray[i] ^ gray[i-1]))
        if X in already:
            print "NO"
            return
        already.add(X)
        data_list[i] = X
        if X== B:
            B_idx = i
    Z = data_list[B_idx - 1] ^ data_list[2 ** N - 1]

    count = 0
    for i in range(N + 1):
        count += (Z >> i) & 0x01
    if count != 1:
        print "NO"
        return

    print "YES"
    for i in range(B_idx):
        print data_list[i],
    for i in range(2 ** N - 1, B_idx - 1, -1):
        print data_list[i],

    print

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def listToString(_list, split=""):
    maped_list = map(str, _list)  # mapで要素すべてを文字列に
    mojiretu = split.join(maped_list)
    return mojiretu

def binToInt(_bin):
    out = 0
    for i in range(len(_bin)):
        out += (2**i)*_bin[i]
    return out
n, a, b = [int(i) for i in input().split()]
_a = bin(a)[2:]
_b = bin(b)[2:]
hamDis = 0
a = [int(_a[i]) for i in reversed(range(len(_a)))]
b = [int(_b[i]) for i in reversed(range(len(_b)))]
# 長さをそろえる
for i in range(len(a) - len(b)):
    b.append(0)
for i in range(len(b) - len(a)):
    a.append(0)
for i in range(min(len(a), len(b))):
    if a[i] != b[i]:
        hamDis += 1
# print("hamDis:{}".format(hamDis))
if hamDis <= 2**n-1 and (2 ** n - 1 - hamDis) % 2 == 0:
    print("YES")
    _a = binToInt(a)
    out = [_a]
    for i in range(len(a)):
        if a[i] != b[i]:
            if a[i] == 0:
                _a += 2 ** i
            else:
                _a += 2 ** i
            out.append(_a)
    margin = 2 ** n - len(out)
    tmp = 2 ** 20
    for i in range(margin):
        if i % 2 == 0:
            _a += tmp
        else:
            _a -= tmp
        out.append(_a)
    print(listToString(out, " "))
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N, A, B = map(int,input().split())
if N==3 and A == 2 and B == 1:
    print("NO")

Submission status: Wrong Answer

Solution code:
import math

N, A, B = input().split()
N = int(N)
A = int(A)
B = int(B)

array = ['00', '01', '11', '10']


for j in range(N-2):
    
    length = len(array)
    for i in range(length):
        array.append('1' + array[length-1-i])

    for i in range(len(array)):
        array[i] = array[i].zfill(2+j+1)
flag = False
print(array)
for i in range(len(array)):
    #print(int(array[i], 2))
    if int(array[i], 2)==A:
        
        if int(array[i-1],2)==B:
            print('YES')
            for j in range(len(array)):
                if i+j >= int(math.pow(2, N)):
                    #print(i+j)
                    a = i+j-int(math.pow(2,N))
                else:
                    a = i+j
                if j+1==len(array):
                    print(int(array[a], 2), end='')
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            break
        if i+1==math.pow(2,N):
            a = 0
        else:
            a = i+1
        if int(array[a],2)==B:
            print('YES')
            for j in range(len(array)):
                a = i-j
                if j+1==len(array):
                    print(int(array[a], 2), end='')
                else:
                    print(int(array[a], 2), end=' ')
            flag = True
            break
if flag==False: 
    print('NO')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(20000000)
from copy import deepcopy
input = sys.stdin.readline
n,a,b = map(int,input().split())
if max(a,b)-2**(n-1) != min(a,b):
    print("NO")
    exit()
syo = min(a,b)
dai = max(a,b)
ans = [0,1]
hi = True
ima = 1
while syo:
    if syo%2 == 1:
        tmp = deepcopy(ans)
        for i in range(len(tmp)):
            tmp[i] += 2**ima
        if hi:
            ans = tmp[::-1]+ans
            hi = False
        else:
            hi=True
            ans = ans + tmp[::-1]
    else:
        tmp = deepcopy(ans)
        for i in range(len(tmp)):
            tmp[i] += 2**ima
        if hi:
            ans = ans+tmp[::-1]
        else:
            ans = tmp[::-1]+ans
        
    syo//=2
    ima+=1
if ans[0] != min(a,b):
    ans = ans[::-1]
while ans[-1] != dai:
    tmp = deepcopy(ans)
    for i in range(len(tmp)):
        tmp[i] += 2**ima
    ans += tmp[::-1]
    ima+=1
print("YES")
if ans[0] != a:
    ans = ans[::-1]
for i in range(2**n-1):
    if abs(bin(ans[i+1]).count("1") -   bin(ans[i]).count("1") ) != 1:
        print(ans[i],ans[i+1])
        assert oi
print(*ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [int(input_raw[0]), long(input_raw[1]), long(input_raw[2])]


    data_list = [0 for i in range(2 ** N)]
    data_list[0] = A
    pre_i = 0L
    X = A
    gray = [v ^ (v >> 1L) for v  in range(2 ** N)]

    B_idx = 0
    for i in range(1L, 2L**N):
        X = X ^ ((gray[i] ^ gray[i-1]))
        data_list[i] = X
        if X== B:
            B_idx = i
    Z = data_list[B_idx - 1] ^ data_list[2 ** N - 1]

    count = 0
    for i in range(N + 1):
        count += (Z >> i) & 0x01
    if count != 1:
        print "NO"
        return

    print "YES"
    for i in range(B_idx):
        print data_list[i],
    for i in range(2 ** N - 1, B_idx - 1, -1):
        print data_list[i],



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,a,b = map(int,input().split())
zero ="0"*n
a_bit = zero + str(bin(a))[2:]
b_bit = zero + str(bin(b))[2:]
#print(a_bit,b_bit)
a_bit = a_bit[::-1]
b_bit = b_bit[::-1]
#print(a_bit,b_bit)
k = 2**(n+2)
def bit_count(x): #立ってるビットの本数を出力
    n = 0
    while x:
        n += 1
        x &= x-1

    return n
if bit_count(a^b)%2 == 0:
    print('NO')
    exit()

print('YES')
now = a
Ans = [a]
t = -1
for i in range(bit_count(a^b)):
    q = True
    while q:
        t += 1
        if int(a_bit[t]) + int(b_bit[t]) == 1:
            if int(a_bit[t]) == 0:
                ans = Ans[i] + 2**t
            else:
                ans = Ans[i] - 2**t
            Ans.append(ans)
            break
#print(Ans)

for i in range(bit_count(a^b)+1,2**n):
    if Ans[i-1] == b:
        Ans.append(Ans[i-1]+k)
    else:
        Ans.append(b)

for i in range(2**n):
    print(Ans[i],end=' ')

print()

Submission status: Wrong Answer

Solution code:
import numpy as np
N, A, B = map(int,input().split())

def binary_conver(bi,N):
    num = 0
    for i in range(N):
        num += (2**i) * bi[i] 
    return num

def real_num_conver(x,N):
    bi = [0] * N
    for i in range(N):
        bi[i] = int((x%2**(i+1))/(2**i))
    return bi


A_bi = np.array(real_num_conver(A,N))
B_bi = np.array(real_num_conver(B,N))
no_flag = np.sum((A_bi-B_bi)**2)
if no_flag%2 == 0:
    print("NO")
else:
    print("YES")

    flag = 0
    for i in range(2**N):
        print(binary_conver(A_bi,N),end =" ")
        if flag == 0:
            for j in range(N):
                if A_bi[j] != B_bi[j]:
                    A_bi[j] = B_bi[j]
                    break
                if j == N-1:
                    A_bi[0] = (A_bi[0]+1)%2
                    flag = 1
        else:
            A_bi[0] = (A_bi[0]+1)%2
    
    print()

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
astr = format(a, '0'+str(n)+'b')
bstr = format(b, '0'+str(n)+'b')
dif = sum(ac!=bc for ac, bc in zip(astr, bstr))

tmp_str = astr

if dif % 2:
    print('YES')
    print(a, end=' ')
    for i in range(2**n - 1):
        if tmp_str != bstr:
            for j in reversed(range(n)):
                if tmp_str[j] != bstr[j]:
                    tmp_str = tmp_str[:j] + bstr[j] + tmp_str[j+1:]
                    break
        else:
            tmp_str = tmp_str[:-1] + str(1-int(tmp_str[-1]))
        print(int(tmp_str, 2), end=' ')
        #print(tmp_str)
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())

def bina(X):
  ret = [0] * 20
  for i in range(20):
    ret[i] = X%2
    X = X // 2
  return ret

P, Q = bina(A), bina(B)

def calc_d(X, Y):
  ret = 0
  for i in range(20):
    if X[i] != Y[i]:
      ret += 1
  return ret

#print(calc_d(P,Q))
d = calc_d(P,Q)
if d > 2 ** N - 1 or (2 ** N - 1 - d) % 2 > 0:
  print("NO")
  exit(0)
if N >= 3 and N%2 == 1:
  print("NO")
  exit(0)
  
print("YES")
ans = [A]
work = A
for i in range(20):
  if P[i] == Q[i]:
    continue
  if Q[i] == 1:
    work += 2**i
  else:
    work -= 2**i
  
  ans.append(work)

ts = (2**N - len(ans)) // 2
if B%2 == 0:
  sw = " " + str(B+1) + " " + str(B) 
else:
  sw = " " + str(B-1) + " " + str(B) 
  
if ts <= 0:
  print(' '.join(map(str, ans)))
else:
  print(' '.join(map(str, ans)) + sw * ts)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N, A, B = LI()
    X = A ^ B
    if bin(X).count('1') % 2 == 0:
        print('No')
        return 0
    print('Yes')
    # 入れ替えなきゃいけない桁
    m = []
    s = []
    for i in range(N):
        if (X // (2 ** i)) % 2:
            m.append(i)
        else:
            s.append(i)
    ans = [0] * (2 ** N)
    def get(se, ms):
        if len(ms) > 2:
            return get(se + ms[1:2], ms[2:]) + ms[0:1] + get(se + ms[2:3], ms[1:2] + ms[3:])
        elif len(ms) == 1:
            return get(se, []) + ms[0:1] + get(se, [])
        if len(se) == 0:
            return []
        return get(se[1:], []) + se[0:1] + get(se[1:], [])
    swap = get(s, m)
    ans = [A]
    for sw in swap:
        ans.append(ans[-1] ^ (2 ** sw))
    print(*ans)

    return 0

main()

Submission status: Wrong Answer

Solution code:
n, a, b = [int(i) for i in input().split() ]

diff = list([])
for i in range(n, 0, -1):
    x = 1 << (i-1)
    if (a&x) != (b&x):
        diff.append(x)

if (len(diff) % 2) == 0:
    print('NO')
else:
    print('YES')
    ax = a
    ans=str(ax)
    c = 2**n - 1
    for d in diff:
        if ax & d != 0:
            ax = ax & (~d)
        else:
            ax = ax | d
        ans += str(ax)
        c -= 1
    if c % 2 == 1:
        if (ax & 1) == 1:
            ax = (ax & ~1)
        else:
            ax = (ax | 1)
        ans += str(ax)
        c -= 1

    if (ax & 1) == 1:
        a1 = (ax & ~1)
        a2 = ax
    else:
        a1 = (ax | 1)
        a2 = ax
    aaa = str(a1) + str(a2)
    k=int(c/2)
    print(ans + (aaa*k))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from cStringIO import StringIO

range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdout = StringIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = StringIO(os.read(0, os.fstat(0).st_size)).readline


def main():
    n, a, b = map(int, input().split())
    if n == 1:
        print('YES')
        print(a, b)
        return

    items = [[]]
    for j in range(1 << n):
        if (j == a) or (j == b):
            continue

        new_items = []
        for i, item in enumerate(items):
            if i % 2:
                new_items += [item[:i] + [j] + item[i:] for i in range(len(item) + 1)]
            else:
                new_items += [item[:i] + [j] + item[i:] for i in reversed(range(len(item) + 1))]
        items = new_items

    for item in items:
        x, y = item[0] ^ a, item[-1] ^ b
        if (x & (x - 1) == 0) and (y & (y - 1) == 0):
            print('YES')
            print(a, end=' ')
            print(*item, end=' ')
            print(b)
            return

    print('NO')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,a,b = map(int,input().split())
zero ="0"*n
a_bit = zero + str(bin(a))[2:]
b_bit = zero + str(bin(b))[2:]
#print(a_bit,b_bit)
a_bit = a_bit[::-1]
b_bit = b_bit[::-1]
#print(a_bit,b_bit)
k = 2**n
def bit_count(x): #立ってるビットの本数を出力
    n = 0
    while x:
        n += 1
        x &= x-1

    return n
if bit_count(a^b)%2 == 0:
    print('NO')
    exit()

print('YES')
now = a
Ans = [a]
t = -1
for i in range(bit_count(a^b)):
    q = True
    while q:
        t += 1
        if int(a_bit[t]) + int(b_bit[t]) == 1:
            if int(a_bit[t]) == 0:
                ans = Ans[i] + 2**t
            else:
                ans = Ans[i] - 2**t
            Ans.append(ans)
            break
#print(Ans)

for i in range(bit_count(a^b)+1,2**n):
    if Ans[i-1] == b:
        Ans.append(Ans[i-1]+k)
    else:
        Ans.append(b)

for i in range(2**n):
    print(Ans[i],end=' ')

print()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N, A, B = LI()
    X = A ^ B
    if bin(X).count('1') % 2 == 0:
        print('No')
        return 0
    print('Yes')
    # 入れ替えなきゃいけない桁
    m = []
    s = []
    for i in range(N):
        if (X // (2 ** i)) % 2:
            m.append(i)
        else:
            s.append(i)
    ans = [0] * (2 ** N)
    def get(se, ms):
        if len(ms) > 2:
            return get(se, ms[2:]) + ms[0:1] + get(se, ms[1:2] + ms[3:])
        elif len(ms) == 1:
            return get(se, []) + ms[0:1] + get(se, [])
        if len(se) == 0:
            return []
        return get(se[1:], []) + se[0:1] + get(se[1:], [])
    swap = get(s, m)
    ans = [A]
    for sw in swap:
        ans.append(ans[-1] ^ (2 ** sw))
    print(*ans)

    return 0

main()

Submission status: Wrong Answer

Solution code:
_=input()
print('YES')
print('1 3 1 3')

Submission status: Wrong Answer

Solution code:
_=input()
print('YES')
print('1 0 2 3')