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
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORR(i, n) for (int i = 1; i <= n; i++)
#define FORi(n) for (int i = 0; i < n; i++)

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   long long mx = 0, ml = 0, wynik = 0, inMx = 0;
   string ms = "";
   for (int i = 0; i < n; i++)
   {
      // cout << mx << "-\n";
      long long s;
      cin >> s;
      string cp = to_string(s);
      long long l = cp.size();
      if (mx < s)
      {
         mx = s;
         ml = l;
         ms = cp;
         continue;
      }
      else
      {
         if (cp.size() == ml)
         {
            ml++;
            mx = s * 10;
            ms += '0';
            wynik++;
            continue;
         }
         int win = 1;
         for (int j = 0; j < l; j++)
         {
            if ((cp[j] > ms[j]) && win == 1)
            {
               //cout << cp[j] << " " << ms[j] << "\n";
               win = 3;
               break;
            }
            if (cp[j] != ms[j])
               win = 0;
            if (j == l - 1 && win == 0)
            {
               win = 2;
            }
         }
         // cout << "=" << win << "\n";
         if (win == 3)
         {
            //   cout << "l = " << l << " ml = " << ml << " s = " << s << "\n";
            mx = s;
            int cml = ml;
            for (int j = l; j < cml; j++)
            {
               mx *= 10;
               wynik++;
            }
            ms = to_string(mx);
            ml = ms.size();
         }
         if (win == 2)
         {

            mx = s;
            for (int j = l; j <= ml; j++)
            {
               mx *= 10;
               wynik++;
            }
            ms = to_string(mx);
            ml = ms.size();
         }
         if (win == 1)
         {
            mx++;
            ms = to_string(mx);
            int win = 1;
            for (int j = 0; j < l; j++)
            {
               if (cp[j] != ms[j])
                  win = 0;
            }
            if (win == 0)
            {
               mx = s * 10;
               for (int j = l; j < ml; j++)
               {
                  mx *= 10;
                  wynik++;
               }
               ms = to_string(mx);
               ml = ms.size();
            }
            else
            {
               wynik += ml - l;
            }
            continue;
         }
      }
   }
   // cout << mx;
   cout << wynik;
   return 0;
}