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;
template <class T>
inline T BM(T p, T e, T M) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T mul(T p, T e, T M) {
  long long int ret = 0;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret + p);
    p = (p + p);
    if (ret >= M) ret -= M;
    if (p >= M) p -= M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T mdINV(T a, T M) {
  return BM(a, M - 2, M);
}
template <class T>
inline T PW(T p, T e) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
template <class T>
bool ISLEFT(T a, T b, T c) {
  if (((a.first.first - b.first.first) * (b.second.second - c.second.second) -
       (b.first.first - c.first.first) * (a.second.second - b.second.second)) <
      0.0)
    return 1;
  else
    return 0;
}
int n;
int ans[23];
int ar[2000004 + 2];
int main() {
  for (int i = 0; i <= 20; i++) {
    ans[i + 1] = (1 << i) - 1;
  }
  scanf("%d", &n);
  int first = n;
  while (n >= 0) {
    int in = lower_bound(ans + 1, ans + 21 + 1, n) - ans;
    int nu = ans[in];
    int baki = nu - n;
    for (int j = baki; j <= n; j++) {
      ar[j] = nu - j;
    }
    n = baki - 1;
  }
  long long int res = 0;
  for (int i = 0; i <= first; i++) {
    res += (long long int)(i ^ ar[i]);
  }
  printf("%lld\n", res);
  for (int i = 0; i <= first; i++) {
    if (i > 0) printf(" ");
    printf("%d", ar[i]);
  }
  return 0;
}
