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 00 to nn , inclusive.

For permutation p=p0,p1,...,pnp=p_{0},p_{1},...,p_{n} , Polo has defined its beauty — number .

Expression means applying the operation of bitwise excluding "OR" to numbers xx and yy . 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 00 to nn the permutation with the maximum beauty.

输入格式

The single line contains a positive integer nn ( 1<=n<=1061<=n<=10^{6} ).

输出格式

In the first line print integer mm the maximum possible beauty. In the second line print any permutation of integers from 00 to nn with the beauty equal to mm .

If there are several suitable permutations, you are allowed to print any of them.

输入输出样例

  • 输入#1

    4
    

    输出#1

    20
    0 2 1 4 3
    
首页