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
#include<iostream>
#include<cmath>
using namespace std;

int dlugosc(int a){
  int s = 0;
  while(a > 0){
    a = (a-a%10)/10;
    s++;
  }
  return s;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  unsigned long long n, suma = 0,p = 0,a,k,l;
  cin >> n;
  for(int i = 0;i < n;++i){
    cin >> a;
    while(a <= p){
      a *= 10;
      k = dlugosc(p) - dlugosc(a);
      l = pow(10,k);
      if(l > 1){
        if(a - a%10 == (p / l) - (p / l)%10){
          if((p / l)%10 == 9){
            a *= 10;
          }
          else
            a += (p / l)%10 - a%10;
        }
      }
      else{
        if(a - a%10 == p - p%10){
          if(p%10 == 9){
            a *= 10;
          }
          else
            a += p%10 - a%10 + 1;
        }
      }
      suma++;
    }
    //cout << a << " ";
    p = a;
  }
  cout /*<< '\n' */<< suma;
}