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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;

int64_t n;
int64_t digits;

int64_t countDigits(int64_t x){
    if(x == 0){
        return 1;
    }
    int res = 0;
    while(x > 0){
        x /= 10;
        res++;
    }
    return res;
}

int64_t max(int a, int64_t b){
    return max((int64_t)a, b);
}

int64_t max(int64_t a, int b){
    return max(b, a);
}

int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n;
    digits = countDigits(n);
    int64_t dp[digits + 1];
    dp[0] = n % 10 + 1;
    if(digits == 1){
        cout << dp[0];
        return 0;
    }
    int64_t dig1 = (n / 10) % 10;
    int64_t num1 = n % 100;
    dp[1] = dp[0] * (dig1 + 1);
    if(num1 >= 10 and num1 <= 18){
        dp[1] += 19 - num1;
    }
    if(digits == 2){
        cout << dp[1];
        return 0;
    }
    n /= 10;
    for(int64_t i = 2; i < digits; i++){
        dig1 = (n / 10) % 10;
        num1 = n % 100;
        int64_t a = 0;
        if(num1 >= 10 and num1 <= 18){
            a = 19 - num1;
        }
        int64_t b = dig1 + 1;
        dp[i] = a * dp[i - 2] + b * dp[i - 1];
        n /= 10;
    }
    cout << dp[digits - 1];

    return 0;
}