Language: C++

#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
int main()
{
	string n;
	int k;
	cin>>n>>k;
	if(k==1)
	{
		ll ans=0;
		ans+=n[0]-'0';
		ans+=(n.size()-1)*9;
		cout<<ans<<endl;
		return 0;
	}
	else if(k==2)
	{
		ll ans=0;
		ans+=(n.size()-1)*(n.size()-2)/2*(ll)9*9;
		ans+=max((ll)0,(ll)(n[0]-'1')*(n.size()-1)*9);
		//cout<<ans<<endl;
		int now=1;
		for(;now<n.size();now++)
		{
			if(n[now]!=0)break;
		}
		//cout<<now<<endl;
		if(now!=n.size())ans+=(n.size()-now-1)*9+(n[now]-'0');
		cout<<ans<<endl;
	}
	else if(k==3)
	{
		ll ans=0;
		ans+=(n.size()-1)*(n.size()-2)*(n.size()-3)/(ll)6*(ll)9*9*9;
		ans+=max((ll)0,(ll)n[0]-'1')*(n.size()-1)*(n.size()-2)/2*(ll)9*9;		
		//cout<<ans<<endl;
		ll now=1;
		for(;now<n.size();now++)
		{
			if(n[now]!=0)break;
		 } 
		if(now!=n.size())
		{
			ans+=(n.size()-now-1)*(n.size()-now-2)/2*(ll)9*9;
			ans+=max((ll)0,(ll)(n[now]-'1')*(n.size()-now-1)*9);
			//cout<<ans<<endl;
			now++;
			for(;now<n.size();now++)
				if(n[now]!=0)break;
			//cout<<now<<endl;
			if(now!=n.size())
			{
				ans+=(n.size()-now-1)*9+(n[now]-'0');
				//cout<<ans<<endl;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:52:25: error: no matching function for call to 'max(long long int, long long unsigned int)'
   52 |                 ans+=max((ll)0,(ll)(n[0]-'1')*(n.size()-1)*9);
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:52:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   52 |                 ans+=max((ll)0,(ll)(n[0]-'1')*(n.size()-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:
/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:52:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   52 |                 ans+=max((ll)0,(ll)(n[0]-'1')*(n.size()-1)*9);
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:77:33: error: no matching function for call to 'max(long long int, long long unsigned int)'
   77 |                         ans+=max((ll)0,(ll)(n[now]-'1')*(n.size()-now-1)*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:77:33: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   77 |                         ans+=max((ll)0,(ll)(n[now]-'1')*(n.size()-now-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
/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:77:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   77 |                         ans+=max((ll)0,(ll)(n[now]-'1')*(n.size()-now-1)*9);
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~