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
#include <iostream>
#include <stdio.h>
using namespace std;

  int main() {
    long n = 0;
    cin >> n;
    long current = 0;
    cin >> current;
    long tail = 0;
    long result = 0;

    cout << n << current;
    for (long iPrice = 0; iPrice < n - 1; iPrice++) {
      long next = 0;
      cin >> next;
      cout << next;

      long nines = 0;
      long temp = next;
      while (temp <= current) {
        temp *= 10;
        temp += 9;
        nines++;
      }

      long zeroes = 0;
      temp = next;
      while (temp <= current) {
        temp *= 10;
        zeroes++;
      }

      if (nines < zeroes) {
        current = current + 1;
        result += nines;
      } else {
        current = temp;
        result += zeroes;
      }
      result += tail;

      // cut long number
      while (current > (1L << 55)) {
        current /= 10;
        tail++;
      }
    }
    
    return 0;
  }