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
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef set<int> SI;
typedef multiset<int> MI;
typedef pair<int, int> PII;
typedef vector<pair<int, int> > VPII;

const int INF = 1000000001;
const LD EPS = 1e-9;
const int MOD = 1000000007;
const LL LLINF = 1000000000000000001;

//813437586

#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORD(i, b, e) for(int i = b; i >= e; i--)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define VAR(v, n) auto v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define GGL(x) "Case #" << x << ": "


/*************************** END OF TEMPLATE ***************************/

const int MAXN = 200046;

int n;
LL Wyn;
LL Tab[MAXN];
LL Pot[19];

int main()
{
	Pot[0] = 1;
	FOR (i, 1, 18)	Pot[i] = Pot[i-1] * 10;
	
	scanf ("%d", &n);
	FOR (i, 1, n)	scanf ("%lld", &Tab[i]);
	
	
//	int IleCyfr = to_string(Tab[1]).length();
//	LL Pref = Tab[1];
//	LL Suf = 0;
	int x = 2;
	FOR (i, 2, n)
	{
		x = i;
		if (Tab[i-1] < Tab[i])	continue;
		if (to_string(Tab[i-1]).length() > 15)
		{
//			cout << to_string(Tab[i-1]).length() << endl;
				break;
			}
		
		int L1 = to_string(Tab[i-1]).length();
		int L2 = to_string(Tab[i]).length();
		
		LL Left = Tab[i-1] / Pot[L1-L2];
		LL Right = Tab[i-1] % Pot[L1-L2];
		
		if (Left < Tab[i])
			Tab[i] *= Pot[L1-L2];
		else if (Left > Tab[i])
			Tab[i] *= Pot[L1-L2+1];
		else
		{
			if (to_string(Right+1).length() > L1-L2)
				Tab[i] *= Pot[L1-L2+1];
			else
				Tab[i] = Tab[i] * Pot[L1-L2] + Right + 1;
		}
//		cout << Tab[i] << endl;
		Wyn += to_string(Tab[i]).length() - L2;
		x = i + 1; 
	}
	LL IleCyfr = to_string(Tab[x-1]).length();
//	cout << IleCyfr << endl;
	for ( ; x <= n; x++)
	{
		int L1 = to_string(Tab[x-1]).length();
		int L2 = to_string(Tab[x]).length();
//		cout << L1 << " " << L2 << endl;
		LL Pref = Tab[x-1] / Pot[L1-L2];
		if (Pref > Tab[x])	++IleCyfr;
		Wyn += IleCyfr - L2;
		Tab[x] *= Pot[15-L2];
	}
	cout << Wyn;
}