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
#include <iostream>

using namespace std;

int n,d,dlug_ost,delta_dlug;
long long m,w,roznica;
int dl[200007];
long long t[200007],p[17];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    p[0]=1;
    for (int i=1; i<17; i++)
    {
        p[i]=p[i-1]*10;
    }
    for (int i=0; i<n; i++)
    {
        cin>>t[i];
        d=1;
        m=10;
        while ((long long)t[i]/m)
        {
            m*=10;
            d++;
        }
        dl[i]=d;
        //cout<<dl[i]<<" ";
    }
    dlug_ost=dl[0];
    int i=1;
    while ((dlug_ost<16)&&(i<n))
    {
        //cout<<i<<") ";
        delta_dlug=dlug_ost-dl[i];
        if (delta_dlug<0)
        {
            //cout<<"A\n";
            dlug_ost=dl[i];
            i++;
            continue;
        }
        else if (delta_dlug==0)
        {
            if (t[i]<=t[i-1])
            {
                w++;
                t[i]*=10;
                dlug_ost++;
                i++;
                //cout<<"X"<<w<<"\n";
                continue;
            }
        }
        t[i]*=p[delta_dlug];
        roznica=t[i]-t[i-1];
        //cout<<"D ";
        if (roznica>0)
        {
            //cout<<"a ";
            w+=delta_dlug;
        }
        else
        {
            //cout<<roznica<<" "<<delta_dlug<<" ";
            roznica*=-1;
            if (roznica<p[delta_dlug]-1)
            {
                //cout<<"c ";
                w+=delta_dlug;
                t[i]+=roznica+1;
            }
            else
            {
                //cout<<"b ";
                w+=delta_dlug+1;
                dlug_ost++;
                t[i]*=10;
            }

        }
        //cout<<w<<"\n";
        i++;
    }
    while (i<n)
    {
        delta_dlug=dlug_ost-dl[i];

        t[i]*=p[16-dl[i]];

        roznica=t[i]-t[i-1];
        //cout<<"D ";
        if (roznica>=0)
        {
            //cout<<"a ";
            w+=delta_dlug;
        }
        else
        {
            //cout<<roznica<<" "<<delta_dlug<<" ";
            w+=delta_dlug+1;
            dlug_ost++;
        }
        i++;
    }
    cout<<w;

    /*cout<<"\n";
    for (int i=0; i<n; i++)
        cout<<t[i]<<" ";*/
    return 0;
}