# Atcoder Beg. Contest 161 D

Can this problem be solved using Digit DP? I read the editorial and it uses queue and I dont even get how it works.

Do you know about Stepping Numbers? You may generate the Lunlun Numbers in a similar fashion. Tell me if it is still unclear.

Will read about it. Seems like a standard problem , I didnâ€™t knew about.

Even brute forcing all solutions will fetch you an AC by the way

``````/*<----------------------------------------------------------------------->

<-------------------------------------------------------------------------->
_           __                _      _____ _____ _____
___ _   _| |__   ___ / _|_ __ ___  __ _| | __ |___  |___  |___  |
/ __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ /    / /   / /   / /
| (__| |_| | |_) |  __/  _| | |  __/ (_| |   <    / /   / /   / /
\___|\__,_|_.__/ \___|_| |_|  \___|\__,_|_|\_\  /_/   /_/   /_/

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vi;
typedef vector<pll> vpll;
typedef unordered_map <ll,ll> umap ;
//#pragma GCC optimize "trapv"
#define loop(i,a,b) for(ll i=a ;i<b;i++)
#define For(i,n) for(int i=0;i<(ll)n;i++)
#define Rev(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,n) for(int i=1;i<=n;++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(),(v).end()
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a,b) make_pair(a,b)
#define pf(n) cout<<n<<"\n"
#define pff(n) cout << n << " " ;
long const M=1e9+7;
const long mxN =1e5+2 ;
const long mxNN =1e6+2 ;
set<ll>store ;
void pre_comp(ll x){
store.insert(x) ;
if(x>323456666+3)return ;
if(x%10>0)pre_comp(x%10-1+x*10) ;
if(x%10<9)pre_comp(x%10+1+x*10) ;
pre_comp(10*x+x%10) ;
}
void solve(){
for(int i=1;i<10;i++)pre_comp(i) ;
ll k; cin >> k ;k--;
while(k--)store.erase(store.begin()) ;
cout << *store.begin() << endl ;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout << setprecision(20) << fixed ;
solve() ;
//ll t ; cin >> t ; while(t--)solve();
return 0;
}
``````