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
#include <bits/stdc++.h>
using namespace std;


int l(long long x) {
	int res = 0;
	while (x) {
		res++;
		x /= 10;
	}
	return res;
}
long long getMini(long long x, long long len) {
	int d = l(x);
	for (int a = 1; a <= len - d; a++) {
		x *= 10;
		x += 0;
	}
	return x;
}
long long getMaks(long long x, long long len) {
	int d = l(x);
	for (int a = 1; a <= len - d; a++) {
		x *= 10;
		x += 9;
	}
	return x;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	//cin >> n;
	long long n, x, pre, mini, maks, len, ans = 0, add = 0;
	cin >> n;
	for (int a = 1; a <= n; a++) {
		cin >> x;
		if (a != 1) {
			len = l(pre);
			mini = getMini(x, len);
			maks = getMaks(x, len);
			if (mini > pre + 1) {
				if (l(x) > len) len = l(x);
				ans += len - l(x) + add;
				pre = mini;
			}
			else if (pre + 1 >= mini && pre + 1 <= maks) {
				if (l(x) > len) len = l(x);
				ans += len - l(x) + add;
				pre++;
			}
			else if (pre + 1 > maks) {
				ans += len + 1 - l(x) + add;
				len++;
				if (len > 15) {
					len--;
					add++;
				}
				pre = getMini(x, len);
			}
		}
		else {
			pre = x;
			len = l(x);
		}
		//cout << a << " " << pre << " " << ans << endl;
	}
	cout << ans << endl;

    return 0;
}