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

using namespace std;
int n;

int digits(long long int x) {
  int d = 0;
  do {
    d++;
    x/=10;
  } while(x > 0);

  return d;
}

int max(int x, int y) { return x > y ? x : y; }

int main() {
  ios::sync_with_stdio(false);

  cin >> n;
  long long int c = 0;
  long long int res = 0;
  long long int d;
  int cuted = 0;
  
  for(int i = 0; i < n; i++) {
    cin >> d;

    long long int min_d = d;
    long long int max_d = d;

    int dc = digits(c);
    
    for(int j = dc - digits(min_d); j > 0; j--) {
      min_d *= 10;
      max_d = max_d * 10 + 9;
      res++;
    }

    if(min_d > c) {
      c = min_d;
    } else if(max_d <= c) {
      if(dc > 15) {
        cuted++;
        c = min_d;
      } else {
        c = min_d * 10;
        res++;
      }
    } else {
      c++;
    }

    res += cuted;
  }

  cout << res;
  return 0;
}