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 <image>.

Expression <image> 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.

Input

The single line contains a positive integer n (1 ≤ n ≤ 106).

Output

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.

Examples

Input

4


Output

20
0 2 1 4 3
import java.io.*;
import java.util.StringTokenizer;

public class ProblemC {

    public static void main(String[] args) throws Exception {
        new ProblemC();
    }

    private BufferedReader in = null;
    private PrintWriter out = null;
    private StringTokenizer tok = new StringTokenizer("");

    public ProblemC() throws Exception {
        init();
        solve();
        in.close();
        out.close();
    }

    private void solve() throws Exception {
        int n = nextInt();
        int[] a = new int[n + 1];
        boolean[] was = new boolean[n + 1];
        int log = -1;
        int tmp = n;
        while (tmp > 0) {
            ++log;
            tmp >>= 1;
        }
        int ones = 0;
        for (int i = log + 1; i < 32; ++i) {
            ones |= 1 << i;
        }

        for (int i = n; i >= 0; --i) {
            if (was[i]) {
                if (i == (1 << log)) {
                    ones |= 1 << log;
                    log--;
                }
                continue;
            }
            was[i] = true;
            a[i] = not(i) ^ ones;
            was[a[i]] = true;
            a[a[i]] = i;
//            System.out.println(Integer.toBinaryString(ones) + " " + log + " " + Integer.toBinaryString(i) + " " + Integer.toBinaryString(a[i]));
            if (i == (1 << log)) {
                ones |= 1 << log;
                log--;
            }
        }
        long ans = 0;
        for (int i = 0; i <= n; ++i) {
            ans += i ^ a[i];
        }
        out.println(ans);
        for (int i = 0; i <= n; ++i) {
            out.print(a[i] + " ");
        }
    }

    private int not(int a) {
        return -a - 1;
    }


    private void init() throws FileNotFoundException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }


    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }


    private String nextToken() throws IOException {
        while (!tok.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null) {
                return null;
            }
            tok = new StringTokenizer(s);
        }
        return tok.nextToken();
    }

}
            