Language: C++

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,lb=1,ub=1e18,mid,dp[20][20][2][2];

string to_string(LL x)
{
	string ret="";
	while(x>0)
	{
		ret=(char)(x%10+'0')+ret;
		x/=10;
	}
	return ret;
}

bool check()
{
	string s=to_string(mid);
	memset(dp,0,sizeof(dp));
	dp[1][0][1][0]=1;
	repn(i,s[0]-'0'-1) dp[1][i][1][1]=1;
	dp[1][s[0]-'0'][0][1]=1;
	LL ret=0;
	repn(i,s.size()-1)
	{
		rep(j,10)
		{
			rep(k,2)
			{
				rep(p,2)
				{
					if(dp[i][j][k][p]==0) continue;
					if(p==1)
					{
						if(k==0)
						{
							if(abs(s[i]-'0'-j)<2) dp[i+1][s[i]-'0'][0][p|(s[i]-'0'>0)]+=dp[i][j][k][p];
							rep(r,s[i]-'0') if(abs(r-j)<2) dp[i+1][r][1][p|(r>0)]+=dp[i][j][k][p];
						}
						else rep(r,10) if(abs(r-j)<2) dp[i+1][r][1][p|(r>0)]+=dp[i][j][k][p];
					}
					else
					{
						dp[i+1][0][1][0]+=dp[i][j][k][p];
						repn(r,9) dp[i+1][r][1][1]+=dp[i][j][k][p];
					}
				}
			}
		}
	}
	rep(i,10) ret+=dp[s.size()][i][1][1];
	return ret<n;
}

int main()
{
	cin>>n;
	while(lb<ub)
	{
		mid=(lb+ub+1)/2;
		if(check()) lb=mid;
		else ub=mid-1;
	}
	cout<<lb<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'bool check()':
a.cc:31:27: error: call of overloaded 'to_string(long long int&)' is ambiguous
   31 |         string s=to_string(mid);
      |                  ~~~~~~~~~^~~~~
a.cc:18:8: note: candidate: 'std::string to_string(long long int)'
   18 | string to_string(LL x)
      |        ^~~~~~~~~
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:4240:3: note: candidate: 'std::string std::__cxx11::to_string(int)'
 4240 |   to_string(int __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4259:3: note: candidate: 'std::string std::__cxx11::to_string(unsigned int)'
 4259 |   to_string(unsigned __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4275:3: note: candidate: 'std::string std::__cxx11::to_string(long int)'
 4275 |   to_string(long __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4294:3: note: candidate: 'std::string std::__cxx11::to_string(long unsigned int)'
 4294 |   to_string(unsigned long __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4310:3: note: candidate: 'std::string std::__cxx11::to_string(long long int)'
 4310 |   to_string(long long __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4327:3: note: candidate: 'std::string std::__cxx11::to_string(long long unsigned int)'
 4327 |   to_string(unsigned long long __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4401:3: note: candidate: 'std::string std::__cxx11::to_string(float)'
 4401 |   to_string(float __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4411:3: note: candidate: 'std::string std::__cxx11::to_string(double)'
 4411 |   to_string(double __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4421:3: note: candidate: 'std::string std::__cxx11::to_string(long double)'
 4421 |   to_string(long double __val)
      |   ^~~~~~~~~