s = input()[::-1]
size = len(s)
s += "4"

a, b = 0, 0

for i in range(size):
    v1, v2 = int(s[i]), int(s[i+1])
    if v1+b>=6 or (v1+b>=5 and v2>=5):
        a += 10-v1-b
        b = 1
    else:
        a += v1+b
        b = 0

print(a+b) s = input()[::-1] s input()[::-1] () input ::-1 -1 size = len(s) size len(s) len s s += "4" s "4" a, b = 0, 0 a 0 b 0 for i in range(size):
    v1, v2 = int(s[i]), int(s[i+1])
    if v1+b>=6 or (v1+b>=5 and v2>=5):
        a += 10-v1-b
        b = 1
    else:
        a += v1+b
        b = 0 i range(size) range size v1, v2 = int(s[i]), int(s[i+1]) v1 int(s[i]) int s[i] s i v2 int(s[i+1]) int s[i+1] s i+1 i 1 if v1+b>=6 or (v1+b>=5 and v2>=5):
        a += 10-v1-b
        b = 1
    else:
        a += v1+b
        b = 0 v1+b>=6 or (v1+b>=5 and v2>=5) v1+b>=6 v1+b v1 b 6 v1+b>=5 and v2>=5 v1+b>=5 v1+b v1 b 5 v2>=5 v2 5 a += 10-v1-b a 10-v1-b 10-v1 10 v1 b b = 1 b 1 a += v1+b a v1+b v1 b b = 0 b 0 print(a+b) print a+b a b b = 0, 0 0 b a, b = 0, 0 0 a v1, v2 = int(s[i]), int(s[i+1]) int(s[i]) v1 b = 0 0 b size = len(s) len(s) size a += 10-v1-b 10-v1-b a s += "4" "4" s b = 1 1 b v2 = int(s[i]), int(s[i+1]) int(s[i+1]) v2 a += v1+b v1+b a s = input()[::-1] input()[::-1] s
s = input()[::-1]
size = len(s)
s += "4"

a, b = 0, 0

for i in range(size):
    v1, v2 = int(s[i]), int(s[i+1])
    if v1+b>=6 or (v1+b>=5 and v2>=5):
        a += 10-v1-b
        b = 1
    else:
        a += v1+b
        b = 0

print(a+b)
