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;
const int oo = 1 << 30;
const double PI = M_PI;
const double EPS = 1e-15;
const int MaxN = 1000005;
int N;
int values[4 * MaxN];
int P[MaxN];
int zero(int x) { return 2 * x + 1; }
int one(int x) { return 2 * x + 2; }
void update(int node, int x, int deep, int val) {
  if (deep == -1) {
    values[node] += val;
    return;
  }
  if (x & (1 << deep))
    update(one(node), x, deep - 1, val);
  else
    update(zero(node), x, deep - 1, val);
  values[node] = values[one(node)] + values[zero(node)];
}
int pick(int node, int x, int deep, int current) {
  if (deep == -1) return current;
  if (x & (1 << deep)) {
    if (values[zero(node)])
      return pick(zero(node), x, deep - 1, current);
    else
      return pick(one(node), x, deep - 1, current | (1 << deep));
  } else {
    if (values[one(node)])
      return pick(one(node), x, deep - 1, current | (1 << deep));
    else
      return pick(zero(node), x, deep - 1, current);
  }
}
int main() {
  cin.sync_with_stdio(false);
  cin >> N;
  N = N + 1;
  for (int i = 0; i < N; i++) update(0, i, 19, +1);
  long long answer = 0;
  for (int i = 0; i < N; i++) {
    P[i] = pick(0, i, 19, 0);
    update(0, P[i], 19, -1);
    answer = answer + (i ^ P[i]);
  }
  cout << answer << endl;
  for (int i = 0; i < N; i++) cout << P[i] << " ";
  return 0;
}
