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
#define _CRT_SECURE_NO_WARNINGS 1
#define _WINSOCK_DEPRECATED_NO_WARNINGS 1
//
#include <cstdio>
#include <vector>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);

	long long max = 1000000000000000;
	long long shift = 0;
	long long last = 0;
	long long result = 0;

	for (int i = 1; i <= n; ++i)
	{
		long long c;
		scanf("%lld", &c);

		if (last >= c)
		{
			int lastCount = (int)log10(last);
			int cCount = (int)log10(c);

			long long delta = lastCount - cCount;
			long long mask = (long long)pow(10, delta);
			long long lastprefix = last / mask;

			if (lastprefix < c)
			{
				result += delta + shift;
				last = c * mask;
			}
			if (lastprefix > c)
			{
				result += delta + 1 + shift;
				last = c * mask * 10;
			}
			if (lastprefix == c)
			{
				long long lastRest = last % mask;
				long long newRest = lastRest + 1;
				if (newRest < mask)
				{
					result += delta + shift;
					last = c * mask + newRest;
				}
				else
				{
					result += delta + 1 + shift;
					last = c * mask * 10;
				}
			}
		}
		else
		{
		   last = c;
	    }

		while (last > max)
		{
			last /= 10;
			shift++;
		}
	}

	printf("%lld", result);
}


//const int val = 1e9;
//int main() {
//	const int n = 2e5;
//	printf("%d\n", n);
//	for (int i = 0; i < n; ++i)
//		printf("%lld\n", 1 + (i * 1ll * i) % val);
//}