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
#include <cstdio>
#define MAXN 200100
#define inf 0x7fffffff
int tab[ MAXN ];
int main()
{
	int n;
	scanf( "%d", &n );
	for( int i = 0; i < n; ++i ) scanf ("%d", tab + i );
	int pop = inf;
	int l = 0;
	long long int wynik = 0;
	for( int i = n-1; i >= 0; --i )
	{
		if( tab[ i ] >= pop )
		{
			long long int a = pop;
			long long int temp = 0;
			bool started = false;
			while( tab[i] >= a )
			{
				if( started ) a -= 9;
				a *= 10;
				a += 9;
				++temp;
				started = true;
			}
			for( int j = 0; j < 10; ++j )
			{
				--a;
				if( tab[j] >= a )
				{
					++a;
					break;
				}
			}
			
			wynik += temp * l;
		}
		++l;
		pop = tab[ i ];
	}
	printf("%lld", wynik );
}