Language: C++

#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<62);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}

ll k1(string n){
	if(n.size()<1)return 0;
	ll ans=0;
	ll d1=(n[0]-'0');
		//zero
		ans+=binomial<ll>((ll)n.size()-1,1)*9;
		//else
		ans+=d1;
	return ans;
}

ll k2(string n){
	if(n.size()<2)return 0;
	ll d2=(n[0]-'0');
	ll ans=0;
		ans+=binomial<ll>((ll)n.size()-1,2)*9*9;
		ans+=max(d2-1,0LL)*binomial<ll>((ll)n.size()-1,1)*9;
		string n2;
		for(int i=1;i<n.size();i++){
			n2.push_back(n[i]);
		}
		ans+=k1(n2);
		return ans;
}

int main(){
	string n;cin>>n;
	ll k;cin>>k;
	ll ans=0;
	if(k==1){
		cout<<k1(n)<<endl;
	}
	if(k==2){
		if(n.size()<2){
			cout<<0<<endl;
			return 0;
		}
		cout<<k2(n)<<endl;
	}
	if(k==3){
		//zero
		if(n.size()<3){
			cout<<0<<endl;
			return 0;
		}
		ll d3=(n[0]-'0');
		ans+=binomial<ll>((ll)n.size()-1,3)*9*9*9;
		ans+=max(d3-1,0LL)*binomial<ll>((ll)n.size()-1,2)*9*9;
		string n2;
		for(int i=1;i<n.size();i++){
			n2.push_back(n[i]);
		}
		ans+=k2(n2);
		cout<<ans<<endl;
	}
}


Compiler output:
a.cc: In function 'll k2(std::string)':
a.cc:118:25: error: no matching function for call to 'max(ll, long long int)'
  118 |                 ans+=max(d2-1,0LL)*binomial<ll>((ll)n.size()-1,1)*9;
      |                      ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:8:
/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:118:25: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
  118 |                 ans+=max(d2-1,0LL)*binomial<ll>((ll)n.size()-1,1)*9;
      |                      ~~~^~~~~~~~~~
/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,
                 from a.cc:25:
/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:118:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
  118 |                 ans+=max(d2-1,0LL)*binomial<ll>((ll)n.size()-1,1)*9;
      |                      ~~~^~~~~~~~~~
a.cc: In function 'int main()':
a.cc:149:25: error: no matching function for call to 'max(ll, long long int)'
  149 |                 ans+=max(d3-1,0LL)*binomial<ll>((ll)n.size()-1,2)*9*9;
      |                      ~~~^~~~~~~~~~
/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:149:25: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
  149 |                 ans+=max(d3-1,0LL)*binomial<ll>((ll)n.size()-1,2)*9*9;
      |                      ~~~^~~~~~~~~~
/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
/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:149:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
  149 |                 ans+=max(d3-1,0LL)*binomial<ll>((ll)n.size()-1,2)*9*9;
      |                      ~~~^~~~~~~~~~