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
#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define FORE(i, t) for(__typeof(t.begin())i=t.begin();i!=t.end();++i)
#define SZ(x) int((x).size())
#define REP(i, n) for(int i=0,_=(n);i<_;++i)
#define FOR(i, a, b) for(int i=(a),_=(b);i<=_;++i)
#define FORD(i, a, b) for(int i=(a),_=(b);i>=_;--i)

#ifdef DEBUG
#define DEB(x) (cerr << x)
#else
#define DEB(x)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;

const int INF = 1e9 + 9;


pil inline compute_next(const ll &x, const ll &last) {
    if (x > last) {
        return pil(0, x);
    }
    int log_x = floorl(log10l(x));
    int log_last = floorl(log10l(last));
    int d = log_last - log_x;
    ll multiplier = powl(10, d);
    ll y = x * multiplier;
    if (y > last) {
        return pil(d, y);
    }
    ll z = last + 1;
    if ((z / multiplier) == x) {
        return pil(d, z);
    }
    return pil(d + 1, y * 10LL);
}

void inline one() {
    int n;
    cin >> n;
//    vi t(n);
    ll last = 0;
    ll result = 0;
    ll base = 0;
    REP (i, n) {
        ll x;
        cin >> x;
//        cout << "x = " << x << " log = " << floorl(log10l((long double)x)) << "\n";

        pil next = compute_next(x, last);

        int added = next.first;
        last = next.second;

        result += added + base;
        while (last >= 1e16) {
            last /= 10LL;
            base += 1;
        }

        DEB("x=" << x << " -> " << last << " (added: " << added << ")\n");
    }
    cout << result << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    //int z; cin >> z; while(z--)
    one();
}