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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include<bits/stdc++.h>
#define VAR(i,n) __typeof(n) i = (n)
#define loop(i,j,s) for(int i=j;i<s;i++)
#define loopback(i,j,s) for(int i=j;i>=s;i--)
#define foreach(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define pln( x ) cout << x << "\n"
#define ps( x ) cout << x << " "
#define entr cout << "\n"
#define pcnt(i) __builtin_popcount(i)
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define SIZE(c) (c).size()
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef vector<int> VI;
const int INFTY=20000000;
const int MAX=500100;
const int MOD=10000000;

void coutTab(int* tab,int n){
	loop(i,0,n){
		cout<<tab[i]<<" ";
	}
	cout<<"\n";
}
//------------------------------------------
int nums(ll a){
	if(a==0) return 1;
	int i=0;
	while(a>0){
		i++;
		a/=10;
	}
	return i;
}
struct Num{
	ll a,b,c; // a*10^b + c, a <= 10^9, c<=200000
	ll toLL(){
		if(nums(a)+b>16)
			return -1;
		ll res = a;
		loop(i,0,b) res*=10;
		res+=c;
		return res;	
	}
	int numsIfBig(){
		return nums(a)+b;
	}
	int numsIfSmall(){
		return nums(toLL());
	}
};
ll rev(ll a){
	ll res=0;
	while(a>0){
		res = res*10 + a%10;
		a/=10;
	}
	return res;
}
bool isBaseCont(ll a, ll b){
	int i=0;
	while(a%10==0){ a/=10; i++;} 
	a=rev(a);
	b=rev(b);
	while(a>0&&b>0&&a%10==b%10){
		a/=10;
		b/=10;
	}
	while(i>0&&b%10==0){
		b/=10;
		i--;
	}
	return (a==0&&i==0);
}
bool isBaseGreater(ll a, ll b){
	a=rev(a);
	b=rev(b);
	while(a%10==b%10){
		a/=10;
		b/=10;
	}
	return a%10 > b%10;
}
int main(){
	ios_base::sync_with_stdio(0);
	int N;
	cin>>N;
	Num cn;
	ll a;
	cin>>cn.a;
	cn.b=0;
	cn.c=0;
	ll res = 0;
	loop(i,1,N){
		cin>>a;
		ll cur = cn.toLL();
		//ps(a);
		//ps(cur);
		if(cur==-1){
			//ps(cn.a);
			if(isBaseCont(a,cn.a)){
				//ps(a);ps(cn.a);ps("equal");
				cn.c++;
				//cn.a=a;
				res+=cn.numsIfBig()-nums(a);
				//res+=cn.b;
				//cn.a=a;
			}else if(isBaseGreater(a,cn.a)){
				//ps("greater"); ps(cn.numsIfBig());ps("endgret");
				cn.b = cn.numsIfBig()-nums(a);
				cn.a=a;
				res+=cn.b;
			}else{
				cn.b = cn.numsIfBig()-nums(a)+1;
				cn.c=0;
				cn.a=a;
				res+=cn.b;
			}
		}else{
			if(cur < a){
				cn.a=a;
				cn.b=0;
				cn.c=0;
			}else if(cur == a){
				cn.b++;
				res++;
			}else{
				ll oa=a;
				loop(j,0,nums(cur)-nums(oa)){ a*=10; res++; }
				if(a<=cur){
					if(isBaseCont(oa,cur+1)){
						a=cur+1;
					}else{
						res++;
						a*=10;
					}
				}
				cn.a=a;
				cn.b=0;
				cn.c=0;
			}
		}
		//ps(res);
		//pln(cn.toLL());
	}
	pln(res);
}