import numpy as np
from numba import njit
N = np.array([int(_) for _ in input()])
dp = np.array([[0, 0] for _ in range(len(N))])


@njit
def solve(N, dp):
    dp[0, 0] = min(N[0], 11 - N[0])
    dp[0, 1] = min(N[0] + 1, 10 - N[0])
    for i in range(1, len(N)):
        dp[i, 0] = min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i])
        dp[i, 1] = min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i])
    print(dp[-1][0])


solve(N, dp) 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()] [0, 0] for _ in range(len(N)) for _ in range(len(N)) _ range(len(N)) range len(N) len N for _ in range(len(N)) [0, 0] 0 0 dp = np.array([[0, 0] for _ in range(len(N))]) dp np.array([[0, 0] for _ in range(len(N))]) np.array np array [[0, 0] for _ in range(len(N))] def solve(N, dp):
    dp[0, 0] = min(N[0], 11 - N[0])
    dp[0, 1] = min(N[0] + 1, 10 - N[0])
    for i in range(1, len(N)):
        dp[i, 0] = min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i])
        dp[i, 1] = min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i])
    print(dp[-1][0]) solve dp[0, 0] = min(N[0], 11 - N[0]) dp[0, 0] dp 0 min(N[0], 11 - N[0]) min N[0] N 0 11 - N[0] 11 N[0] N 0 dp[0, 1] = min(N[0] + 1, 10 - N[0]) dp[0, 1] dp 0 min(N[0] + 1, 10 - N[0]) min N[0] + 1 N[0] N 0 1 10 - N[0] 10 N[0] N 0 for i in range(1, len(N)):
        dp[i, 0] = min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i])
        dp[i, 1] = min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i])
     i range(1, len(N)) range 1 len(N) len N dp[i, 0] = min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i]) dp[i, 0] dp i min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i]) min dp[i - 1, 0] + N[i] dp[i - 1, 0] dp i - 1 i 1 N[i] N i dp[i - 1, 1] + 10 - N[i] dp[i - 1, 1] + 10 dp[i - 1, 1] dp i - 1 i 1 10 N[i] N i dp[i, 1] = min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i]) dp[i, 1] dp i min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i]) min dp[i - 1, 0] + N[i] + 1 dp[i - 1, 0] + N[i] dp[i - 1, 0] dp i - 1 i 1 N[i] N i 1 dp[i - 1, 1] + 9 - N[i] dp[i - 1, 1] + 9 dp[i - 1, 1] dp i - 1 i 1 9 N[i] N i print(dp[-1][0]) print dp[-1][0] [-1] dp -1 0 N N dp dp @njit solve njit solve solve(N, dp) solve N dp N = np.array([int(_) for _ in input()]) np.array([int(_) for _ in input()]) N dp = np.array([[0, 0] for _ in range(len(N))]) np.array([[0, 0] for _ in range(len(N))]) dp def solve(N, dp):
    dp[0, 0] = min(N[0], 11 - N[0])
    dp[0, 1] = min(N[0] + 1, 10 - N[0])
    for i in range(1, len(N)):
        dp[i, 0] = min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i])
        dp[i, 1] = min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i])
    print(dp[-1][0]) def solve(N, dp):
    dp[0, 0] = min(N[0], 11 - N[0])
    dp[0, 1] = min(N[0] + 1, 10 - N[0])
    for i in range(1, len(N)):
        dp[i, 0] = min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i])
        dp[i, 1] = min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i])
    print(dp[-1][0]) solve
import numpy as np
from numba import njit
N = np.array([int(_) for _ in input()])
dp = np.array([[0, 0] for _ in range(len(N))])


@njit
def solve(N, dp):
    dp[0, 0] = min(N[0], 11 - N[0])
    dp[0, 1] = min(N[0] + 1, 10 - N[0])
    for i in range(1, len(N)):
        dp[i, 0] = min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i])
        dp[i, 1] = min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i])
    print(dp[-1][0])


solve(N, dp)
