#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
int n;
LL res;
string s;
int Length;
string change(string a, string b){
if((int)b.size() > Length){
Length = b.size();
return b;
}
if((int)b.size() == Length){
if(a < b)
return b;
b.push_back('0');
Length = b.size();
return b;
}
bool eq = true, better = false;
for(int i = 0; i < (int)b.size(); ++i){
better |= eq && a[i] < b[i];
eq &= a[i] == b[i];
}
if(better){
for(int i = 0; i < b.size(); ++i)
a[i] = b[i];
for(int i = b.size(); i < (int)a.size(); ++i)
a[i] = '0';
return a;
}
if(eq){
bool can = Length > 16;
if(!can)
for(int i = b.size(); i < (int)a.size(); ++i)
can |= a[i] < '9';
if(!can){
for(int i = b.size(); i < (int)a.size(); ++i)
a[i] = '0';
++Length;
a.push_back('0');
return a;
}
a[a.size() - 1] += 1;
for(int i = a.size() - 1; i >= 0; --i){
if(a[i] <= '9')
break;
a[i] = '0';
a[i - 1]++;
}
return a;
}
++Length;
for(int i = 0; i < (int)b.size(); ++i)
a[i] = b[i];
for(int i = b.size(); i < (int)a.size(); ++i)
a[i] = '0';
if(a.size() < 16)
a.push_back('0');
return a;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for(int i = 1; i <= n; ++i){
string a;
cin >> a;
s = change(s, a);
res += Length - a.size();
// cout << s << " ";
}
cout << res << "\n";
return 0;
}