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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>

long long getd(long long x) {
    long long dl = 0;
    while (x) {
        dl++;
        x /= 10;
    }
    return dl;
}

bool pref(long long a, long long b) {
    long long dla = getd(a), dlb = getd(b);
    while (dla > dlb) {
        a /= 10;
        dla--;
    }
    return a == b;
}

bool mogeDodac(long long a, long long b) {
    a += 1;
    return pref(a, b);
}

bool wiekszy(long long a, long long b) {
    long long dla = getd(a), dlb = getd(b);
    if (dla < dlb) {
        while (dlb > dla) {
            dlb--;
            b /= 10;
        }
    } else {
        while (dla > dlb) {
            a /= 10;
            dla--;
        }
    }
    return a > b;
}

int main() {
    int n;
    long long x, pop, dl, wyn = 0;
    scanf("%d", &n);
    scanf("%lld", &x);
    dl = getd(x);
    for (int i = 1; i < n; i++) {
        pop = x;
        scanf("%lld", &x);
        if (dl < 18) {
            long long dln = getd(x);
            if (x > pop) {
                dl = dln;
                continue;
            }
            if (mogeDodac(pop, x)) {
                x = pop + 1;
                dl = getd(x);
                wyn += dl - dln;
            } else {
                while (dln < dl) {
                    dln++;
                    wyn++;
                    x *= 10;
                }
                if (x <= pop) {
                    dl++;
                    wyn++;
                    x *= 10;
                }
            }
        } else {
            long long dln = getd(x);
            if (pref(pop, x)) {
                wyn += dl - dln;
                long long d = getd(pop);
                d > dln ? x = pop : x = x;
            } else {
                if (wiekszy(pop, x)) {  // 1337  100001
                    wyn += dl - dln + 1;
                    dl++;
                } else {
                    wyn += dl - dln;
                }
            }
        }
    }
    printf("%lld", wyn);
    return 0;
}