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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

namespace {
constexpr std::size_t size = 19;
int result[size];


long long simple_case(int num) {
    return static_cast<long long>(num+1);
}

long long two_digit(int num) {
    num += 10;
    return 18 - num + 1;
}

long long count(int pos) {
    long long c1 = 0;
    long long c2 = 0;

    if(pos == size -1){
        return simple_case(result[pos]);
    }

    //one digit case:
    c1 =  simple_case(result[pos]) * count(pos+1);

    //two digit case:
    if(result[pos] < 9 && result[pos+1] == 1) {
        c2 = two_digit(result[pos]);
        if(pos < size - 2) {
            c2 *= count(pos+2);
        }
    }

    return c1 + c2;
}

}

int main(void) {
    std::memset(result, 0, size);
    char number[size];
    std::memset(number, '0', size);

    std::cin >> number;

    for(int i=0; i<size; ++i) {
        result[i] = number[i] - 48;
    }

    if(std::strlen(number) == 1) {
        std::cout << simple_case(result[0]);
        return 0;
    }

    long long counter = 0;
    std::reverse(result, result+size);

    for(int i=0; i<size; ++i) {

        if(result[i] == -48) {
            // std::cout << "start:";
            counter = count(i+1);
            break;
        } else {
            // std::cout << result[i] << ", ";
        }

    }

    std::printf("%lld ", counter);


    return 0;
}