OTHS Coding Competition 2 P3 - Tally Clicker

View as PDF

Submit solution


Points: 5
Time limit: 1.0s
Python 2.0s
Memory limit: 512M

Author:
Problem types

Aki has given Denji an important non-negative integer to relay to Makima. Denji is unfortunately not smart enough to remember numbers or write them down. As his friend, you have given him a four-digit tally-clicker to store the number for him to help him impress Makima. Denji wishes to be lazy efficient; given a non-negative integer n within the boundaries, he wants to be told the least number of clicks to display that number on the tally clicker.

The tally clicker consists of two buttons. The first button increments the value by 1, wrapping to 0000 if the tally currently displays 9999. The second button shift all 4 digits up by one. Should any digit be 9, the second button can't be pressed.

Constraints

0 \leq n \leq 9999

Input Specification

The first and only line contains a non-negative integer n, the desired value to be displayed.

Output Specification

Output one non-negative integer, the minimum number of clicks to display n.

Sample Input 1

9999

Sample Output 1

9

Explanation for Sample Output 1

It is optimal to click the second button nine times.

Sample Input 2

101

Sample Output 2

101

Explanation for Sample Output 2

The only possible combination is to click the first button 101 times.


Comments

There are no comments at the moment.