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

using namespace std;
long long int pot10[12] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000};
int l (long long int n) {
	for (int i = 0; i < 12; i++) {
		if (n < pot10[i]) return i+1;
	}
}
int nth (int n, int k) {
		
}

long long int n, tab[200001];

int main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> tab[i];
	}
	
	int wyn = 0;

	for (int i = 1; i < n; i++) {
		int l1 = l(tab[i-1]), l2 = l(tab[i]);
		if (l1 == l2) {
			if (tab[i] <= tab[i-1]) {
				wyn++;
				tab[i] *= 10;
			}
		}
		else if (l1 > l2) {
			//cout << i << ": " << tab[i] << " " << tab[i-1] << " " << l1 - l2 << " " << pot10[l1-l2] << endl;
			if (tab[i-1] < tab[i] * pot10[l1-l2]) {
				
				tab[i] = tab[i] * pot10[l1-l2];
				wyn += l1 - l2;
			}
			else if ( tab[i-1] / pot10[l1-l2] == tab[i] ) {
				int ile9 = 0, x = tab[i-1];
				for (int j = 0; j < l2; j++) {
					if (x%10 == 9) {
						ile9++;
						x/=10;
					} else break;
				}
				if (ile9 == l1-l2) {
					tab[i] = tab[i] * pot10[l1-l2+1];
					wyn += l1 + l2 + 1;
				}
				tab[i] *= pot10[l1-l2-ile9];
				tab[i] += (tab[i-1]%pot10[l1-l2])/pot10[ile9] + 1;
				tab[i] *= pot10[ile9];
			}
			else {
				tab[i] = tab[i] * pot10[l1-l2+1];
				wyn += l1 - l2 + 1;
			}
			
		}
		//cout << endl << tab[i] << endl;
	}
	//for (int i = 0; i < n; i++) cout << tab[i] << " ";
	cout << wyn;
}