l=[0]+[int(i) for i in input()]
l.reverse()
su=0
for i in range(len(l)):
    if l[i]>5:
        l[i]=10-l[i]
        l[i+1]+=1
    elif l[i]==5 and l[i+1]>4:
        l[i+1]+=1
    su+=l[i]
print(su) int(i) for i in input() for i in input() i input() input for i in input() int(i) int i l=[0]+[int(i) for i in input()] l [0]+[int(i) for i in input()] [0] 0 [int(i) for i in input()] l.reverse() l.reverse l reverse su=0 su 0 for i in range(len(l)):
    if l[i]>5:
        l[i]=10-l[i]
        l[i+1]+=1
    elif l[i]==5 and l[i+1]>4:
        l[i+1]+=1
    su+=l[i] i range(len(l)) range len(l) len l if l[i]>5:
        l[i]=10-l[i]
        l[i+1]+=1
    elif l[i]==5 and l[i+1]>4:
        l[i+1]+=1
     l[i]>5 l[i] l i 5 l[i]=10-l[i] l[i] l i 10-l[i] 10 l[i] l i l[i+1]+=1 l[i+1] l i+1 i 1 1 elif l[i]==5 and l[i+1]>4:
        l[i+1]+=1
     l[i]==5 and l[i+1]>4 l[i]==5 l[i] l i 5 l[i+1]>4 l[i+1] l i+1 i 1 4 l[i+1]+=1 l[i+1] l i+1 i 1 1 su+=l[i] su l[i] l i print(su) print su su=0 0 su l=[0]+[int(i) for i in input()] [0]+[int(i) for i in input()] l su+=l[i] l[i] su
l=[0]+[int(i) for i in input()]
l.reverse()
su=0
for i in range(len(l)):
    if l[i]>5:
        l[i]=10-l[i]
        l[i+1]+=1
    elif l[i]==5 and l[i+1]>4:
        l[i+1]+=1
    su+=l[i]
print(su)