#include <bits/stdc++.h>

using namespace std;

ifstream fi ("bai4_17.inp");
ofstream fo ("bai4_17.out");

string s;
int num=0,ans=0,num1=0;
string m="",ss="";

void cdnp(int n){
  while (n>0){
    if (n%2==1){s='1'+s;num1++;}
    else s='0'+s;
    n=n/2;
  }
}

void timmax()
{
  for (int i=0;i<num-1;i++)
   {
     ss=ss[num-1]+ss;
     ss.erase(num,1);
     if (ss>s){s=ss;}
  }
}

int main(){
    int n;
    fi>>n;
    cdnp(n);
    fo<<s<<endl;
    ss=s;
    num=s.length();
    timmax();
    for (int i=0;i<num;i++){
        if (s[i]=='1'){ans=ans+pow(2,num-i-1);num1--;}
        if (num1=0) break;
    }
    fo<<ans;
}
