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>).
s = str(input())
ans = 0
while int(s)!=0:
    l = len(s)         
    tmp = "1"*len(s)    #xâu 1
    so1 = int(s)
    so2 = int(tmp)
    #print("so1 =",so1)
    #print("so2 =",so2)
    #print("l =",l)
    if so1 > so2*int(s[0]):
        ans += int(s[0])*l
        so1 = so1-so2*int(s[0])
        s = str(so1)
        #print("1",ans)
        #print (s)
    elif so1 < so2*int(s[0]):
        ans+=l*int(s[0])
        so1=so2*int(s[0])-so1
        s = str(so1)
        #print (s)
        #print("2",ans)
    else:
        ans+=l*int(s[0])
        s = str(so1-so2*int(s[0]))
        #print("3",ans)
print(ans)
        
