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
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <bits/stdc++.h>
//brut
//nie mam czasu klepac tego na stringach xD
// sorry sprawdzian z geometri :(
using namespace std;
unsigned long long getint(){
	char c;unsigned long long temp=0;
	do{
		c=getchar_unlocked();
	}while(c<'0' || c>'9');
	do{
		temp=temp*10+c-'0';
		c=getchar_unlocked();
	}while(c>='0' && c<='9');
	return temp;
}
unsigned long long wynik;
unsigned long long tab[400000];
int main(){
    unsigned long long ile=getint();
    for(int i=0;i<ile;i++){
        tab[i]=getint();
    }
    /*for(int i=0;i<ile;i++){
        cout<<tab[i]<<" ";
    }cout<<endl;*/
    unsigned long long dltab;
    unsigned long long dlmin;
    unsigned long long roznica;
    unsigned long long minimum=tab[0];
    //unsigned long long dozmiany=0;

    for(int i=1;i<ile;i++){
        //if(i==2)cout<<minimum;
        if(tab[i]<=minimum){
            //cout<<i<<"."<<tab[i]<<"<"<<minimum<<endl;
            //musimy zwiekszyc tab[i]
            //dl tab[i]
            dltab=to_string(tab[i]).size();
            //dl minimum
            dlmin=to_string(minimum).size();
            roznica=dlmin-dltab;
            //dopisuje roznica zer
            wynik+=roznica;
            //cout<<roznica<<"a";
            long long pot=pow(10,(int)roznica);
            //cout<<pot<<"b";
            if(tab[i]>minimum/pot ){
                //jakie moze byc nowe minimum ?
                minimum=tab[i]*pot;
                //cout<<"a";
            }
            else if(tab[i]==minimum/pot && minimum%pot+1!=pot){
                minimum=tab[i]*pot+minimum%pot+1;
                //cout<<"b";
            }
            else{
                //dopisz jeszcze jedno zero
                minimum=tab[i]*pot*10;
                wynik++;
                
                //cout<<minimum;
                //cout<<"c";
            }
            //pamietac aby zupdatowac minimum
        }
        else {
            minimum=tab[i];
        }
    }
    cout<<wynik;
}