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;
int main() {
  int n;
  vector<int> pot;
  int cont = 2;
  while (cont < 10000000) {
    pot.push_back(cont);
    cont *= 2;
  }
  while (scanf("%d", &n) == 1) {
    bool cmp[n + 1];
    int pos[n + 1];
    memset(cmp, 0, sizeof cmp);
    memset(pos, 0, sizeof pos);
    int c = 0;
    for (int i = int(0); i < int(pot.size()); i++) {
      if (n < pot[i])
        break;
      else
        c++;
    }
    int des = c + 1;
    vector<int> save;
    for (int i = int(n); i >= int(0); i--) {
      int val = (~i) & ((1 << des) - 1);
      if (val <= n) {
        pos[i] = val;
        cmp[val] = true;
      } else {
        save.push_back(i);
      }
    }
    vector<int> save1;
    int cmp1[1000009];
    memset(cmp1, 0, sizeof cmp1);
    while (des > 0 && save.size() > 0) {
      save1.clear();
      des--;
      for (int i = int(0); i < int(save.size()); i++) {
        int val = (~save[i]) & ((1 << des) - 1);
        if (val <= n && cmp[val] == false) {
          pos[save[i]] = val;
          cmp[val] = true;
        } else
          save1.push_back(save[i]);
      }
      save = save1;
    }
    for (int i = int(0); i < int(save.size()); i++) {
      pos[save[i]] = save[i];
    }
    long long val = 0;
    for (int i = int(0); i < int(n + 1); i++) {
      val += (pos[i] ^ i);
    }
    cout << val << endl;
    for (int i = int(0); i < int(n + 1); i++) {
      printf("%d ", pos[i]);
    }
    cout << endl;
  }
  return 0;
}
