S = map(int, input())

a, b = 0, 1
for s in S:
    a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1)

print(a) S = map(int, input()) S map(int, input()) map int input() input a, b = 0, 1 a 0 b 1 for s in S:
    a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1) s S a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1) a a + s if a + s < b + 10 - s else b + 10 - s a + s < b + 10 - s a + s a s b + 10 - s b + 10 b 10 s a + s a s b + 10 - s b + 10 b 10 s b a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1) a + (s + 1) < b + 10 - (s + 1) a + (s + 1) a s + 1 s 1 b + 10 - (s + 1) b + 10 b 10 s + 1 s 1 a + (s + 1) a s + 1 s 1 b + 10 - (s + 1) b + 10 b 10 s + 1 s 1 print(a) print a b = 0, 1 1 b S = map(int, input()) map(int, input()) S a, b = 0, 1 0 a a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1) a + s if a + s < b + 10 - s else b + 10 - s a b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1) a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1) b
S = map(int, input())

a, b = 0, 1
for s in S:
    a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1)

print(a)