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 md = 1e9 + 7;
const int inf = 1e9;
struct node {
  node *p[2];
  int cnt[2];
  node() {
    for (int i = 0; i < 2; i++) cnt[i] = 0, p[i] = NULL;
  }
} * tr;
const int maxn = 1 << 20;
void insert(int x) {
  node *cur = tr;
  for (int p = maxn; p >= 1; p >>= 1) {
    bool v = (x / p) & 1;
    cur->cnt[v]++;
    if (cur->p[v] == NULL) cur->p[v] = new node();
    cur = cur->p[v];
  }
}
void del(int x) {
  node *cur = tr;
  for (int p = maxn; p >= 1; p >>= 1) {
    bool v = (x / p) & 1;
    cur->cnt[v]--;
    cur = cur->p[v];
  }
}
int max_xor(int x) {
  node *cur = tr;
  int val = 0;
  for (int p = maxn; p >= 1; p >>= 1) {
    bool v = (x / p) & 1;
    v ^= 1;
    val <<= 1;
    if (cur->cnt[v]) {
      val = val | 1;
      cur = cur->p[v];
    } else
      cur = cur->p[(v ^ 1)];
  }
  return val;
}
const int N = 1000005;
int a[N];
signed main() {
  tr = new node();
  int n;
  scanf("%d", &n);
  for (int i = 0; i <= n; i++) insert(i);
  long long int ans = 0;
  for (int i = 0; i <= n; i++) {
    int val = max_xor(i);
    ans += val;
    del((val ^ i));
    a[i] = (val ^ i);
  }
  printf("%lld\n", ans);
  for (int i = 0; i <= n; i++) printf("%d ", a[i]);
  return 0;
}
