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
#include <iostream>

using namespace std;

int main()
{
    int n, x = 0;

    cin >> n;

    int a[n];

    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = 1; i < n; i++)
    {
        while (a[i] <= a[i - 1])
        {
            if (a[i] == a[i - 1] / 10)
            {
                if (a[i - 1] % 10 == 9)
                {
                    a[i] *= 100;
                    x = x + 2;
                }
                else
                {
                    a[i] = a[i] * 10 + a[i - 1] % 10 + 1;
                    x++;
                }

            }
            else
            {
                a[i] = a[i] * 10;
                x++;
            }
        }
    }

    cout << x;

    return 0;
}