s = "0" + input()
keta = len(s)
dp = [0] * (keta + 1)
kuri = 0
for i in range(keta):
    ni = i + 1
    num = int(s[-i - 1])
    if kuri:
        num += 1
        kuri = 0
    if num == 10:
        kuri = 1
        dp[ni] = dp[i]
    elif num < 5:
        dp[ni] = dp[i] + num
    elif num > 5:
        num %= 10
        kuri = 1
        dp[ni] = dp[i] + 10 - num
    else:
        nn = int(s[-ni - 1])
        if nn < 5:
            dp[ni] = dp[i] + num
        else:
            kuri = 1
            dp[ni] = dp[i] + 10 - num
print(dp[keta] + kuri) s = "0" + input() s "0" + input() "0" input() input keta = len(s) keta len(s) len s dp = [0] * (keta + 1) dp [0] * (keta + 1) [0] 0 keta + 1 keta 1 kuri = 0 kuri 0 for i in range(keta):
    ni = i + 1
    num = int(s[-i - 1])
    if kuri:
        num += 1
        kuri = 0
    if num == 10:
        kuri = 1
        dp[ni] = dp[i]
    elif num < 5:
        dp[ni] = dp[i] + num
    elif num > 5:
        num %= 10
        kuri = 1
        dp[ni] = dp[i] + 10 - num
    else:
        nn = int(s[-ni - 1])
        if nn < 5:
            dp[ni] = dp[i] + num
        else:
            kuri = 1
            dp[ni] = dp[i] + 10 - num i range(keta) range keta ni = i + 1 ni i + 1 i 1 num = int(s[-i - 1]) num int(s[-i - 1]) int s[-i - 1] s -i - 1 -i i 1 if kuri:
        num += 1
        kuri = 0
     kuri num += 1 num 1 kuri = 0 kuri 0 if num == 10:
        kuri = 1
        dp[ni] = dp[i]
    elif num < 5:
        dp[ni] = dp[i] + num
    elif num > 5:
        num %= 10
        kuri = 1
        dp[ni] = dp[i] + 10 - num
    else:
        nn = int(s[-ni - 1])
        if nn < 5:
            dp[ni] = dp[i] + num
        else:
            kuri = 1
            dp[ni] = dp[i] + 10 - num num == 10 num 10 kuri = 1 kuri 1 dp[ni] = dp[i] dp[ni] dp ni dp[i] dp i elif num < 5:
        dp[ni] = dp[i] + num
     num < 5 num 5 dp[ni] = dp[i] + num dp[ni] dp ni dp[i] + num dp[i] dp i num elif num > 5:
        num %= 10
        kuri = 1
        dp[ni] = dp[i] + 10 - num
     num > 5 num 5 num %= 10 num 10 kuri = 1 kuri 1 dp[ni] = dp[i] + 10 - num dp[ni] dp ni dp[i] + 10 - num dp[i] + 10 dp[i] dp i 10 num nn = int(s[-ni - 1]) nn int(s[-ni - 1]) int s[-ni - 1] s -ni - 1 -ni ni 1 if nn < 5:
            dp[ni] = dp[i] + num
        else:
            kuri = 1
            dp[ni] = dp[i] + 10 - num nn < 5 nn 5 dp[ni] = dp[i] + num dp[ni] dp ni dp[i] + num dp[i] dp i num kuri = 1 kuri 1 dp[ni] = dp[i] + 10 - num dp[ni] dp ni dp[i] + 10 - num dp[i] + 10 dp[i] dp i 10 num print(dp[keta] + kuri) print dp[keta] + kuri dp[keta] dp keta kuri dp = [0] * (keta + 1) [0] * (keta + 1) dp nn = int(s[-ni - 1]) int(s[-ni - 1]) nn kuri = 0 0 kuri num %= 10 10 num kuri = 0 0 kuri num += 1 1 num keta = len(s) len(s) keta ni = i + 1 i + 1 ni kuri = 1 1 kuri kuri = 1 1 kuri num = int(s[-i - 1]) int(s[-i - 1]) num s = "0" + input() "0" + input() s kuri = 1 1 kuri
s = "0" + input()
keta = len(s)
dp = [0] * (keta + 1)
kuri = 0
for i in range(keta):
    ni = i + 1
    num = int(s[-i - 1])
    if kuri:
        num += 1
        kuri = 0
    if num == 10:
        kuri = 1
        dp[ni] = dp[i]
    elif num < 5:
        dp[ni] = dp[i] + num
    elif num > 5:
        num %= 10
        kuri = 1
        dp[ni] = dp[i] + 10 - num
    else:
        nn = int(s[-ni - 1])
        if nn < 5:
            dp[ni] = dp[i] + num
        else:
            kuri = 1
            dp[ni] = dp[i] + 10 - num
print(dp[keta] + kuri)
