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
#include <stdio.h>

unsigned long long int lt[100050]; //last tab
unsigned long long int l; //last
long long int P[] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000,1000000000000};

int size_count(long long int x) {
  int i=1;
  while(x>=P[i] && i<12) i++;
  return i;
}

int main() {
  long long int s = 0;
  int N;
  long long int b,c,d;
  int PA[2]={0,0}, NA[2]={0,0}, A[2]={0,0};
  
  long long int a_t1, a_t2;
  int st;


  scanf("%d", &N);
  N--;
  scanf("%lli", &b);
  //printf("%lli____\n", b);
  A[0] = size_count(b);
  while(N--) {
    scanf("%lli", &c);
    //printf("%lli____\n", c);
    A[1] = size_count(c);

    if(A[1] > A[0] + PA[0]) {
      //printf("A[1] > A[0] + PA[0]\n");
      PA[0] = 0;
      NA[0] = 0;
    } else if(A[1] == A[0] + PA[0]) {
      //printf("A[1] == A[0] + PA[0]\n");
      b *= P[PA[0]];
      if(c<=b) {
        //printf("%lli <= %lli\n", c,b);
        PA[0] = 1;
        s++;
      } else {
        //printf("%lli > %lli\n", c,b);
        PA[0]=0;
      }
      NA[0]=0;
    } else {
      //printf("A[1] < A[0] + PA[0]\n");
      d=c;
      a_t2=a_t1=0;
      if(A[1]<A[0]) {
        //printf("A[1] < A[0]\n");
        a_t2 = a_t1 = A[0] - A[1];
        d *= P[a_t1];
        d += (b%P[a_t1]);
      } else if(A[1] > A[0]) {
        //printf("A[1] > A[0]\n");
        a_t1 = A[1] - A[0]; //+
        a_t2 = A[0] - A[1]; //-
        b *= P[a_t1];
        b += NA[0]/P[a_t1];
      }
      if(d<b) {
        //printf("%lli <= %lli\n", d,b);
        PA[0] += a_t2 + 1;
        NA[0] = 0;
      } else if(b == d) {
        //printf("%lli = %lli\n", d,b);
        st = size_count(NA[0]);
        NA[0]++;
        if(NA[0] >= P[st]) {
          NA[0] = 0;
          PA[0]++;
        }
        PA[0] += a_t2;
      } else {//c>b
        //printf("%lli > %lli\n", d,b);
        PA[0] = PA[0] + a_t2;
        NA[0] = 0;
      }
      s += PA[0];

    }
    A[0] = A[1];
    b = c;
    //printf("s = %d\n\n\n\n\n", s);
  }

  printf("%lli\n", s);
  return 0;
}