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
#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main()
{
	iostream::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<string>pay(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> pay[i];
	}
	long long result = 0;
	for (int i = 1; i < n; ++i)
	{
		if (pay[i].length() > pay[i - 1].length()) continue;
		bool equal = 1;
		for (unsigned j = 0; j < pay[i].length(); ++j)
		{
			if (pay[i][j] < pay[i - 1][j])
			{
				equal = 0;
				for (unsigned k = pay[i].length(); k < pay[i - 1].length() + 1; ++k)
				{
					pay[i] += '0';
					++result;
				}
				break;
			}
			if (pay[i][j] > pay[i - 1][j])
			{
				equal = 0;
				for (unsigned k = pay[i].length(); k < pay[i - 1].length(); ++k)
				{
					pay[i] += '0';
					++result;
				}
				break;
			}
		}
		if (!equal) continue;
		int ninend = 0;
		for (unsigned j = pay[i - 1].length() - 1; j >= pay[i].length(); --j)
		{
			if (pay[i - 1][j] != '9') break;
			++ninend;
		}
		if (pay[i - 1].length() - pay[i].length() == ninend)
		{
			for (int j = 0; j <= ninend; ++j)
			{
				pay[i] += '0';
				++result;
			}
			continue;
		}
		for (unsigned j = pay[i].length() + 1; j <= pay[i - 1].length() - ninend; ++j)
		{
			pay[i] += pay[i - 1][j - 1];
			++result;
		}
		++pay[i].back();
		for (int j = 0; j < ninend; ++j)
		{
			pay[i] += '0';
			++result;
		}
	}
	cout << result;
	return 0;
}