using
System;
using
System.Collections.Generic;
class
GFG
{
static
readonly
int
M = 20;
static
int
[,,,]dp=
new
int
[M, M, 2, 2];
static
int
d, K;
static
int
count(
int
pos,
int
cnt,
int
tight,
int
nonz, List<
int
> num)
{
if
(pos == num.Count)
{
if
(cnt == K)
return
1;
return
0;
}
if
(dp[pos, cnt, tight, nonz] != -1)
return
dp[pos, cnt, tight, nonz];
int
ans = 0;
int
limit = ((tight != 0) ? 9 : num[pos]);
for
(
int
dig = 0; dig <= limit; dig++)
{
int
currCnt = cnt;
if
(dig == d)
{
if
(d != 0 || (d == 0 && nonz != 0))
currCnt++;
}
int
currTight = tight;
if
(dig < num[pos])
currTight = 1;
ans += count(pos + 1, currCnt,
currTight, (dig != 0 ? 1 : 0), num);
}
return
dp[pos, cnt, tight, nonz] = ans;
}
static
int
solve(
int
x)
{
List<
int
> num =
new
List<
int
>();
while
(x != 0)
{
num.Add(x % 10);
x /= 10;
}
num.Reverse();
for
(
int
i = 0; i < M; i++)
for
(
int
j = 0; j < M; j++)
for
(
int
k = 0; k < 2; k++)
for
(
int
l = 0; l < 2; l++)
dp[i, j, k, l]=-1;
return
count(0, 0, 0, 0, num);
}
public
static
void
Main()
{
int
L = 11, R = 100;
d = 2; K = 1;
Console.Write( solve(R) - solve(L - 1) );
}
}