//g++ 2.cpp -std=c++14 -O2 -I . #include using namespace std; #include using namespace atcoder; using ll = long long; using ld = long double; using vi = vector; using vvi = vector; using vll = vector; using vvll = vector; using vld = vector; using vvld = vector; using vst = vector; using vvst = vector; #define fi first #define se second #define pb push_back #define eb emplace_back #define pq_big(T) priority_queue,less> #define pq_small(T) priority_queue,greater> #define all(a) a.begin(),a.end() #define rep(i,start,end) for(ll i=start;i<(ll)(end);i++) #define per(i,start,end) for(ll i=start;i>=(ll)(end);i--) #define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end()) vi a = {1,0,0,0,1,0,1,0,2,1}; map seen; ll f(ll n){ ll res=0; while(n>0){ res+=a[n%10]; n/=10; } return res; } // 1 to n ll count(ll n){ ll res=0; if(seen[n]!=0){ return seen[n]; } if(n<10){ rep(i,1,n+1){ res+=a[i]; } seen[n]=res; return res; } ll x=n/10,y=n%10; res+=6*x; // 1 から x-1 まで 10個ずつ res+=10*count(x-1); res+=f(x); rep(i,10*x+1,n+1){ res+=f(i); } seen[n]=res; return res; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); rep(i,0,300){ ll naive=0; ll opt=count(i); rep(j,0,i+1){ naive+=f(j); } assert(naive==opt); } ll k; cin>>k; ll ng=-1,ok=1e17; while(ok-ng>1){ ll ch=(ng+ok)/2; //cout<=k){ ok=ch; } else{ ng=ch; } } if(count(ok)==k){ cout<