CF288C.Polo the Penguin and XOR operation
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to n , inclusive.
For permutation p=p0,p1,...,pn , Polo has defined its beauty — number .
Expression means applying the operation of bitwise excluding "OR" to numbers x and y . This operation exists in all modern programming languages, for example, in language C++ and Java it is represented as "^" and in Pascal — as "xor".
Help him find among all permutations of integers from 0 to n the permutation with the maximum beauty.
输入格式
The single line contains a positive integer n ( 1<=n<=106 ).
输出格式
In the first line print integer m the maximum possible beauty. In the second line print any permutation of integers from 0 to n with the beauty equal to m .
If there are several suitable permutations, you are allowed to print any of them.
输入输出样例
输入#1
4
输出#1
20 0 2 1 4 3