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>
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos(-1.0);
int dx[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[] = {1, 1, 0, -1, -1, -1, 0, 1};
int gcd(const long long &a, const long long &b) {
  return b == 0 ? a : gcd(b, a % b);
}
using namespace std;
const int maxn = 1e6 + 10;
int a[maxn];
int bitcnt(int n) {
  int cnt = 0;
  while (n) {
    n = n >> 1;
    cnt++;
  }
  return cnt;
}
map<long long, long long> pos;
int main() {
  memset(a, 0, sizeof(a));
  int n;
  scanf("%d", &n);
  for (int i = n; i >= 0; --i) {
    int len = bitcnt(i);
    long long maxv = (1 << len) - 1;
    if (!pos.count(i) && !pos.count(maxv ^ i)) {
      pos[i] = maxv ^ i;
      pos[maxv ^ i] = i;
    }
  }
  long long sum = 0;
  for (int i = 0; i <= n; ++i) {
    sum += pos[i] ^ i;
  }
  printf("%I64d\n", sum);
  for (int i = 0; i <= n; ++i) {
    printf((i) ? " %I64d" : "%I64d", pos[i]);
  }
  return 0;
}
