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>).
def addend(num, count=0):
    n = 0
    while(int(num) > 1):
        possibles = []
        possibles.append(len(num)*"1")
        if(len(num) > 1):
            possibles.append((len(num)-1)*"1")
        possibles.append((len(num)+1)*"1")
        minimum = int(num)
        for possible in possibles:
            x = int(num) - int(possible)
            if(abs(x) < minimum):
                h = len(possible)
                minimum = abs(x)
        n += h
        num = str(minimum)
    if(int(num) == 1):
        n += 1
    return n

def reader():
    n = input()
    print(addend(n))

reader()