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
#include <bits/stdc++.h>
using namespace std;

typedef long long int lli;

const lli MIL = 100000;
// vector<int> v, pre;

vector<lli> pot;

int lg(lli a) {
	lli p = 1;
	for (int i=0; i<100; i++) {
		if (p > a)
			return i;
		p *= 10;
	}
	
	assert(0);
}

int main() {
	pot.push_back(1);
	for (int i=1; i<100; i++)
		pot.push_back(pot.back()*10);
	
	int n;
	scanf("%d", &n);
	
	lli a;
	lli res = 0;
	lli pre = 0;
	lli lp = 0;
	
	while (n--) {
// 		printf("  %lld\n", pre);
		scanf("%lld", &a);
		
		int l = lg(a);
		
		if (a > pre) {
			pre = a;
			lp = l;
			continue;
		}
		
		if (a*pot[lp-l] > pre) {
			pre = a*pot[lp-l];
			res += lp-l;
			continue;
		}
		
		if (pre >= (a+1)*pot[lp-l]-1) {
			pre = a*pot[lp-l+1];
			res += lp-l+1;
			lp++;
			if (lp > 16)
				break;
			
			continue;
		}
		
		pre++;
		res += lp-l;
	}
	
	const lli CUT = 1000000;
	
	lli cnt = lg(CUT-1);
	pre /= CUT;
	lp = lg(pre);
	
	for (int iter=0; iter<n; iter++) {
// 		printf("  %lld (%lld)\n", pre, cnt);
		scanf("%lld", &a);
		
		int l = lg(a);
// 		printf("[%lld, lg %d %d, %lld, %lld]", a, l, lp, pot[lp-l], a*pot[lp-l]);
		
		if (a*pot[lp-l] > pre) {
			pre = a*pot[lp-l];
			res += lp-l+cnt;
			continue;
		}
		
		if (pre >= (a+1)*pot[lp-l]-1) {
			pre = a*pot[lp-l];
			cnt++;
			res += lp-l+cnt;
			continue;
		}
		
		res += cnt+lp-l;
	}
	
	printf("%lld\n", res);
	
	return 0;
}