import numpy as np
from numba import njit

N = np.array([int(_) for _ in input()])


def solve(N):
    p, q = 0, 1
    for x in N:
        p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
    print(p)


solve(N) import numpy as np numpy from numba import njit int(_) for _ in input() for _ in input() _ input() input for _ in input() int(_) int _ N = np.array([int(_) for _ in input()]) N np.array([int(_) for _ in input()]) np.array np array [int(_) for _ in input()] def solve(N):
    p, q = 0, 1
    for x in N:
        p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
    print(p) solve p, q = 0, 1 p 0 q 1 for x in N:
        p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
     x N p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x) p min(p + x, q + 10 - x) min p + x p x q + 10 - x q + 10 q 10 x q min(p + x + 1, q + 9 - x) min p + x + 1 p + x p x 1 q + 9 - x q + 9 q 9 x print(p) print p N N solve(N) solve N def solve(N):
    p, q = 0, 1
    for x in N:
        p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
    print(p) def solve(N):
    p, q = 0, 1
    for x in N:
        p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
    print(p) solve N = np.array([int(_) for _ in input()]) np.array([int(_) for _ in input()]) N
import numpy as np
from numba import njit

N = np.array([int(_) for _ in input()])


def solve(N):
    p, q = 0, 1
    for x in N:
        p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
    print(p)


solve(N)
