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:
n,a,b=map(int,input().split())
ab=format(a,"b").zfill(n)
bb=format(b,"b").zfill(n)
alb=list(ab)
blb=list(bb)
cnt=0
l=[]
for i in range(n):
    if alb[i]!=blb[i]:
        l.append(i)
        cnt+=1
if cnt%2==0 or cnt>2**n-1:
    print("NO")
    exit (0)
print("YES")
print(a,end=" ")
for i in l:
    if alb[i]=="0":
        alb[i]="1"
    else: 
        alb[i]="0"
ai="".join(alb)
print(int(ai,2),end=" ")

for i in range(2**n-1-len(l)):
    if alb[0]=="0":
        alb[0]="1"
    else: 
        alb[0]="0"
    ai="".join(alb)
    print(int(ai,2),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])]
    X = A^B
    count = 0
    for i in range(N + 1):
        count += (X >> i) & 0x01
    if count != 1:
        print "NO"
        return

    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

    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:
from math import log


N, A, B = [int(elem) for elem in input().split()]
diff_bit = int(log(A ^ B, 2)) + 1

# probably if A and B differ in more than one bit it's impossible.
def num_ups(num):
    res = 0
    while num:
        res += 1
        num -= num & -num
    return res



def gray_code(num_bits, diff_bit):
    if num_bits == 0:
        return [0]
    prev_gray_code = gray_code(num_bits - 1, diff_bit)
    if num_bits != diff_bit:
        return prev_gray_code + \
            [bits_without_msb | 1 << num_bits - 1 for bits_without_msb in reversed(prev_gray_code)]
    else:
        mask = (1 << num_bits - 1) - 1
        common_bits = A & mask
        # print(num_bits, common_bits)
        split_idx = prev_gray_code.index(common_bits)
        result = []
        result.extend(bits | 1 << num_bits - 1 for bits in reversed(prev_gray_code[:split_idx]))
        result.extend(prev_gray_code[:split_idx + 1])
        result.append(prev_gray_code[split_idx] | 1 << num_bits - 1)
        result.extend(bits | 1 << num_bits - 1 for bits in prev_gray_code[split_idx + 1:])
        result.extend(reversed(prev_gray_code[split_idx + 1:]))
        return result


def is_gray_code(perm):
    for i in range(len(perm) - 1):
        num1, num2 = perm[i], perm[i + 1]
        if num_ups(num1 ^ num2) != 1:
            return False
    return True


if num_ups(A ^ B) > 1:
    print("NO")
    exit(0)

# print(diff_bit)
perm = gray_code(N, diff_bit)
print("YES")
if A < B:
    split_idx = perm.index(B)
    perm = perm[split_idx:] + perm[:split_idx]
    print(*perm[::-1])
else:
    split_idx = perm.index(A)
    perm = perm[split_idx:] + perm[:split_idx]
    print(*perm)

Submission status: Wrong Answer

Solution code:
import sys
n, a, b = map(int, input().split())
def pop_count(x):
	res = 0
	for i in range(17):
		res += ((x>>i)%2 == 1)
	return res
if (pop_count(a) - pop_count(b)) % 2 == 0:
	print("NO")
else:
	#print("YES")
	used = [False] * (2**n)
	used[a] = True
	used[b] = True
	if pop_count(a) < pop_count(b):
		x, y = a, b
	else:
		x, y = b, a
	left = [x]
	while left[-1] != 0:
		for i in range(n):
			if (left[-1] >> i) % 2 == 1:
				left.append(left[-1] - 2**i)
				used[left[-1]] = True
				break
	right = [y]
	while right[-1] != 2**n - 1:
		for i in range(n):
			if (right[-1] >> i) % 2 == 0:
				right.append(right[-1] + 2**i)
				used[right[-1]] = True
				break
	right = right[::-1]
	#print(left, right)
	used[2**n-1] = False
	while left[-1] != 2**n - 1:
		for i in range(n):
			if (left[-1] >> i) % 2 == 1:
				if used[left[-1] - 2**i] == False:
					left.append(left[-1] - 2**i)
					used[left[-1]] = True
					break
		else:
			for i in range(n):
				if (left[-1] >> i) % 2 == 0:
					if used[left[-1] + 2**i] == False:
						left.append(left[-1] + 2**i)
						used[left[-1]] = True
						break
			else:
				print("NO")
				sys.exit()
		#print(left[-1])

	print("YES")
	left += right[1:]
	if x == b:
		left = left[::-1]
	print(*left)

Submission status: Wrong Answer

Solution code:
N, A, B = [int(_) for _ in input().split()]
if bin(A ^ B).count('1') != 1:
    print('NO')
    exit()
ans = [A]
for X in range(N):
    if (A ^ B) >> X == 1:
        break
for i in range(1, 2**N):
    for Y in range(N):
        if i >> Y & 1:
            break
    A ^= 2**((X + Y + 1) % N)
    ans += [A]
print('YES')
print(*ans)

Submission status: Wrong Answer

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

di = None
for i in range(N):
    if A&(1<<i) != B&(1<<i):
        if di is not None:
            print('NO')
            exit()
        else:
            di = i
print('YES')
b_order = {}
k = 1
for i in range(N):
    if i==di: continue
    b_order[k] = 2**i
    k *= 2
b_order[2**(N-1)] = 2**di

order = [0]
for i in range(1,2**N):
    order.append(order[-1] ^ b_order[i&-i])

ai = order.index(A)
bi = order.index(B)

if abs(ai-bi) == 2**N-1:
    if ai==0:
        print(*order)
    else:
        print(*order[::-1])
else:
    if ai < bi:
        order.reverse()
        ai = 2**N-1 - ai
        bi = 2**N-1 - bi
    print(*(order[ai:] + order[:bi+1]))

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
def pop_count(x):
	res = 0
	for i in range(17):
		res += ((x>>i)%2 == 1)
	return res
if (pop_count(a) - pop_count(b)) % 2 == 0:
	print("NO")
else:
	print("YES")
	used = [False] * (2**n)
	used[a] = True
	used[b] = True
	if pop_count(a) < pop_count(b):
		x, y = a, b
	else:
		x, y = b, a
	left = [x]
	while left[-1] != 0:
		for i in range(n):
			if (left[-1] >> i) % 2 == 1:
				left.append(left[-1] - 2**i)
				used[left[-1]] = True
				break
	right = [y]
	while right[-1] != 2**n - 1:
		for i in range(n):
			if (right[-1] >> i) % 2 == 0:
				right.append(right[-1] + 2**i)
				used[right[-1]] = True
				break
	right = right[::-1]
	#print(left, right)
	used[2**n-1] = False
	while left[-1] != 2**n - 1:
		for i in range(n):
			if (left[-1] >> i) % 2 == 1:
				if used[left[-1] - 2**i] == False:
					left.append(left[-1] - 2**i)
					used[left[-1]] = True
					break
		else:
			for i in range(n):
				if (left[-1] >> i) % 2 == 0:
					if used[left[-1] + 2**i] == False:
						left.append(left[-1] + 2**i)
						used[left[-1]] = True
						break
		#print(left[-1])

	left += right[1:]
	if x == b:
		left == left[::-1]
	print(*left)

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)

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:
n,a,b=[int(x) for x in input().split()]
bina=str(bin(a))[2:]
binb=str(bin(b))[2:]
keta=max(len(bina),len(binb))
bina="0"*(keta-len(bina))+bina
binb="0"*(keta-len(binb))+binb
dp=[0]*(keta+1)
p=[""]*(keta)
for i in range(keta):
    for j in range(keta):
        if j<=i:
            p[j]=p[j]+bina[i]
        else:
            p[j]=p[j]+binb[i]
    if bina[i]==binb[i]:
        dp[i+1]=dp[i]
    else:
        dp[i+1]=dp[i]+1
if ((2**n-1)-dp[-1])%2==1:
    print("No")
else:
    print("Yes")
    def mult_and_add(bit_list):
        output = 0
        for bit in bit_list:
            output = output * 2 + int(bit)
        return output
    diff=[]
    if p[-1][-1]=="0":
        diff=[p[-1][:-1]+"1",p[-1]]
    else:
        diff=[p[-1][:-1]+"0",p[-1]]
    while len(p)!=2**n:
        p=p+diff
    print(" ".join([str(mult_and_add(list(x))) for x in p]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

N, A, B = [int(i) for i in input().split(" ")]




def whetherConnect(i,j):
    score=0
    for i in bin(i^j)[2::]:
        score+=int(i)
    return score==1

history=[A]
visitedFlag=[0 for i in range(2**N)]
visitedFlag[A]=1


for visitedCount in range(1,2**N):
    for i,flag in enumerate(visitedFlag):
        if flag==1:
            continue
        if i==B:
            if visitedCount==2**N-1:
                history.append(B)
                print("YES")
                print(" ".join([str(i) for i in history]))
                sys.exit()
        if whetherConnect(history[-1],i):
            history.append(i)
            visitedFlag[i]=1
            break

print("NO")

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
ab=format(a,"b").zfill(n)
bb=format(b,"b").zfill(n)
alb=list(ab)
blb=list(bb)
cnt=0
l=[]
for i in range(n):
    if alb[i]!=blb[i]:
        l.append(i)
        cnt+=1
if cnt%2==0 or cnt>2**n-1:
    print("NO")
    exit (0)
    print("YES")
print(a,end=" ")
for i in l:
    if alb[i]=="0":
        alb[i]="1"
    else: 
        alb[i]="0"
ai="".join(alb)
print(int(ai,2),end=" ")

for i in range(2**n-1-len(l)):
    if alb[0]=="0":
        alb[0]="1"
    else: 
        alb[0]="0"
    ai="".join(alb)
    print(int(ai,2),end=" ")

Submission status: Wrong Answer

Solution code:
N, A, B = [int(_) for _ in input().split()]
if bin(A ^ B).count('1') != 1:
    print('NO')
    exit()
ans = [A]
for X in range(N):
    if A ^ B >> X == 1:
        break
for i in range(1, 2**N):
    for Y in range(N):
        if i >> Y & 1:
            break
    A ^= 2**((X + Y + 1) % N)
    ans += [A]
print('YES')
print(*ans)

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 s_permutations(seq):
    items = [[]]
    for j in seq:
        new_items = []
        for i, item in enumerate(items):
            if i % 2:
                new_items.extend(item[:i] + [j] + item[i:] for i in range(len(item) + 1))
            else:
                new_items.extend(item[:i] + [j] + item[i:] for i in reversed(range(len(item) + 1)))
        items = new_items

    return items


def main():
    n, a, b = map(int, input().split())

    for item in s_permutations(range(1 << n)):
        if item[0] == a and item[-1] == b:
            print('YES')
            print(*item)
            return
    print('NO')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, A, B = map(int,input().split())
A_bi = [1] * (N)
B_bi = [1] * (N)

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


no_flag = 0
for i in range(N):
    A_bi[i] = int((A%(2**(i+1)))/(2**(i)))
    B_bi[i] = int((B%(2**(i+1)))/(2**(i)))
    if A_bi[i] != B_bi[i]:
        no_flag += 1
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 A_bi == B_bi:
                flag = 1
        else:
            A_bi[0] = (A_bi[0]+1)%2
    
    print()

Submission status: Wrong Answer

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

AB = A ^ B
lastbit = 0
bitcount = 0
for b in range(N):
    if AB & (1 << b) != 0:
        lastbit = b
        bitcount += 1

if bitcount != 1:
    print "NO"
else:
    print "YES"
    bit = [b for b in range(N) if b != lastbit]
    bit.append(lastbit)

    ret = []
    for i in range(1 << N):
        v = A
        t = i ^ (i << 1)
        for b in range(N):
            if t & (2 << b) != 0:
                v ^= 1 << bit[b]
        ret.append(str(v))

    print " ".join(ret)

Submission status: Wrong Answer

Solution code:
from sys import exit, setrecursionlimit, stderr, stdin
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

setrecursionlimit(10**7)

M = 10 ** 9 + 7

def input():
  return stdin.readline().strip()

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

def bitcount(a, N):
  return sum((a & (1 << i)) > 0 for i in range(N))

def topbit(a, N):
  return next(i for i in range(N-1, -1, -1) if (a & (1 << i)) > 0)

def swap(x, i, j):
  y = x & ~(1 << i) & ~(1 << j)
  if (x & (1 << i)) > 0:
    y |= 1 << j
  if (x & (1 << j)) > 0:
    y |= 1 << i
  return y

def solve(N, A, B):
  if N == 1:
    ans = [A & 1, B & 1]
    return ans
  C = A ^ B
  t = topbit(C, N)
  AA = swap(A, t, N-1)
  BB = swap(B, t, N-1)
  D = AA ^ 1
  ans = []
  ans.extend(swap(x, t, N-1) for x in solve(N-1, AA, D))
  ans.extend(swap(x, t, N-1) | (1 << t) for x in solve(N-1, D, BB))
  return ans

N, A, B = reads()
if bitcount(A ^ B, N) % 2 == 0:
  print("NO"); exit()
print("YES")
print(*solve(N, A, B))

Submission status: Wrong Answer

Solution code:
from sys import exit, setrecursionlimit, stderr, stdin
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

setrecursionlimit(10**7)

M = 10 ** 9 + 7

def input():
  return stdin.readline().strip()

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

def bitcount(a, N):
  return sum((a & (1 << i)) > 0 for i in range(N))

def topbit(a, N):
  return next(i for i in range(N-1, -1, -1) if (a & (1 << i)) > 0)

def swap(x, i, j):
  y = x & ~(1 << i) & ~(1 << j)
  if (x & (1 << i)) > 0:
    y |= 1 << j
  if (x & (1 << j)) > 0:
    y |= 1 << i
  return y

def solve(N, A, B):
  if N == 1:
    ans = [A & 1, B & 1]
    return ans
  C = A ^ B
  t = topbit(C, N)
  AA = swap(A, t, N-1)
  BB = swap(B, t, N-1)
  D = AA ^ 1
  ans = []
  ans.extend(swap(x, t, N-1) for x in solve(N-1, AA, D))
  ans.extend(swap(x, t, N-1) | (1 << t) for x in solve(N-1, D, BB))
  return ans

N, A, B = reads()
if bitcount(A ^ B, N) % 2 == 0:
  print("NO"); exit()
print(*solve(N, A, B))

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 = 0
        for i in po2[:-1]:
            y = x^i
            if f[y] > m:
                m = f[y]
                k = y
        ans.append(k)
        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:
#!/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 s_permutations(seq):
    items = [[]]
    for j in seq:
        new_items = []
        for i, item in enumerate(items):
            if i % 2:
                # step up
                new_items += [item[:i] + [j] + item[i:] for i in range(len(item) + 1)]
            else:
                # step down
                new_items += [item[:i] + [j] + item[i:] for i in range(len(item), -1, -1)]
        items = new_items

    return items


def main():
    n, a, b = map(int, input().split())

    k = a ^ b
    if k & (k - 1) == 0:
        for item in s_permutations(range(1 << n)):
            if item[0] == a and item[-1] == b:
                print('YES')
                print(*item)
                return
        print('NO')
    else:
        print('NO')


if __name__ == '__main__':
    main()

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]
print(*ans)

Submission status: Wrong Answer

Solution code:
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

INF = 1<<29

DIV = 10**9+7

def make2d_arr(w,h,val =INF):
    return [[val]*w for i in xrange(h)]

def floyd_warshall(costs):
    N = len(costs)
    for k in xrange(N):
        for i in xrange(N):
            for j in xrange(N):
                costs[i][j]  = min(costs[i][j],costs[i][k]+costs[k][j])
    return costs

N,A,B = ints_raw()

DIF_B = []
A2s = []
B2s = []
num_db =0

for i in xrange(N):
    a2 = (A>>i)%2
    b2 = (B>>i)%2
    A2s.append(a2)
    B2s.append(b2)
    if a2 == b2:
        DIF_B.append(0)    
    else:
        DIF_B.append(1)
        num_db+=1
    
numP = (2**N)-1
if (num_db > numP) or (num_db%2 ==0):
    print "NO"
else:
    print "YES"
    print A,
    for i in xrange(0,numP-num_db,2):
        print A+(-1 if A2s[0]==1 else 1),
        print A,
    PI = A
    for i in xrange(N):
        if DIF_B[i]==1:
            PI += (-1 if A2s[i]==1 else 1)*(1<<i)
            print PI,

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")
print(*ans)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
a_str = bin(A)[2:]
b_str = bin(B)[2:]
a_bin = int(a_str)
b_bin = int(b_str)
a = [0] * (N+1)
b = [0] * (N+1)
c = [A] + [0]*(2**N-2) + [B]
# for i in range(len(a_str),2,-1):
# 	a.append(int(a_str[i-1]))
# for i in range(len(b_str),2,-1):
# 	b.append(int(b_str[i-1]))
cnta = 0
cntb = 0
while (a_bin):
	a[cnta] = a_bin%10
	a_bin = a_bin//10
	cnta += 1
while (b_bin):
	b[cntb] = b_bin%10
	b_bin = b_bin//10
	cntb += 1

# print(cnta,cntb)
d = A^B
h = 0
while(d):
	d &= d-1
	h += 1
# print(h)

if (2**N-h)%2 == 0 or h > 2**N-2:
	print('NO', end='')
	exit()
else:
	print('YES')
	j = 1
	C = A
	for i in range(max(cnta, cntb)):
		if a[i] != b[i]:
			if a[i] == 1:
				C -= 2**i
				c[j] = C
			else:
				C += 2**i
				c[j] = C
			j += 1
	for i in range(j,2**N-1,2):
		c[j],c[j+1] = c[j-2],c[j-1]
	for i in range(2**N):
		print(c[i], end=' ')

Submission status: Wrong Answer

Solution code:
def walk(a, b, rest_bit):
    ret = []
    if rest_bit == 0:
        return [a,b]

    change_bit = 0
    for i in range(19,-1,-1):
        if (rest_bit & (1 << i)) != 0:
            change_bit = 1 << i
            break
    rest_bit &= ~change_bit
    ret += walk(a, a ^ change_bit, rest_bit)
    ret += walk(b ^ change_bit, b, rest_bit)
    return ret

def solve():
    N,A,B=map(int,input().split())
    change_bit = (A ^ B)
    if bin(change_bit).count('1') != 1:
        print('NO')
        return
    rest_bit = (1<<N)-1
    rest_bit &= ~change_bit
    print('YES')
    print(' '.join(map(str,walk(A,B,rest_bit))))

solve()

Submission status: Wrong Answer

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

A = []
for i in range(1 << n):
    A.append(i ^ (i >> 1))

index = A.index(a)
if A[index - 1] == b:
    ans = A[index:] + A[:index]
    print('YES')
    print(*ans)
elif A[(index + 1) % 2 ** n] == b:
    A.reverse()
    index = A.index(a)
    ans = A[index:] + A[:index]
    print('YES')
    print(*ans)

else:        
    print('NO')

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
if (a-b)%2==0:
  print('NO')
else:
  print('YES')

Submission status: Wrong Answer

Solution code:
print('NO')

Submission status: Wrong Answer

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

AB = A ^ B
lastbit = 0
bitcount = 0
for b in range(N):
    if AB & (1 << b):
        lastbit = b
        bitcount += 1

if bitcount != 1:
    print "NO"
else:
    print "YES"
    bit = [b for b in range(N) if b != lastbit]
    bit.append(lastbit)

    ret = []
    for i in range(1 << N):
        v = A
        t = i ^ (i >> 1)
        for b in range(N):
            if t & (1 << b):
                v ^= 1 << bit[b]
        ret.append(str(v))

    print " ".join(ret)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
if (a-b)%2==0:
  print('NO')
print('YES')

Submission status: Wrong Answer

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

order = [0]
for i in range(1,2**N):
    order.append(order[-1] ^ (i&-i))

ai = order.index(A)
bi = order.index(B)

if(abs(ai-bi) > 1) and abs(ai-bi) != 2**N-1:
    print('NO')
    exit()

print('YES')
if abs(ai-bi) == 2**N-1:
    if ai==0:
        print(*order)
    else:
        print(*order[::-1])
else:
    if ai < bi:
        order.reverse()
        ai = 2**N-1 - ai
        bi = 2**N-1 - bi
    print(*(order[ai:] + order[:bi+1]))

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
a_str = bin(A)[2:]
b_str = bin(B)[2:]
a_bin = int(a_str)
b_bin = int(b_str)
a = [0] * (N+1)
b = [0] * (N+1)
c = [A] + [0]*(2**N-2) + [B]
# for i in range(len(a_str),2,-1):
# 	a.append(int(a_str[i-1]))
# for i in range(len(b_str),2,-1):
# 	b.append(int(b_str[i-1]))
cnta = 0
cntb = 0
while (a_bin):
	a[cnta] = a_bin%10
	a_bin = a_bin//10
	cnta += 1
while (b_bin):
	b[cntb] = b_bin%10
	b_bin = b_bin//10
	cntb += 1

# print(cnta,cntb)
d = A^B
h = 0
while(d):
	d &= d-1
	h += 1
# print(h)

if (2**N-h)%2 == 0 or h > 2**N-2:
	print('NO')
	exit()
else:
	print('YES')
	j = 1
	C = A
	for i in range(max(cnta, cntb)):
		if a[i] != b[i]:
			if a[i] == 1:
				C -= 2**i
				c[j] = C
			else:
				C += 2**i
				c[j] = C
			j += 1
	for i in range(j,2**N-1,2):
		c[j],c[j+1] = c[j-2],c[j-1]
	for i in range(2**N):
		print(c[i], end=' ')

Submission status: Wrong Answer

Solution code:
N,A,B =[int(i)for i in input().split()]
st = format(A^B,"b")
st = [i for i in st]
num = st.count("1")
ans = [A]
if num%2==0:
    print("NO")
else:
    print("YES")
    n = len(st)
    for i,j in enumerate(st):
        if j =="1":
            foo = ans[-1]^(1<<(n-i-1))
            ans.append(foo)
    foo = ans[-1]^1
    ans = [str(i)for i in ans]
    num = (2**N -1-num)//2
    print(" ".join(ans+[str(foo),str(ans[-1])]*num))

Submission status: Wrong Answer

Solution code:

# coding: utf-8

# In[1]:


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


# In[2]:


l = [i^(i>>1) for i in range(2**N)]
["{:0>3b}".format(x) for x in l]


# In[3]:


X = l[0]^A
X


# In[6]:


if l[2**N-1]^X == B:
    print("YES")
    ans = [str(x^X) for x in l]
    print(" ".join(ans))
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N,A,B =[int(i)for i in input().split()]
st = format(A^B,"b")
st = [i for i in st]
num = st.count("1")
ans = [A]
if num%2==0:
    print("NO")
else:
    n = len(st)
    for i,j in enumerate(st):
        if j =="1":
            foo = ans[-1]^(1<<(n-i-1))
            ans.append(foo)
    foo = ans[-1]^1
    ans = [str(i)for i in ans]
    num = (2**N -1-num)//2
    print(" ".join(ans+[str(foo),str(ans[-1])]*num))

Submission status: Wrong Answer

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

res = None
if N == 1:
	res = [
		None,
		[0b0, 0b1]
	][G]
elif N == 2:
	res = [
		None,
		[0b00, 0b10, 0b11, 0b01],
		[0b00, 0b01, 0b11, 0b10],
		None
	][G]

if res:
	print('YES')
	print(' '.join(str(A ^ r) for r in res))
else:
	print('NO')

Submission status: Wrong Answer

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

order = [0]
for i in range(1,2**N):
    order.append(order[-1] ^ (i&-i))

ai = order.index(A)
bi = order.index(B)

if(abs(ai-bi) > 1) and abs(ai-bi) != 2**N-1:
    print('NO')
    exit()

print('YES')
if abs(ai-bi) == 2**N-1:
    if ai==0:
        print(*order)
    else:
        print(*order[::-1])
else:
    if ai < bi:
        order.reverse()
        ai,bi = bi,ai
    print(*(order[ai:] + order[:bi+1]))

Submission status: Wrong Answer

Solution code:
N,A,B = map(int,input().split())
AA = A
BB = B
biA = ""
biB = ""
count = 0
out = str(A)

for i in range(17):
	biA = str(AA%2)+biA
	biB = str(BB%2)+biB
	AA = int((AA - (AA%2))/2)
	BB = int((BB - (BB%2))/2)
	if biA[0] != biB[0]:
		count = count + 1

if count%2 == 0:
	print("NO")
else:
	print("YES")
	for i in range(count):
		for j in range(17):
			if biA[j] != biB[j]:
				biA = biA[:j]+biB[j]+biA[j+1:]
				num = 0
				for k in range(17):
					num = num + int(biA[16-k])*(2**k)
				out = out + " " + str(num)
	if B%2 == 0:
		for i in range(2**N - 1 - count):
			if i % 2 == 0:
				out = out + " " + str(B+1)
			else:
				out = out + " " + str(B)
	else:
		for i in range(2**N - 1 - count):
			if i%2 == 0:
				out = out + " " + str(B-1)
			else:
				out = out + " " + str(B)
	print(out)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
Abit = list(format(A, "b").zfill(16))
Bbit = list(format(B, "b").zfill(16))
change = 0

def ten(C):
    out = 0
    for i in range(16):
        if int(C[-1-i]) == 1:
            out += 2 ** i
    return out

for i in range(16):
    if Abit[i] != Bbit[i]:
        change += 1

Left = 2 ** N - 1 - change

if Left < 0 or Left % 2 == 1: print("NO")
else:
    Ans = str(A)+" "
    for i in range(16):
        if Abit[i] != Bbit[i]:
            Abit[i] = Bbit[i]
            Ans += str(ten(Abit))+ " "
    Bbit[-1] = ("0" if Bbit[-1] == "1" else "1")
    flip = str(ten(Bbit))
    for i in range(Left//2):
        Ans += flip + " " + str(B) + " "
    print("YES")
    print(Ans)

Submission status: Wrong Answer

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