N = [int(s) for s in input()]
n = len(N)
a = 0
b = 11
for n in N:
    a1 = min(a+n, b+n)
    b1 = min(a+11-n, b+9-n)
    a = a1
    b = b1
print(min(a,b)) int(s) for s in input() for s in input() s input() input for s in input() int(s) int s N = [int(s) for s in input()] N [int(s) for s in input()] n = len(N) n len(N) len N a = 0 a 0 b = 11 b 11 for n in N:
    a1 = min(a+n, b+n)
    b1 = min(a+11-n, b+9-n)
    a = a1
    b = b1 n N a1 = min(a+n, b+n) a1 min(a+n, b+n) min a+n a n b+n b n b1 = min(a+11-n, b+9-n) b1 min(a+11-n, b+9-n) min a+11-n a+11 a 11 n b+9-n b+9 b 9 n a = a1 a a1 b = b1 b b1 print(min(a,b)) print min(a,b) min a b b = 11 11 b a = a1 a1 a a = 0 0 a a1 = min(a+n, b+n) min(a+n, b+n) a1 b1 = min(a+11-n, b+9-n) min(a+11-n, b+9-n) b1 b = b1 b1 b N = [int(s) for s in input()] [int(s) for s in input()] N n = len(N) len(N) n
N = [int(s) for s in input()]
n = len(N)
a = 0
b = 11
for n in N:
    a1 = min(a+n, b+n)
    b1 = min(a+11-n, b+9-n)
    a = a1
    b = b1
print(min(a,b))