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
# include <cstdio>


const long long MAX_TOTAL_GAMES = 200001;
const long long MAX_GAME_PRICE = 1000000001;
const long long MAX_CHECKED_PRICE = 999999999999999;


int main() {
  long long total_games;
  long long previous_price;
  long long current_price;
  long long total_digits = 0;
  long long previous_digits_above_checked = 0;
  
  scanf( "%lld", & total_games );
  scanf( "%lld", & previous_price );

  for ( int current_num = 1; current_num < total_games; current_num ++ ) {
    scanf( "%lld", & current_price );
    long long current_added_digits = 0;
    long long current_mod = 1;
    long long current_max = current_price;
    while ( current_max < MAX_CHECKED_PRICE && current_max <= previous_price ) {
      current_max = current_max * 10 + 9;
      current_mod *= 10;
      current_added_digits ++;
    }

    if ( current_added_digits == 0 ) {
      previous_price = current_price;
      continue;
    }
    /*
    if ( current_max > previous_price && previous_price <= MAX_CHECKED_PRICE ) {
      current_price = current_price * current_mod;
      if ( current_price <= previous_price ) {
        current_price += ( previous_price % current_mod ) + 1;
      }
      total_digits += current_added_digits;
    }
    if ( current_max > previous_price && previous_price > MAX_CHECKED_PRICE ) {
      current_price = current_price * current_mod;
      if ( current_price <= previous_price ) {
        current_price += ( previous_price % current_mod ) + 1;
      }
      total_digits += current_added_digits + previous_digits_above_checked;
    }
    */
    current_price *= current_mod;
    if ( current_max > previous_price ) {
      if ( current_price <= previous_price ) {
        current_price += ( previous_price % current_mod ) + 1;
      }
    }
    else {
      previous_digits_above_checked ++;
    }
    total_digits += current_added_digits + previous_digits_above_checked;
    previous_price = current_price;
  }
  printf( "%lld", total_digits );
  return 0;
}