n = list(map(int,input()))[::-1]
n.append(0)
for i in range(len(n)):
    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)) n = list(map(int,input()))[::-1] n list(map(int,input()))[::-1] (map(int,input())) list map(int,input()) map int input() input ::-1 -1 n.append(0) n.append n append 0 for i in range(len(n)):
    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)) range len(n) len n 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 = list(map(int,input()))[::-1] list(map(int,input()))[::-1] n
n = list(map(int,input()))[::-1]
n.append(0)
for i in range(len(n)):
    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))
