Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to *n*, inclusive.

For permutation *p* = *p*<sub class="lower-index">0</sub>, *p*<sub class="lower-index">1</sub>, ..., *p*<sub class="lower-index">*n*</sub>, Polo has defined its beauty — number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0c51fe5d835015fdb8b8dbb056e9a83c439c83dc.png" style="max-width: 100.0%;max-height: 100.0%;"/>.

Expression <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b364f2e04c665b78b924ec10666327a4ef4635bc.png" style="max-width: 100.0%;max-height: 100.0%;"/> 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.
The single line contains a positive integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">6</sup>).
// #pragma GCC optimize("unroll-loops")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define pb push_back
// #define int short
#define int long long
#define pii pair<int, int>
#define pdd pair<double, double>
#define pdi pair<double, int>
#define unmap unordered_map
#define unset unordered_set
#define tupint tuple<int, int, int>
#define pib pair<int, bool>
#define dbl long double
#define str string
#define psi pair<str, int>
using namespace std;
const int M = 998244353;


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n; n++;
    vector<int> ans(n);
    for (int i = 1; i < n; i++) {
        if (i % 2 == 0) {
            ans[i - 1] = i;
        } else {
            ans[i + 1] = i;
        }
    }
    if (n % 2 == 0) {
        ans[n - 1] = 0;
        ans[0] = n - 1;
    }
    int d = 0;
    for (int i = 0; i < n; i++) {
        d += i ^ ans[i];
    }
    cout << d << '\n';
    for (auto g : ans) {
        cout << g << ' ';
    }


}