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
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    long long n;

    cin >> n;

    long long previousPairCount = 1;

    int previousDigitNumber = n % 10;

    n /= 10;

    int digitNumber = (int)(n % 10);

    long long pairCount = previousDigitNumber + 1;

    while (n){
        int twoDigitNumber = digitNumber * 10 + previousDigitNumber;

        long long newPairCount = (digitNumber + 1) * pairCount + 
            max(0, 10 - abs(9-twoDigitNumber)) * previousPairCount;

        previousDigitNumber = digitNumber;
        
        n /= 10;

        digitNumber = (int)(n % 10);

        previousPairCount = pairCount;

        pairCount = newPairCount;
    }

    cout << pairCount << endl;

    return 0;
}