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

struct Number {
	int m, e;
	void Reduce() { for (; m % 10 == 0; m /= 10) e++; }
	Number() { int x; scanf("%d", &x); m = x; e = 0; }
	int MakeGreaterThan(Number& o) {
		for (; o.m <= 100000000 && o.m < m; o.m *= 10) o.e--;
		int q = o.m;
		int de = 0;
		for (;; q /= 10, de++)
			if (q == m) {
				m = o.m;
				e = std::max(o.e, 0);
				return de + e;
			} else if (q < m) {
				e = std::max(o.e + de, 0);
				return e;
			}
	}
};

int main()
{
	int n;
	long long total = 0;
	scanf("%d", &n);
	Number a;
	a.Reduce();
	while (--n > 0) {
		Number b;
		int res = b.MakeGreaterThan(a);
		total += res;
		b.Reduce();
		a = b;
	}
	printf("%lld\n", total);
	return 0;
}