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

using namespace std;
long long n,a, pop,suma;
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n;
    cin>>a;
    pop=a;
    for(int i = 2; i<=n; i++){
        cin>>a;
        int dp = (int)log10(pop)+1,da = (int)log10(a)+1;
        if(dp==da)
        {
            if(pop>=a){ a*=10;suma++;}
        }
        else if(dp>da)
        {
            long long u = pow(10,dp-da), c = pop/u, r = c%u;
            if(a>c) {a*=u;suma+=((int)log10(u)+1);}
            else if(a<c) {a*=(u*10);suma+=((int)log10(u)+2);}
            else if(a==c)
            {
                if(r+1<u)
                {
                    a*=u;
                    a+=(r+1);
                    suma+=((int)log10(u)+1);}
                }
                else {a*=(u*10);suma+=((int)log10(u)+2);}

        }
        pop=a;
    }
    cout<<suma<<"\n";
    return 0;
}