Language: C++

    #include <bits/stdc++.h>
    #define int long long
    using namespace std;
    inline int read(){
        int ret=0,pos=1;char c=getchar();
        while(!isdigit(c) && c!='-' )c=getchar();
        if(c=='-')	pos=-1,c=getchar();
        while(isdigit(c))ret=(ret<<3)+(ret<<1)+c-48,c=getchar();
        return pos*ret;
    }
    string n;
    int k;
    /*int ans[150];
    void add(int x){
    	int i=0;a[0]+=x;
    	while(a[i]>=10){
    		a[i+1]+=a[i]/10;
    		a[i]%=10;
    		i++;
    	}
    	if(a[i]==0) tp=i-1;
    	else tp=i;
    }
    void mul(int x){
    	int i=0;
    	int tag=0;
    	while(a[i]>=10 || i<=tp){
    		a[i]*=x;
    		a[i]+=tag;
    		tag=a[i]/10;
    		a[i]%=10;
    		i++;
    	}
    	if(a[i]==0) tp=i-1;
    	else tp=i;
    }*/
    int ans;
    int cnt,l,r;
    signed main(){
    	cin>>n;
    	k=read();
    	int len=n.length();
    	if(k==1){
            ans+=9*(len-1);
            ans+=(n[0]-'0');
    	}
    	else if(k==2){
    		cnt=(len-1)*(len-2)/2*81;
    		ans+=cnt;
    		l=n[0]-'0',r=n[1]-'0';
    		ans+=(l-1)*(len-1)*9;
    		len--;
    		l=n[1]-'0';
    		cnt=(len-1)*9+r;
    		ans+=cnt;
    	}
    	else{
    		int cnt=(len-1)*(len-2)*(len-3)/6*729;
    		ans+=cnt;
    		l=n[0]-'0',r=n[1]-'0';
    		ans+=(l-1)*(len-1)*(len-2)/2*81;
    		len--;
    		cnt=max((len-1)*(len-2)/2*81,0);
    		ans+=cnt;
    		l=n[1]-'0',r=n[2]-'0';
    		ans+=(l-1)*(len-1)*9;
    		len--;
    		l=n[2]-'0';
    		cnt=(len-1)*9+r;
    		ans+=cnt;
    	}
    	cout<<ans;
    }

Compiler output:
a.cc: In function 'int main()':
a.cc:63:24: error: no matching function for call to 'max(long long int, int)'
   63 |                 cnt=max((len-1)*(len-2)/2*81,0);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:63:24: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   63 |                 cnt=max((len-1)*(len-2)/2*81,0);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:63:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   63 |                 cnt=max((len-1)*(len-2)/2*81,0);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~