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
#include <stdio.h>
#include <stdint.h>

int64_t numberOfDigits(int64_t value)
{
    if (value == 0)
        return 0;

    int64_t total = 0;
    while (value > 0)
    {
        value /= 10;
        ++total;
    }
    return total;
}

int main()
{
    int n;
    scanf("%u", &n);

    int64_t total = 0;
    int64_t last = 0;
    int64_t digitsOverflow = 0;
    for (int i = 0; i < n; ++i)
    {
        int64_t value;
        scanf("%lu", &value);

        if (last == 0)
        {
            last = value;
            continue;
        }


        int64_t multiplier = 1;
        int64_t increases = 0;
        int64_t digits = numberOfDigits(value);
        while (digits < 19)
        {
            if (last < value * multiplier)
            {
                value = value * multiplier;
                break;
            }
            else if ((last >= value * multiplier) && last < ((value + 1) * multiplier - 1))
            {
                value = last + 1;
                break;
            }

            multiplier *= 10;
            increases++;
            digits++;
        }

        if (digits == 19)
        {
            digitsOverflow++;
            increases--;
            value = value * (multiplier / 10);
        }

        increases += digitsOverflow;
        total += increases;
        last = value;
        //printf("value: %lu  inc: %lu  over: %lu\n", value, increases, digitsOverflow);
    }


    printf("%lu\n", total);
    return 0;
}