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;
typedef priority_queue<long long, vector<long long>, greater<long long>>
    minHeap;
const int INF = 1e9 + 9;
const long long LINF = 1e17 + 9;
const long long MD = 1000000007;
inline long long mul(long long a, long long b) { return (a * b) % MD; }
inline long long po(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) ans = mul(ans, a);
    a = mul(a, a);
    b /= 2;
  }
  return ans;
}
const int N = 2e4 + 33;
long long n, m, k, t;
long long arr[N];
map<int, int> mp;
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);
  cout << fixed;
  cout << setprecision(8);
  cerr << "N"
       << " is " << N << endl;
  cin >> n;
  vector<int> ans(n + 1);
  int msb = 0;
  for (int i = 30; i >= 0; i--) {
    if ((1 << i) & n) {
      msb = i;
      break;
    }
  }
  int x = 0;
  for (int i = 0; i <= msb; i++) x += (1 << i);
  long long but = 0;
  cerr << "x"
       << " is " << x << endl;
  for (int i = n; i >= 0; i--) {
    ans[i] = x ^ i;
    if (ans[i] > n || mp[ans[i]] != 0) {
      for (int j = msb; j >= 0 && (ans[i] > n || mp[ans[i]] != 0); j--) {
        if (ans[i] & (1 << j)) ans[i] ^= 1 << j;
      }
    }
    mp[ans[i]]++;
    but += ans[i] ^ i;
  }
  cout << but << endl;
  for (int u : ans) cout << u << " ";
  return 0;
}
