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

#define ulli long long int

/*
6
1 5 2 16 17 3000

11
1 5 2 16 16 16 16 17 3000 300 400

13
16 16 16 16 16 16 16 16 16 16 16 16 16

10
1 2 3 4 500 6 7 8 9 1
*/

using namespace std;

ulli log10f(ulli a)
{
	ulli ile=0;
	do
	{
		a/=10;
		ile++;
	}
	while(a>0);
	return ile;
}

int main()
{
	ulli tab[200000]={}, n, ile, dopis, dldop, kand1, kand2, oldx;
	
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> tab[i];
	}
	dopis=0;
	ile=0;
	dldop=log10f(dopis)+1;
	oldx=tab[0];
	for(int i=1;i<n;i++)
	{
		if(tab[i-1]>=tab[i])
		{
			kand1=log10f(tab[i-1]);
			kand2=log10f(tab[i]);
			tab[i]*=pow(10, kand1-kand2);
			ile+=kand1-kand2;
			if(tab[i-1]-tab[i]>=0 && log10f(tab[i-1]-tab[i]+1)<=kand1-kand2)
			{
				tab[i]+=tab[i-1]-tab[i]+1;
				dopis=0;
			}
			else if(tab[i-1]>=tab[i])
			{
				if(oldx!=tab[i]) dopis=0;
				dldop=log10f(dopis);
				tab[i]=tab[i]*pow(10, dldop)+dopis;
				ile+=dldop;
				dopis++;
				oldx=tab[i];
			}
			else
			{
				dopis=0;
			}
			//cout << tab[i] << endl;
		}
		else
		{
			dopis=0;
		}
	}
	
	cout << ile;
	return 0;
}