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

#define ll long long

ll p[19] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 10000000000000000, 100000000000000000, 1000000000000000000};

ll c(ll x) { 
    return (x >= p[18] ? 19 : (x >= p[17] ? 18 : (x >= p[16] ? 17 : (x >= p[15] ? 16 : (x >= p[14] ? 15 : (x >= p[13] ? 14 : (x >= p[12] ? 13 : (x >= p[11] ? 12 : (x >= 10000000000 ? 11 : (x >= 1000000000 ? 10 : (x >= 100000000 ? 9 : (x >= 10000000 ? 8 : (x >= 1000000 ? 7 : (x >= 100000 ? 6 : (x >= 10000 ? 5 : (x >= 1000 ? 4 : (x >= 100 ? 3 : (x >= 10 ? 2 : 1))))))))))))))))));
} // xd

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

    ll n, a, b, res = 0, pa, z;
    cin >> n;

    cin >> a;
    for(int i = 0; i < n - 1; ++i) {
        cin >> b;
        if(b > a) {
            a = b;
            continue;
        }
        if(c(a) == c(b)) {
            ++res;
            a = b * 10;
        }
        else {
            z = c(a) - c(b);
            pa = a / p[z];
            if(pa > b) {
                res += z + 1;
                a = b * p[z + 1];
            }
            else if(pa < b) {
                res += z;
                a = b * p[z];
            }
            else {
                if(a % p[z] == p[z] - 1) {
                    res += z + 1;
                    a = b * p[z + 1];
                }
                else {
                    res += z;
                    a = a + 1;
                }
            }
        }
    }

    cout << res;

    return 0;
}