ll dp[21][2];
ll dfs(int pos,int limit,int lead){
if(pos==0) return 1;
if(!limit && dp[pos][lead]!=-1)
return dp[pos][lead];
ll ans=0;
int maxx=limit?a[pos]:9;
for(int i=0;i<=maxx;i++){
ans+=dfs(pos-1,limit&&i==maxx,lead&&i==0);
}
if(!limit) dp[pos][lead]=ans;
return ans;
}
ll solve(ll x){
len=0;
while(x){
a[++len]=x%10;
x/=10;
}
return dfs(len,1,1);
}
int main () {
memset(dp,-1,sizeof dp);//init
//.....
}