1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>

long long apb(long long n)
{
    if (n < 10)
    {
        return n + 1;
    }
    long long lsd = n % 10; // least significant digit
    long long doublet = n % 100;
    long long lsd_apb = apb(lsd);
    if (doublet < 19)
    {
        return lsd_apb * apb(n/10) + (10-lsd_apb)*apb(n/100);
    }
    else
    {
        return lsd_apb * apb(n/10);
    }
}

int main()
{
    long long n;
    std::cin >> n;
    std::cout << apb(n) << std::endl;
}