Prof. Vasechkin wants to represent positive integer *n* as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum.
The first line of the input contains integer *n* (1 ≤ *n* &lt; 10<sup class="upper-index">15</sup>).
num = int(input())

def get(num, count):

    if num == 0:
        return count
    num_s = str(num)
    f1 = "1" * len(num_s)
    f2 = "1" * len(num_s) + "1"
    if abs(int(f1) - num) <= abs(int(f2) - num):
        return get(abs(num - int(f1)), count + len(f1))
    else:
        return get(abs(num - int(f2)), count + len(f1))
        

print(get(num, 0))