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
#include <bits/stdc++.h>

using namespace std;

int getLen(long long x) {
    int ret = 0;
    while (x >= 1) {
        ret++;
        x /= 10;
    }
    return ret;
}

long long getPrefix(long long x, int l) {
    int len = getLen(x);
    while (len > l) {
        x /= 10;
        len--;
    }
    return x;
}

int main() {
    int n;
    scanf("%d", &n);
    
    long long ans = 0;
    long long last = 0;
    int lenLast = 0;
    for (int i = 1; i <= n; i++) {
        long long x;
        scanf("%lld", &x);
        int len = getLen(x);
        if (x <= last) {
            long long tmp = getPrefix(last, len);
            if (x == tmp && getPrefix(last + 1, len) == x) {
                x = last + 1;
                int newLen = getLen(x);
                ans += lenLast - len;
                len = lenLast;
            } else {
                int newLen = x > tmp ? lenLast : lenLast + 1;
                ans += newLen - len;
                for (int j = 1; j + len <= min(18, newLen); j++) {
                    x *= 10;
                }
                len = newLen;
            }
        }
        last = x;
        lenLast = len;
    }
    
    printf("%lld\n", ans);
    return 0;
}