Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8. Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
  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
// Author: Piotr Grzegorczyk (ud2@interia.eu)
// Task: PA2018/KON

#include <bits/stdc++.h>
using namespace std;

int intlen(long long x) {
	if (x==0)
		return 1;
	int r = 0;
	while (x) {
		x /= 10;
		r++;
	}	
	return r;
}

int getdigit(long long x, int i) {
	int c = intlen(x) - 1 - i;
	while(c-- > 0) 
		x /= 10;

	return x%10;
}

struct T {
	long long a;
	long long l;
	long long c;
	
	T(long long a, long long l, long long c) : a(a), l(l), c(c) {}
	
	int getlen() const {
		return intlen(a) + l;
	}
	
	int getdigit(int i) const {
		int al = intlen(a);
		int cl = intlen(c);
		
		if (i < al)
			return ::getdigit(a, i);
		if (i >= al+l-cl)
			return ::getdigit(c, i-(al+l-cl));
		return 0;
	}
	
	long long subint(int p, int l) const {
		long long m=1;
		long long r=0;
		for (int i=0; i<l; i++) {
			r += m*getdigit(i+p);
			m *= 10;
		}
		return r;
	}
	
	int compare(const T & t, int l) const{
		for (int i=0; i<l; i++) {
			int dl = getdigit(i);
			int dr = t.getdigit(i);
			if (dl < dr)
				return -1;
			if (dl > dr)
				return 1;
		}
		return 0;	
	}
};


int main() {
	
	long long r = 0;
	
	int n;
	scanf("%d", &n);
	
	T t0(0, 0, 0);
	
	for (int w=0; w<n; w++) {
		int a;
		scanf("%d", &a);

		T t(a, 0, 0);
		
		int dl = t0.getlen() - t.getlen();
		if (dl < 0) {
			t0 = t;
			continue;
		}
		t.l += dl;
		r += dl;
		
		int sgn = t.compare(t0, intlen(t.a));
		
		if (sgn < 0) {
			t = T(t.a, t.l+1, 0);
			r++;
		} else if (sgn > 0) {
			// nie r�b nic
		} else { // if (sgn ==0) 
		
			if (intlen(t.a) < intlen(t0.a)) {
			
				if (intlen(t0.c+1) <= t0.l) {
					t = T(t0.a, t0.l, t0.c+1);
				} else {
					if (intlen(t0.a+1) <= intlen(t0.a) ) {
						T t2(t0.a+1, t0.l, 0);
						if (t2.compare(t, intlen(t.a))==0) {
							t = t2;
						} else {
							t = T(t.a, t.l+1, 0);
							r++;
						}
					} else {
						t = T(t.a, t.l+1, 0);
						r++;
					}
				} 
			} else {
				if (intlen(t.c+1) <= t.l) {
					t.c++;
				} else {
					t = T(t.a, t.l+1, 0);
					r++;
				}
			}
		} 
		
		t0 = t;			
	}
	
	printf("%lld\n", r);

	return 0;
}