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
#include<cstdio>
#define LIMIT (100000000000000000LLU)
typedef unsigned long long u64;

int n;
u64 N, Z, count, x;

int cyfry(u64 x){
		if(x==0)return 1;
    int ile = 0;
    while(x > 0) {
        x/=10;
        ile++;
    }
    return ile;
}

int main() {
    scanf("%d", &n);
    for(int i=0;i<n;i++) {
        scanf("%llu", &x);
        
        if(N < x) {
            N = x;
        } else
        if(N == x) {
            count++;
            N = 10*x;
        } else {
					int a = cyfry(N), b = cyfry(x);
					u64 M = N;
					for(int j=0;j<a-b;j++)M/=10;

					if(M < x) {
						N = x;
						for(int j=0;j<a-b;j++) {
							N*=10;count+=1;
						}
						count+=Z;
					} else 
					if(M > x) {
						N = x;
						for(int j=0;j<a-b;j++) {
							N*=10;count+=1;
						}
						if(10*N >= LIMIT) {
							Z++;
						} else {
							N*=10;count++;
						}			
						count += Z;
					} else {
						if(Z>0) {
							count += a - b + Z;
						} else {
							for(int j=0;j<a-b;j++) {
								x*=10;count+=1;
							}
							u64 y = N - x;
							if(cyfry(y+1) <= a-b) {
								N++;
							} else {
								if(10 * x >= LIMIT) {
									N = x; Z++;
								} else {
									N = 10*x;
								}
								count++;

							}
						}
					}
        }
			//printf(">> %llu %llu\n", N, Z);
    }

    printf("%llu\n", count);
    return 0;
}