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

#define N 2000000

using namespace std;

long long paycheck[N];
long long new_paycheck[N];
int n;

int get_digits(long long number) {
        int digits = 0;
        do {
                number /= 10; digits++;
        } while (number != 0);
        return digits;
}

bool is_prefix(string foo, string foobar) {
	auto res = std::mismatch(foo.begin(), foo.end(), foobar.begin());
	if (res.first == foo.end())
		return true;
	return false;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &paycheck[i]);
	}
	long long prev = 0;
	long long prev_new = 0;
	long long acc = 0;
	for (int i = 0; i < n; i++) {
		if (paycheck[i] > prev_new) {
			new_paycheck[i] = paycheck[i];
			prev_new = new_paycheck[i];
			prev = paycheck[i];
			continue; 
		}
		int prev_digits = get_digits(prev_new);
		int curr_digits = get_digits(paycheck[i]);
		if (prev_digits == curr_digits) {
			if ((is_prefix(to_string(paycheck[i]), to_string(prev_new + 1)))) {
				new_paycheck[i] = prev_new + 1;
			} else {
				new_paycheck[i] = paycheck[i] * 10;
				acc++;
			}
		} else if (prev_digits > curr_digits) {
			if ((is_prefix(to_string(paycheck[i]), to_string(prev_new + 1)))) {
				new_paycheck[i] = prev_new + 1;
				int added_digits = get_digits(new_paycheck[i]) - get_digits(paycheck[i]);
				acc += added_digits;
			} else {
				new_paycheck[i] = paycheck[i];
				while (new_paycheck[i] <= prev_new) {
					new_paycheck[i] *= 10;
					acc += 1;
				}
			}
		} else {
		}
		prev_new = new_paycheck[i];
		prev = paycheck[i]; 
	}

	cout << acc << endl;
	return 0;
}