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
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;

	cin >> n;

	int appended = 0;
	string last = "";

	for (int i = 0; i < n; ++i) {
		string a;

		cin >> a;

		if (a.size() > last.size()) {
			last = a;
			continue;
		}

		int j;

		for (j = 0; j < a.size(); ++j) {
			if (a[j] < last[j]) {
				int toAppend = last.size() - a.size()+1;
				appended += toAppend;
				last = a + string(toAppend, '0');
				break;
			}
			if (a[j] > last[j]) {
				int toAppend = last.size() - a.size();
				appended += toAppend;
				last = a + string(toAppend, '0');
				break;
			}
		}

		if (j == a.size()) {
			++appended;
			last = a + "0";
		}
	}

	cout << appended << endl;

	return 0;
}