Problem:
Score : 500 points

Problem Statement

Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.

Constraints

1 \leq N < 10^{100}

1 \leq K \leq 3

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the count.

Sample Input 1

100
1

Sample Output 1

19

The following 19 integers satisfy the condition:

1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100

Sample Input 2

25
2

Sample Output 2

14

The following 14 integers satisfy the condition:

11,12,13,14,15,16,17,18,19,21,22,23,24,25

Sample Input 3

314159
2

Sample Output 3

937

Sample Input 4

9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3

Sample Output 4

117879300

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力


const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
int main() {
    COMinit();
    vector<ll> sum3(1001);

    ll K;
    string S;
    cin >>S>>K;
    ll ans=0;
    ll N = S.size();
    if(K>N) {
        cout << 0 << endl;


        return 0;
    }
    if(K==3){
        ans += COM(N-1,K)*pow(9,K);
        //cout << ans << endl;
        ans += COM(N-2,K-1) * ctoi(S[0])*pow(9,K-1);
        string T = S.substr(0, 2);
        int num = atoi(T.c_str());
        //ans += num+1;
        //cout << num;
        int nm = num+1;
        rep(i,num){
            if((i%10) == 0 || ((i/10)%10) == 0){
                nm--;
            }
        }
        ans += COM(N-3,K-2) * nm*pow(9,K-2);
        //cout << ans << endl;
        string U = S.substr(0, 3);
        num = atoi(U.c_str());
        ans += num+1;
        //cout << num;
        rep(i,num){
            if(i<100||(i%10) == 0 || ((i/10)%10) == 0){
                ans--;
            }
        }
    }else if(K==2){
        ans += COM(N-1,K)*pow(9,K);
        //cout << ans << endl;
        ans += COM(N-2,K-1) * ctoi(S[0])*pow(9,K-1);
        //cout << ans << endl;
        string T = S.substr(0, 2);
        int num = atoi(T.c_str());
        ans += num+1;
        //cout << num;
        rep(i,num){
            if((i%10) == 0 || ((i/10)%10) == 0){
                ans--;
            }
        }
    }else{
        ans += COM(N-1,K)*pow(9,K);
        string V = S.substr(0, 1);
        int num = atoi(V.c_str());
        ans += num+1;
        //cout << num;
        rep(i,num){
            if((i%10) == 0){
                ans--;
            }
        }
    }
    
    cout << ans << endl;


    return 0;
    

}