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>).
n = input().strip()
l = len(n)
n = int(n)
ans = 0
c = 0
for i in range(l, 0, -1):
    cur = int('1' * i)
    raz = 10 ** 16
    m_z = 0
    zn = ''
    for z in range(0, 10):
        if abs(n - (c - cur * z)) < raz:
            zn = '-'
            m_z = z
            raz = abs(n - (c - cur * z))
        if abs(n - (c + cur * z)) < raz:
            zn = '+'
            m_z = z
            raz = abs(n - (c + cur * z))        
    if zn is '-':
        c -= cur * m_z
    else:
        c += cur * m_z
    ans += m_z * i
print(ans)