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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5;

int n, cntxd;
long long res, cnt, akt;
string now, x, q;
bool czy;

void solve1(){
	long long a;
	cin >> a;
	
	if(a > akt){
		akt = a;
		return;
	}
	
	x = to_string(a);
	if(x.size() == now.size()){
		res ++;
		cnt ++;
		a *= 10;
		akt = a;
		now += '0';
		return;
	}
	
	int zm = x.size() - 1;
	bool hm = false;
	q.clear();
	if(x[zm] == now[zm]){
		int it = now.size() - 1;
		int ble = it - zm;
		while(ble --){
			if(!hm and now[it] != '9'){
				q += char(now[it] + 1);
				hm = true;
			}else{
				if(now[it] == '9'){
					q += '0';
				}else{
					q += now[it];
				}
			}
			it --;
		}
		for(int i=q.size()-1; i>=0; i--){
			x += q[i];
		}
		if(!hm){
			x += '0';
		}
		int roz = x.size();
		res += roz - zm - 1;
		cnt += roz - cnt;
		now = x;
		return;
	}
	if(x[zm] > now[zm]){
		int roz1 = now.size();
		int roz2 = x.size();
		int it = roz1 - roz2;
		int cnt1 = it;
		for(int i=0; i<it; i++){
			x += '0';
		}
		cnt += cnt1 - cnt;
		res += cnt1;
		now = x;
		return;
	}
	
	int roz1 = now.size();
	int roz2 = x.size();
	int it = roz1 - roz2 + 1;
	int cnt1 = it;
	for(int i=0; i<it; i++){
		x += '0';
	}
	cnt += cnt1 - cnt;
	res += cnt1;
	now = x;
	return;
}

long long robto(string rr){
	long long pot = 1;
	long long liczba = 0;
	for(int i=0; i<10; i++){
		liczba += rr[i] - '0';
		liczba *= 10;
	}
	liczba /= 10;
	return liczba;
}

void solve2(){
	long long a;
	cin >> a;
	if(akt < a){
		res += cnt;
		akt = a;
		return;
	}
	if(akt == a){
		res += cnt;
		return;
	}
	x = to_string(a);
	int zm = x.size();
	if(10 == zm){
		cnt ++;
		res += cnt;
		akt = a;
		return;
	}
	
	res += cnt;
	res += 9 - zm;
	for(int i=0; i<10-zm; i++){
		a *= 10;
	}
	akt = a;
	return;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	cout.tie(0);
	cin >> n;

	cin >> akt;
	now = to_string(akt);
	n --;
//	cout << "\n";
	while(n --){
		if(!czy){
			solve1();
		}else{
		//	cout << " XD";
			solve2();
		}
		if(!czy and now.size() >= 18){
			czy = true;
			akt = robto(now);
			cnt = now.size() - 9;
		//	cntxd = now.size();
		//	cout << " wypisuje dane: " << cnt << " " << now << " " << akt << " " << res << "\n";
		}
	}
	
	cout << res << "\n";
	
	return 0;
}