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>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
template <typename T>
inline T Abs(T x) {
  return (x >= 0) ? x : -x;
}
template <typename T>
inline T sqr(T x) {
  return x * x;
}
template <typename T>
string toStr(T x) {
  stringstream st;
  st << x;
  string s;
  st >> s;
  return s;
}
inline int nextInt() {
  int x;
  if (scanf("%d", &x) != 1) throw;
  return x;
}
inline long long nextInt64() {
  long long x;
  if (scanf("%I64d", &x) != 1) throw;
  return x;
}
inline double nextDouble() {
  double x;
  if (scanf("%lf", &x) != 1) throw;
  return x;
}
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int MAXN = 1001000;
int n, a[MAXN];
long long ans = 0;
void build(int n, int* a) {
  if (n == 0) return;
  int p = 1;
  while (2 * p <= n) p *= 2;
  for (int i = 0; i < (int)(p); i++) a[i] = (p - 1) ^ i;
  build(n - p, a + p);
  for (int i = p; i < n; i++) a[i] += p;
  for (int i = p; i < n; i++) swap(a[i], a[i % p]);
}
int main() {
  n = nextInt() + 1;
  build(n, a);
  long long sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    ans += a[i] ^ i;
    sum += 2 * i;
  }
  cerr << sum << endl;
  cerr << ans << endl;
  cout << ans << endl;
  for (int i = 0; i < (int)(n); i++) printf("%d ", a[i]);
  return 0;
}
