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
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

unsigned long long int gry[200001];

int main()
{
	int n;
	cin>>n;
	unsigned long long int licznik=0;
	int breaker=1;
	double iloraz;
	int cyfry1;
	int cyfry2;
	
	for(int i=0;i<n;i++)
	{
		cin>>gry[i];
		//cout<<int(floor(double(gry[i])/double(pow(10,floor(int( log10(gry[i]) ) ) ) ) ) )%10<<endl;
	}
	
	for(int i=1;i<n;i++)
	{
		if(gry[i]<=gry[i-1])
		{
			breaker=1;
			while(breaker==1)
			{
				iloraz=double(gry[i-1])/double(gry[i]);
				//cout<<iloraz<<endl;
				cyfry1=floor(log10(gry[i]+pow(10,-10)));
				cyfry2=floor(log10(gry[i-1]+pow(10,-10)));
				gry[i]=gry[i]*pow(10,max(cyfry2-cyfry1,1));
				licznik+=max(1,cyfry2-cyfry1);
				if(gry[i]>gry[i-1])
				{
					//cout<<gry[i]<<"   "<<gry[i-1]<<endl;
					break;
				}else{
					//cout<<gry[i]<<"   "<<gry[i-1]<<endl;
					if(cyfry2-cyfry1==1)
					{
						//cout<<"jest"<<endl;
						if(gry[i-1]%10==9)
						{
							gry[i]=10*gry[i];
							licznik++;
							breaker=1;
							break;
						}
					}
					if(int(floor(double(gry[i])/double(pow(10,floor(int( log10(gry[i]) ) ) ) ) ) )%10<int(floor(double(gry[i-1])/double(pow(10,floor(int( log10(gry[i-1]) ) ) ) ) ) )%10)
					{
							gry[i]=10*gry[i];
							licznik++;
							breaker=1;
							break;
					}
					if(gry[i-1]-gry[i]<pow(10,cyfry2-cyfry1))
					{
						gry[i]=gry[i-1];
					}
					if(gry[i-1]-gry[i]==round(pow(10,cyfry2-cyfry1)))
					{
						gry[i]=10*gry[i];
						licznik++;
						breaker=1;
						break;
					}
					
					for(int j=0;j<int(pow(10,floor(log10(iloraz))))-1;j=j+1)
					{
						gry[i]++;
						if(gry[i]>gry[i-1])
						{
							breaker=0;
							//cout<<gry[i]<<"   "<<gry[i-1]<<endl;
							break;
						}
						//cout<<gry[i]<<"   "<<gry[i-1]<<endl;
						if(j==int(pow(10,floor(log10(iloraz))))-2)
						{
							gry[i]-=int(pow(10,floor(log10(iloraz))))-1;
							//cout<<gry[i]<<"   "<<gry[i-1]<<endl;
						}
					}
				}
				//cout<<gry[i]<<"    "<<gry[i-1]<<endl;
			}
		}
	
	}
	/*cout<<endl;
	for(int i=0;i<n;i++)
	{
		cout<<gry[i]<<endl;
	}*/
	
	cout<<licznik<<endl;
	
	return 0;
}