Background
Whether it sounds banal or not, but the world has changed. Many years have passed since the famous four of cheaters were shaking on the dance floor of the transitional economics (these stores are fully described in the problems
"Credit operations" and
"Credit operations 2").
The modern world is not a place for shady financial intrigues. Former police general Ivan Crowbar and tax police chief Peter Bullman retired long ago and now spend most of their free time playing dominoes. Meanwhile, old friends businessman Vladimir Bludgeon and banker Alexander Ironfist became honest persons and now go to church every Sunday and even pay taxes properly.
Problem
On the basis of "Industrial Trust Ltd.", controlled by Vladimir, and "Financial Holding Company", owned by Alexander, a corporation "United Russian Corporation" was established. Since then a summarized income statement is submitted on behalf of the corporation every month.
Once Mr. Bludgeon and Mr. Ironfist sent a regular income statement to the tax police. It was declared in the document, that during last month a clear profit of "Industrial Trust Ltd." was equal to A dollars, a clear profit of "Financial Holding Company" was equal to B dollars, and an overall profit of "United Russian Corporation" was equal to C dollars. Unfortunately, while filling the statement, some crucial errors were made, so a condition A + B = C was not satisfied. Of course, these errors should be corrected at once.
Paragraph "h" of 113-th article of federal law "Legal Entities Taxation Act" instructs: "...Each digit of the number should be corrected separately. A correction procedure means a replacing an erroneous digit with a correct one. At that it is prohibited to replace the first digit of the number with zero and to add or remove decimal positions (i.e. to change the length of the number). A special penalty is imposed for each correction procedure and equals to an absolute value of the difference between the erroneous digit and the correct one. A total penalty for the correction of the number is calculated as a sum of all penalties for the corrections of its digits. An overall penalty for the correction of the whole income statement is computed as a sum of all penalties for the corrections of the numbers mentioned in it..."
It goes without saying, that Vladimir and Alexander are going to correct the numbers A, B and C so that an overall penalty would be minimal.
Input
The first line contains the integer number A (1 ≤ A < 101000). The second line contains the integer number B (1 ≤ B < 101000). The third line contains the integer number C (1 ≤ C < 101000).
Output
If the income statement could be corrected according to the rules given, you should output the minimal overall penalty. Otherwise you should output "-1".
Sample
Notes
In the sample, let us correct the number A (123) to 121, the number B (554) to 324 and the number C (345) to 445. Then a total penalty for the correction of the number A is abs(3-1) = 2 dollars, for the correction of the number B: abs(5-3) + abs(5-2) = 5 dollars, and for the correction of the number C: abs(3-4) = 1 dollar. So an overall penalty will be equal to 2 + 5 + 1 = 8 dollars.
Problem Author: Nikita Rybak, Ilya Grebnov, Dmitry Kovalioff
Problem Source: Timus Top Coders: Third Challenge