using
System;
using
System.Collections.Generic;
class
GFG{
static
List<
int
> digits =
new
List<
int
>();
static
bool
[]vis =
new
bool
[170];
static
int
[,,,]dp =
new
int
[ 19, 19, 2, 170 ];
static
void
ConvertIntoDigit(
int
n)
{
while
(n > 0)
{
int
dig = n % 10;
digits.Add(dig);
n /= 10;
}
digits.Reverse();
}
static
int
solve(
int
idx,
int
k,
int
tight,
int
sum)
{
if
(idx == digits.Count &&
k == 0 && sum % 2 == 1)
{
if
(!vis[sum])
{
vis[sum] =
true
;
return
1;
}
return
0;
}
if
(idx > digits.Count)
{
return
0;
}
if
(dp[idx, k, tight, sum] > 0)
{
return
dp[idx, k, tight, sum];
}
int
j;
if
(idx < digits.Count && tight == 0)
{
j = digits[idx];
}
else
{
j = 9;
}
int
cnt = 0;
for
(
int
i = (k > 0 ? 0 : 1); i <= j; i++)
{
int
newtight = tight;
if
(i < j)
{
newtight = 1;
}
if
(i == 0)
cnt += solve(idx + 1, k - 1,
newtight, sum);
else
cnt += solve(idx + 1, k, newtight,
sum + i);
}
return
dp[idx, k, tight, sum] = cnt;
}
public
static
void
Main(String[] args)
{
int
N, k;
N = 169; k = 2;
ConvertIntoDigit(N);
k = digits.Count - k;
Console.Write(solve(0, k, 0, 0));
}
}