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
#include <iostream>
#include <string>
using namespace std;

#define LIMIT (10000000000000000LL) // 10**16

inline bool startswith(string const& a, string const& b) {
    if (a.length() < b.length()) return 0;
    for (unsigned i = 0; i < b.length(); ++i) {
        if (a[i] != b[i]) return 0;
    }
    return 1;
}

inline bool only9after(string const& a, string const& b) {
    for (unsigned i = b.length(); i < a.length(); ++i) {
        if (a[i] != '9') return 0;
    }
    return 1;
}

unsigned long long ans = 0;

int main() {
    ios::sync_with_stdio(0);

    int n;
    cin >> n;

    int cur_exp = 0;
    unsigned long long cur_val;
    cin >> cur_val;

    for (int i = 1; i < n; ++i) {
        unsigned long long v;
        cin >> v;

        auto cur_val_str = to_string(cur_val);
        auto v_str = to_string(v);

        if (startswith(cur_val_str, v_str)) {
            if (only9after(cur_val_str, v_str)) {
                while (v <= cur_val) {
                    v *= 10;
                    ++ans;
                }
            } else {
                v = cur_val + 1;
                ans += cur_val_str.length() - v_str.length();
            }
        } else {
            while (v <= cur_val) {
                v *= 10;
                ++ans;
            }
        }

        cur_val = v;
        ans += cur_exp;
        while (cur_val > LIMIT) {
            cur_val /= 10;
            ++cur_exp;
        }
    }

    cout << ans;

    return 0;
}