s = '0' + input()
m = len(s)
up = 0
cnt = 0
y = []
for i in range(-1, -m-1, -1):
    cs = int(s[i]) + up
    if cs < 5 or (cs == 5 and int(s[i-1]) < 5):
        cnt += cs
        y.append([cs, s[i]])
        up = 0
    else:
        cnt += 10 - cs
        y.append([10 - cs, s[i]])
        up = 1
        
print(cnt) s = '0' + input() s '0' + input() '0' input() input m = len(s) m len(s) len s up = 0 up 0 cnt = 0 cnt 0 y = [] y [] for i in range(-1, -m-1, -1):
    cs = int(s[i]) + up
    if cs < 5 or (cs == 5 and int(s[i-1]) < 5):
        cnt += cs
        y.append([cs, s[i]])
        up = 0
    else:
        cnt += 10 - cs
        y.append([10 - cs, s[i]])
        up = 1
         i range(-1, -m-1, -1) range -1 -m-1 -m m 1 -1 cs = int(s[i]) + up cs int(s[i]) + up int(s[i]) int s[i] s i up if cs < 5 or (cs == 5 and int(s[i-1]) < 5):
        cnt += cs
        y.append([cs, s[i]])
        up = 0
    else:
        cnt += 10 - cs
        y.append([10 - cs, s[i]])
        up = 1
         cs < 5 or (cs == 5 and int(s[i-1]) < 5) cs < 5 cs 5 cs == 5 and int(s[i-1]) < 5 cs == 5 cs 5 int(s[i-1]) < 5 int(s[i-1]) int s[i-1] s i-1 i 1 5 cnt += cs cnt cs y.append([cs, s[i]]) y.append y append [cs, s[i]] cs s[i] s i up = 0 up 0 cnt += 10 - cs cnt 10 - cs 10 cs y.append([10 - cs, s[i]]) y.append y append [10 - cs, s[i]] 10 - cs 10 cs s[i] s i up = 1 up 1 print(cnt) print cnt m = len(s) len(s) m y = [] [] y cnt += cs cs cnt cnt += 10 - cs 10 - cs cnt s = '0' + input() '0' + input() s cnt = 0 0 cnt up = 0 0 up up = 1 1 up cs = int(s[i]) + up int(s[i]) + up cs up = 0 0 up
s = '0' + input()
m = len(s)
up = 0
cnt = 0
y = []
for i in range(-1, -m-1, -1):
    cs = int(s[i]) + up
    if cs < 5 or (cs == 5 and int(s[i-1]) < 5):
        cnt += cs
        y.append([cs, s[i]])
        up = 0
    else:
        cnt += 10 - cs
        y.append([10 - cs, s[i]])
        up = 1
        
print(cnt)