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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <bits/stdc++.h>

#define DEBUG if (0)
#define COUT cout << "\e[36m"
#define VAR(v) " [\e[32m" << #v << "\e[36m=\e[91m" << v << "\e[36m] "
#define ENDL "\e[39m" << endl

using namespace std;


long long digits(long long a)
{
    long long out = 0;
    while(a)
    {
        out++;
        a/=10;
    }
    return out;
}
long long  powof10(long long a)
{
    long long out = 1;
    while(a--)
        out *= 10ll;
    return out;
}

long long restsize = 0, backnum = 0;
bool hola = 0;

long long calc(long long& prev, long long curr)
{
    if(prev < curr)
    {
        prev = curr;
        backnum = 0;
        return restsize;
    }
    long long diff = digits(prev) - digits(curr);
    curr *= powof10((diff));
    if(prev < curr)
    {
        prev = curr;
        return diff+restsize;
    }
    if(prev - curr+1 >= powof10((diff)))
    {
        long long oldprev = prev;
        prev = curr*10;
        if(prev >= 1e10)
        {
            prev/=10;
            if(oldprev == prev)
            {
                hola = 1;
                backnum++;
                if(digits(backnum) > restsize)
                {
                    restsize++;
                    backnum = 0;
                }
            }
            else
            {
                restsize++;
                backnum = 0;
            }


        }
        else
            diff++;
        return diff+restsize;
    }
    if(restsize > 0)
    {
        backnum++;
        if(digits(backnum) > restsize)
        {
            prev++;
            backnum = 0;
        }

    }
    else{prev++;}
    if(prev >= 1e10)
    {
        prev/=10;
        backnum++;
        if(digits(backnum) > restsize)
        {
            restsize++;
            backnum = 0;
        }
    }


    return diff+restsize;
}

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

    int n;
    long long ans = 0;
    long long prev = -1, curr;
    cin  >> n >> prev;
    DEBUG COUT << VAR(n) << VAR(prev) << ENDL;
    for(int i = 1; i < n; i++)
    {
        hola = 0;
        cin >> curr;
        long long orgprev = prev;
        ans += calc(prev, curr);
        //if(prev <= orgprev) DEBUG COUT << "ZESPUTE!!!" << VAR(orgprev) << VAR(prev) << ENDL;
        if(hola) DEBUG COUT << VAR(orgprev) << VAR(curr) << VAR(prev) << VAR(restsize) << VAR(backnum) << ENDL;
    }
    DEBUG COUT << ENDL;
    cout << ans << endl;

    return 0;
}