N = [int(i) for i in input()]
n = N[::-1]+[0]
for i in range(len(n)-1):
    if n[i] >= 6 or (n[i] == 5 and n[i+1] >= 5):
        n[i] = 10 - n[i]
        n[i+1] += 1
print(sum(n)) int(i) for i in input() for i in input() i input() input for i in input() int(i) int i N = [int(i) for i in input()] N [int(i) for i in input()] n = N[::-1]+[0] n N[::-1]+[0] N[::-1] N ::-1 -1 [0] 0 for i in range(len(n)-1):
    if n[i] >= 6 or (n[i] == 5 and n[i+1] >= 5):
        n[i] = 10 - n[i]
        n[i+1] += 1 i range(len(n)-1) range len(n)-1 len(n) len n 1 if n[i] >= 6 or (n[i] == 5 and n[i+1] >= 5):
        n[i] = 10 - n[i]
        n[i+1] += 1 n[i] >= 6 or (n[i] == 5 and n[i+1] >= 5) n[i] >= 6 n[i] n i 6 n[i] == 5 and n[i+1] >= 5 n[i] == 5 n[i] n i 5 n[i+1] >= 5 n[i+1] n i+1 i 1 5 n[i] = 10 - n[i] n[i] n i 10 - n[i] 10 n[i] n i n[i+1] += 1 n[i+1] n i+1 i 1 1 print(sum(n)) print sum(n) sum n N = [int(i) for i in input()] [int(i) for i in input()] N n = N[::-1]+[0] N[::-1]+[0] n
N = [int(i) for i in input()]
n = N[::-1]+[0]
for i in range(len(n)-1):
    if n[i] >= 6 or (n[i] == 5 and n[i+1] >= 5):
        n[i] = 10 - n[i]
        n[i+1] += 1
print(sum(n))
