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
#include<iostream>
#define MAX 200002
#define LL unsigned long long
using namespace std;
 int d=0,ileDodano=0;
 LL tab[MAX];
int len(LL a, LL *tab){
 if (a>0){
     len(a/10,tab);
     tab[d] = a%10;
     d++;
 }
 return d;
}

int policz(LL a,LL b){
 LL tabA[20]={-1},tabB[20]={-1};
 int dA, dB,ile=0;
 d=0;
 dA = len(a,tabA);
 d=0;
 dB = len(b,tabB);
 if (dA==dB) {ileDodano++; b*=10; return b;}
 int i=0;
  while (tabA[i]==tabB[i] && i<dB) i++;

  if (i==dB){

    for (int j=i;j<dA;j++){
        if (tabA[j]<9) {
            b=a+1;
            ileDodano+=(dA-dB);
            return b;
        }
    }
    for (int j=i;j<dA+1;j++)
        b=b*10;
    ileDodano+=(dA-dB)+1;
    return b;
  }

  ile= dA-i-1;
  if (tabA[i]>tabB[i]){
       ile++;
  }
   for(int i=0;i<ile;i++)
     b=b*10;
  ileDodano+=ile;
  return b;
}
int main(){
    ios_base::sync_with_stdio(0);
  cin.tie(0);
 int n;
 LL tab[MAX],d1,d2;
 cin >>n;
 //cin >>tab[0]>>tab[1];
 //cout <<policz(tab[0],tab[1])<<endl;
// cout <<ileDodano<<endl;

cin >>tab[0];
 for (int i=1;i<n;i++){
    cin >>tab[i];
    if (tab[i-1]==tab[i]){
        ileDodano++;
        tab[i]*=10;
    }
    else if (tab[i-1]>tab[i]){
       tab[i]=policz(tab[i-1],tab[i]);
    }
    }
//for(int i=0;i<n;i++)cout <<tab[i]<<" ";


 cout <<ileDodano<<endl;
}