
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    
    if (N == 0) {
        print(0);
        return 0;
    }

    vector<pair<ll, ll>> v;

    ll l = 0, r = 0;
    ll c = 1;
    REP(i, 50) {
        v.eb(l, r);
        if (l <= N && N <= r) break;
        (i % 2 ? l : r) += c;

        c *= -2;
    }

    string S(v.size() - 1, '0');

    c /= -2;
    REVFOR(i, 1, v.size()) {
        if (v[i].fi <= N && N <= v[i].se && (v[i-1].fi > N || v[i-1].se < N)) {
            S[i - 1] = '1';
            N -= c;
        }

        c /= -2;
    }

    reverse(ALL(S));
    print(S);
}

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int merge(VI& a, int s1, int s2, int t){
  int i, j, res = 0;
  VI tmp;
  for(i=s1,j=s2;i<s2&&j<t;){
	if(a[i] > a[j]){
	  tmp.PB(a[j++]);
	  res += s2-s1-(i-s1);
	}
	else{
	  tmp.PB(a[i++]);
	}
  }
  while(i<s2) tmp.PB(a[i++]);
  while(j<t) tmp.PB(a[j++]);

  for(i=s1;i<t;++i)
	a[i] = tmp[i-s1];
  return res;
}

int sort(VI& a, int s, int t){
  if(s+1 >= t) return 0;
  int m = (s + t) / 2, res = 0;
  res += sort(a, s, m);
  res += sort(a, m, t);
  res += merge(a, s, m, t);
  return res;
}


int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  VI a(N); REP(i,N) cin >> a[i];
  int ans = sort(a, 0, N);

  cout << a[0];
  REP(i,N-1) cout << " " << a[i+1];
  cout << endl;

  cout << ans << endl;
  
  return 0;
}