Given an integer N, find two permutations:  Permutation p of numbers from 1 to N such that p_{i} ≠ i and p_{i} & i = 0 for all i = 1, 2, ..., N.  Permutation q of numbers from 1 to N such that q_{i} ≠ i and q_{i} & i ≠ 0 for all i = 1, 2, ..., N. 

& is the bitwise AND operation.


-----Input-----

The input consists of one line containing a single integer N (1 ≤ N ≤ 10^5).


-----Output-----

For each subtask, if the required permutation doesn't exist, output a single line containing the word "NO"; otherwise output the word "YES" in the first line and N elements of the permutation, separated by spaces, in the second line. If there are several possible permutations in a subtask, output any of them.


-----Examples-----
Input
3

Output
NO
NO

Input
6

Output
YES
6 5 4 3 2 1 
YES
3 6 2 5 1 4

Difficulty: VERY_HARD
Tags: Constructive algorithms

Starter code:

Solutions:
def test(x, i):
	i = list(i)
	ok = True
	for j in range(x):
		if i[j] == j + 1 or i[j] & j + 1 != 0:
			ok = False
	if ok:
		print(i)

def comp(n):
	return 2 ** len(bin(n)[2:]) - 1 - n
n = int(input())
nn = n
if n % 2 == 0:
	x = []
	while n != 0:
		for i in range(comp(n), n + 1):
			x.append(i)
		n = comp(n) - 1
	x.reverse()
	print('YES')
	print(' '.join([str(i) for i in x]))
else:
	print('NO')
pow2 = [2 ** i for i in range(20)]

def make(n):
	if n <= 5:
		return []
	if n == 6:
		return [3, 6, 1, 5, 4, 2]
	if n == 7:
		return [3, 6, 1, 5, 4, 7, 2]
	if n in pow2:
		return []
	shift = 2 ** (len(bin(n)[2:]) - 1)
	array = [i for i in range(shift, n + 1)]
	array = array[1:] + [array[0]]
	return make(shift - 1) + array
n = nn
k = make(n)
if k == []:
	print('NO')
else:
	print('YES')
	print(' '.join([str(i) for i in k]))


from math import log
n = int(input())
a = [i for i in range(n + 1)]

def ans(n):
	if n <= 0 or n % 2:
		return
	(j, cr) = (1 << int(log(n, 2)), 1)
	while j + cr - 1 <= n:
		(a[j - cr], a[j + cr - 1]) = (a[j + cr - 1], a[j - cr])
		cr += 1
	ans(j - cr)
if n % 2 == 0:
	ans(n)
	print('YES')
	print(*a[1:])
else:
	print('NO')
if n <= 5 or 1 << int(log(n, 2)) == n:
	print('NO')
	return
print('YES')
print('3 6 1 5 4 2' if n <= 6 else '3 6 1 5 4 7 2', end=' ')
cr = 8
v = 1 << int(log(n, 2))
for i in range(8, n + 1):
	if i >= v:
		print(n if i == v else i - 1, end=' ')
		continue
	if i == cr:
		cr *= 2
		print(cr - 1, end=' ')
	else:
		print(i - 1, end=' ')


from math import log2, floor
n = int(input())
if n % 2:
	print('NO')
else:
	print('YES')
	k = floor(log2(n)) + 1
	res = [0 for i in range(n)]
	occupied = [0 for i in range(n)]
	switch = 0
	for i in range(n, 0, -1):
		val = 2 ** k - 1 - i
		if val > n:
			k -= 1
			val = 2 ** k - 1 - i
		if occupied[val - 1]:
			while occupied[val - 1]:
				k -= 1
				val = 2 ** k - 1 - i
		val = 2 ** k - 1 - i
		occupied[val - 1] = 1
		res[i - 1] = val
	for i in res:
		print(i, end=' ')
	print()
if n in [1, 2, 3, 4, 5]:
	print('NO')
elif int(log2(n)) == log2(n):
	print('NO')
elif n == 6:
	print('YES')
	print('3 6 2 5 1 4')
else:
	print('YES')
	print('7 3 2 5 6 4 1', end=' ')
	for i in range(8, n):
		p = pow(2, floor(log2(i)) + 1)
		if i < pow(2, floor(log2(n))):
			print(p * 3 // 2 - 1 - i, end=' ')
		else:
			print(i + 1, end=' ')
	if n > 7:
		print(pow(2, floor(log2(n))))


from math import log2
n = int(input())
p = [0] * (n + 1)

def f(n):
	k = int(log2(n))
	while k:
		i = 1
		while (1 << k) + i - 1 <= n:
			p[(1 << k) + i - 1] = (1 << k) - i
			p[(1 << k) - i] = (1 << k) + i - 1
			i += 1
		n = (1 << k) - i
		if not n:
			break
		k = int(log2(n))
if n & 1:
	print('NO')
else:
	print('YES')
	f(n)
	print(*p[1:])
if n < 6 or 1 << int(log2(n)) == n:
	print('NO')
else:
	print('YES')
	if n == 6:
		print('3 6 2 5 1 4')
	elif n == 7:
		print('7 3 6 5 1 2 4')
	else:
		print('7 3 6 5 1 2 4', end=' ')
		k = 3
		while 1 << k < n:
			for i in range((1 << k) + 1, min(1 << k + 1, n + 1)):
				print(i, end=' ')
			print(1 << k, end=' ')
			k += 1