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
// Nowy kontrakt [B].cpp : Defines the entry point for the console application.
//

#include <bits/stdc++.h>
using namespace std;
long long fix(string a, string &b) {
	if (a.length() < b.length()) return 0;
	if (a.length() == b.length()) {
		if (a < b) return 0;
		b += "0";
		return 1;
	}
	int i = 0;
	while (i<b.length() && a[i] == b[i]) i++;
	if (i == b.length()) {
		int j = a.length() - 1;
		while (j>0 && a[j] == '9') {
			j--;
		}
		if (j + 1 == i) {
			int res = 0;
			while (b.length() < a.length()) {
				b += "0";
				res++;
			}
			b += "0";
			res++;
			return res;
		}
		int res = 0;
		for (int k = b.length(); k < a.length(); k++) {
			res++;
			if (k < j) b += a[k];
			if (k == j) b += (a[k] + 1);
			if (k > j) b += '0';
		}
		return res;
	}
	int res = 0;
	for (int k = b.length(); k < a.length(); k++) {
		res++;
		b += "0";
	}
	if (a[i] > b[i]) {
		b += "0";
		res++;
	}
	return res;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<string> arr(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	long long res = 0;
	for (int i = 1; i < n; i++) {
		res += fix(arr[i - 1], arr[i]);
	}
	cout << res << endl;
    return 0;
}