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
#include <cstdio>
#include <algorithm>
#define lld long long int
#define MUCH 99999999999999999ll //17 9s

using namespace std;

int numd(lld a) {
    int res = 0;
    lld x = 1;
    while (x <= a) {
        res++; x*= 10;
    }
    return res;
}

lld last, curr, result, p10[19];
int n, ld, cd, extra;

int main() {
    p10[0] = 1;
    for (int i = 1; i < 19; i++) p10[i] = p10[i - 1] * 10;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &curr);
        ld = numd(last);
        int dd = max(ld - numd(curr), 0);
        for (int j = 0; j < dd; j++) curr*= 10;
        if (curr > last) {
            last = curr;
        } else {
            last++; ld++;
            while (last / p10[ld] == curr / p10[ld]) ld--;
            if (dd <= ld) {
                curr = curr * 10;
                if (curr > MUCH) {
                    curr /= 10;
                    extra++;
                } else {
                    dd++;
                }
                last = curr;
            }
        }
        result += dd + extra;
    }
    printf("%lld\n", result);
    return 0;
}