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 double eps = 1e-8;
const double pi = 2 * acos(0.0);
const string alphabetU = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string alphabetL = "abcdefghijklmnopqrstuvwxyz";
const long long infinite = 1000000000;
const long long maxn = 100010;
static const int m37pos[] = {32, 0, 1,  26, 2,  23, 27, 0,  3,  16, 24, 30, 28,
                             11, 0, 13, 4,  7,  17, 0,  25, 22, 31, 15, 29, 10,
                             12, 6, 0,  21, 14, 9,  5,  20, 8,  19, 18};
inline int nextInt() {
  int x = 0;
  register int c = getc(stdin);
  int sign = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getc(stdin))
    ;
  if (c == '-') {
    sign = 1;
    c = getc(stdin);
  }
  for (; c > 47 && c < 58; c = getc(stdin)) x = (x << 1) + (x << 3) + c - 48;
  if (sign) x = -x;
  return x;
}
inline long long nextLong() {
  long long x = 0;
  register int c = getc(stdin);
  int sign = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getc(stdin))
    ;
  if (c == '-') {
    sign = 1;
    c = getc(stdin);
  }
  for (; c > 47 && c < 58; c = getc(stdin)) x = (x << 1) + (x << 3) + c - 48;
  if (sign) x = -x;
  return x;
}
inline string nextLine() {
  string s;
  while (!feof(stdin)) {
    char c = fgetc(stdin);
    if (c == 13) continue;
    if (c == 10) return s;
    s += c;
  }
  return s;
}
void scan(int &x) { x = nextInt(); }
void scanl(long long &x) { x = nextLong(); }
void scans(string &s) { s = nextLine(); }
int f[1000001];
int b[22], n;
bool vs[1000001];
void input() { scan(n); }
void process() {
  memset(vs, false, sizeof(vs));
  for (int i = 1, _b = 21; i <= _b; i++) b[i] = (1 << i) - 1;
  int k;
  f[0] = 0;
  for (int i = n, _b = 1; i >= _b; i--)
    if (!vs[i]) {
      vs[i] = true;
      k = log2(i) + 1;
      if (b[k] - i > n) {
        f[i] = 0;
        f[0] = i;
      } else {
        f[i] = b[k] - i;
        f[b[k] - i] = i;
        vs[b[k] - i] = true;
      }
    }
  long long ans = 0;
  for (int i = 0, _b = n; i <= _b; i++) ans += (long long)f[i] ^ (long long)i;
  cout << ans << endl;
  for (int i = 0, _b = n; i <= _b; i++) printf("%d ", f[i]);
}
int main() {
  int test = 1;
  for (int i = 1, _b = test; i <= _b; i++) {
    input();
    process();
  }
  return 0;
}
