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

using namespace std;

string to_s(int x){
    string w="";
    while(x){
        w+=x%10+'0';
        x=x/10;
    }
    reverse(w.begin(),w.end());
    return w;
}

int main(){
    string s[2];
    int n,odp=0,a,dod;
    bool zmian;
    cin >> n >> a;
    s[0]=to_s(a);
    for(int i=1;i<n;i++){
        cin >> a;
        s[i%2]=to_s(a);
        if(s[i%2].size()<=s[(i+1)%2].size()){
            dod=0;
            for(int j=0;j<s[i%2].size();j++){
                if(s[i%2][j]<s[(i+1)%2][j]){
                    dod=1;
                    break;
                }
                else if(s[i%2][j]>s[(i+1)%2][j]){
                    dod=2;
                    break;
                }
            }
            if(dod==2||dod==1){
                odp+=s[(i+1)%2].size()-s[i%2].size()+2-dod;
                for(int j=s[i%2].size();j<s[(i+1)%2].size();j++){
                    s[i%2]+="0";
                }
                if(dod==1)s[i%2]+="0";
            }
            else{
                if(s[i%2].size()==s[(i+1)%2].size()){
                    s[i%2]+="0";
                    odp++;
                }
                else{
                    odp+=s[(i+1)%2].size()-s[i%2].size();
                    for(int j=s[i%2].size();j<s[(i+1)%2].size();j++){
                        s[i%2]+=s[(i+1)%2][j];
                    }
                    s[i%2][s[i%2].size()-1]++;
                    for(int j=s[i%2].size();zmian&&j>0;j--){
                        zmian=false;
                        if(s[i%2][j]>'9'){
                            s[i%2][j-1]+=(s[i%2][j]-'0')/10;
                            s[i%2][j]-=10;
                            zmian=true;
                        }
                    }
                }
            }
        }
    }
    cout << odp << endl;
}