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
#include<stdio.h>
#include<math.h>

int main()
{
    long long n,j, a, a_old, m, t, counter = 1, result=0, mult, lenght, maximum=10e17;
    long a_len, a_old_len;

    scanf("%lld", &n);
    scanf("%lld", &m);
    //printf("%lld\n", m);
    a_old = m;

    t = m;
    a_old_len = 0;
    for(t;t;t/=10, a_old_len++);

    for(long i=1; i<n; i++)
    {
        scanf("%lld", &a);
        //printf("%lld\n", a);
        t = a;
        a_len = 0;
        for(t;t;t/=10, a_len++);
        if(m<maximum)
        {
            mult = 1;
            counter=0;
            a_old = a;
            while(m-a>=mult)
            {
                mult*=10;
                a*=10;
                counter++;
            }

            if(m-a>=0)
            {
                if(counter>0)
                {
                    if((m-a)%mult==mult-1)
                    {
                        a*=10;
                        counter++;
                    }
                    else
                        a+=m-a+1;
                }
                else
                {
                    a*=10;
                    counter++;
                }
            }
            result+=counter;

            //printf("[%lld][%lld]\n", a, counter);

            m = a;
            for(t=m,lenght=0;t;t/=10, lenght++);

        }else
        {
            if(a>a_old)
            {
                t = a;
                int a_len = 0;
                for(t;t;t/=10, a_len++);

                /*t = a_old;
                int a_old_len = 0;
                for(t;t;t/=10,a_old_len++);
                */

                t=a_old;
                for(j=0;j<a_len-a_old_len; j++, t*=10);

                if(a<t) //bylo <=
                {
                    lenght++;
                }

                result+=lenght-a_len;
                //printf("a. [%lld",a);
                //for(j=0;j<lenght-a_len;j++,printf("0"));
                //printf("]->[%lld]\n", lenght-a_len);

            }else if(a<=a_old)
            {
                /*t = a_old;
                int a_old_len = 0;
                for(t;t;t/=10,a_old_len++);*/

                t=a;
                for(j=0,mult=1;j<a_old_len-a_len; j++, t*=10,mult*=10);
                //printf("b. t=%lld mult=%lld\n",t, mult);

                if(a_old>t) //bylo >=
                {
                    if(a_old-t+1>=mult)
                        lenght++;
                }
                result+=lenght-a_len;
                //printf("b. [%lld",a);
                //for(j=0;j<lenght-a_len;j++,printf("0"));
                //printf("]->[%lld]\n", lenght-a_len);
            }
            a_old = a;
        }
        a_old_len = a_len;
    }

    printf("%lld", result);

    return 0;
}