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
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <cmath>

using namespace std;

const long long TRESHOLD = 1e9 * 1e6;

inline void solve() {
	int games;
	long long price;
	long long prefix;
	bool is_over_treshold = false;
	long long length_over_treshold = 0;
	long long result = 0;

	cin >> games;
	cin >> prefix;

	for (int i = 1; i < games; ++i) {
		cin >> price;

		if (!is_over_treshold) {
			if (prefix < price) {
				prefix = price;
			} else {
				++prefix;

				long long tmp = prefix;
				int shift = 0;
				while (tmp > price) {
					tmp /= 10;
					++shift;
				}

				if (tmp != price) {
					while (price < prefix) {
						price *= 10;
						++result;
					}
					prefix = price;
				} else {
					result += shift;
				}
			}

			if (prefix > TRESHOLD) {
				is_over_treshold = true;
			}
		} else {
			result += length_over_treshold;

			long long tmp = prefix;
			int shift = 0;
			while (tmp > price) {
				tmp /= 10;
				++shift;
			}

			if (tmp != price) {
				while (price < prefix) {
					price *= 10;
					++result;
				}
				prefix = price;
			} else {
				result += shift;
			}

			if (prefix >= 10 * TRESHOLD) {
				++length_over_treshold;
				prefix /= 10;
			}
		}
	}

	cout << result << endl;
}

int main(int argc, char **argv) {
	ios_base::sync_with_stdio(0);

	solve();

	return 0;
}