SP23772 ZAMENA - Zamena
Description
Little Picsel, a long-term member of the Secret Committee, has decided to resign after years of loyal service. However, as he does not want his departure to go unnoticed, he has decided to encrypt his final suggestion for this year's Nationals, using a key only known to him. He left only a single array to the other Committee members, containing all of their IDs (**the IDs are of a fixed length and need not be unique**), and the statement of the problem that they must solve in order to obtain the key:
Picsel had initially traversed the array, starting from the first element towards the last, until he found an ID he liked and remembered it. Then he continued his traversal, and upon encountering a very similar ID to the one he remembered (two IDs are _very similar_ if they differ **at most in a single digit**), he has two options:
- **remembering the encountered ID** instead of the previously remembered one, and continuing his traversal;
- **continuing his traversal** **without remembering the encountered ID**.
Picsel also keeps track of the total 'score' he has obtained throughout his traversal; initially, his score is set to zero, however whenever he chooses to remember a new ID, **the score increases by the absolute difference of the old and new ID's digit on the position in which they differ**. For example, if the previously remembered ID was 1234, and the newly remembered ID is 1274, the score increases by 4 in that case. The Committee now must determine the **maximal score** that Picsel could have achieved.
The Nationals have already begun, and the Committee had failed to decrypt Picsel's problem and are unable to offer the contestants a new one. As such, they asked for your help with the decryption; for additional motivation, they are offering you 100 points at the contest as a reward.
Input Format
The first line of the standard input contains a natural number N, representing the amount of members of the Secret Committee.
Each of the following N lines contains a single integer A $ _{i} $ , representing the ID of the i-th committee member in the array.
Output Format
Write to the first and only line of the standard output a single integer M, representing the maximal score that Picsel could have achieved.