#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int cache[n];
memset(cache,0,sizeof(cache[0])*n);
cout<<exchange(n,cache);
return 0;
}
int exchange(int n,int *cache){
if(n==0 || n==1){
return n;
}
if(cache[n]!=0)
return cache[n];
int op1,op2,op3;
op1 = exchange(n/2,cache);
op2 = exchange(n/3,cache);
op3 = exchange(n/4,cache);
return cache[n] = max(n,op1+op2+op3);
}