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
101
102
103
104
105
//Krzysztof Boryczka
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

#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 SIZE(x) ((int)(x).size())
#define pb push_back
#define st first
#define nd second
#define sp ' '
#define ent '\n'
#define WATCH(x) cout<<(#x)<<" is "<<(x)<<ent

//END OF TEMPLATE

const int N=2e5;
const ll mod=1e16;

int n;
ll t[N+5], cyf[N+5], befcyf[N+5];

ll log_10(ll v){
	ll odp=0;
	while(v){
		v/=10;
		odp++;
	}
	return odp;
}

ll pot(ll a, ll b){
	ll odp=1;
	FOR(i, 1, b){
		odp*=a;
	}
	return odp;
}

ll beg(int a, int b){ //0 - i-1<i, 1 - i-1>i, 2 - i-1==i
	ll v1=t[a], v2=t[b], v3=log_10(v1)-log_10(v2);
	FOR(i, 1, (int)(v3)){
		v1/=10;
	}
	if(v1<v2){
		return 0;
	}
	if(v1>v2){
		return 1;
	}
	return 2;
}

void rep(int a, int b){
	ll help=beg(a, b);
	if(help!=2){
		cyf[b]=cyf[a]+help;
	}
	else{
		if((t[a]+1)%pot(10, log_10(t[a])-cyf[b])){
			cyf[b]=cyf[a];
			t[b]=t[a]+1;
		}
		else{
			cyf[b]=cyf[a]+1;
		}
	}
	while(t[b]<=t[a]){
		t[b]*=10;
	}
	while(t[b]>=mod){
		t[b]/=10;
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll odp=0;
	cin>>n;
	FOR(i, 1, n){
		cin>>t[i];
	}
	FOR(i, 1, n){
		befcyf[i]=cyf[i]=log_10(t[i]);
	}
	FOR(i, 2, n){
		if(t[i-1]>=t[i]){
			rep(i-1, i);
		}
	}
	FOR(i, 1, n){
		odp+=cyf[i]-befcyf[i];
	}
	cout<<odp<<ent;
	return 0;
}