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.util.*;
import java.io.*;
public class Problem0288c {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int[] p = new int[n + 1];
        for (int i = n; i > 0; i--) {
            if (p[i] > i) {
                continue;
            }
            p[i] = up(i) - i;
            if (!(p[p[i]] != 0 && (i & p[i]) != 0)) {
                p[p[i]] = i;
            }
        }
        long sum = 0;
        for (int i = 0; i <= n; i++) {
            sum += i ^ p[i];
        }
        out.println(sum);
        for (int i = 0; i <= n; i++) {
            out.print(p[i] + " ");
        }
        out.println("");
        out.flush();
    }
    public static int largest_power(int n) {
        n = n | (n >> 1);
        n = n | (n >> 2);
        n = n | (n >> 4);
        n = n | (n >> 8);
        n = n | (n >> 16);
        return (n + 1) >> 1;
    }
    public static boolean check(int n, int i) {
        if ((n & (1 << i)) != 0) {
            return true;
        }
        return false;
    }
    public static int up(int n) {
        int two = largest_power(n);
        two *= 2;
        two--;
        return two;
    }
}