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
#include <bits/stdc++.h>
using namespace std;
struct trie {
  trie* ch[2];
  int r;
  trie() {
    ch[0] = ch[1] = NULL;
    r = 0;
  }
  void add(int x, int l) {
    r++;
    if (l == -1) {
      return;
    }
    int z = x & (1 << l);
    z = min(1, z);
    if (ch[z] == NULL) ch[z] = new trie();
    ch[z]->add(x, l - 1);
  }
  long long cal(int x, int l) {
    if (l == -1) {
      return 0;
    }
    int z = x & (1 << l);
    z = min(1, z);
    if (ch[!z] != NULL) {
      long long y = 0;
      if (!z == 1) y = 1 << l;
      return y + ch[!z]->cal(x, l - 1);
    }
    if (ch[z] == NULL) return x;
    long long y = 0;
    if (z == 1) y = 1 << l;
    return y + ch[z]->cal(x, l - 1);
  }
  void del(int x, int l) {
    r--;
    if (l == -1) return;
    int z = x & (1 << l);
    z = min(1, z);
    ch[z]->del(x, l - 1);
    if (ch[z]->r <= 0) {
      delete (ch[z]);
      ch[z] = NULL;
    }
  }
};
int res[1001000];
int main() {
  int n;
  cin >> n;
  trie root;
  for (int i = 0; i <= n; i++) {
    root.add(i, 25);
  }
  long long r = 0;
  memset(res, -1, sizeof res);
  for (int i = n; i >= 0; i--) {
    if (res[i] != -1) continue;
    long long z = root.cal(i, 25);
    if (z != i) root.del(z, 25);
    root.del(i, 25);
    r += z ^ i;
    r += z ^ i;
    res[i] = z;
    res[z] = i;
  }
  cout << r << endl;
  for (int i = 0; i <= n; i++) {
    printf("%d ", res[i]);
  }
  return 0;
}
