x = list(map(int,list(input())))
n = len(x)
dp = [[0,1] for _ in range(n+1)]
for i in range(n):
    dp[i+1][0] = min(dp[i][0]+x[i],dp[i][1]+10-x[i])
    dp[i+1][1] = min(dp[i][0]+x[i]+1,dp[i][1]+9-x[i])
print(dp[n][0]) x = list(map(int,list(input()))) x list(map(int,list(input()))) list map(int,list(input())) map int list(input()) list input() input n = len(x) n len(x) len x [0,1] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [0,1] 0 1 dp = [[0,1] for _ in range(n+1)] dp [[0,1] for _ in range(n+1)] for i in range(n):
    dp[i+1][0] = min(dp[i][0]+x[i],dp[i][1]+10-x[i])
    dp[i+1][1] = min(dp[i][0]+x[i]+1,dp[i][1]+9-x[i]) i range(n) range n dp[i+1][0] = min(dp[i][0]+x[i],dp[i][1]+10-x[i]) dp[i+1][0] [i+1] dp i+1 i 1 0 min(dp[i][0]+x[i],dp[i][1]+10-x[i]) min dp[i][0]+x[i] dp[i][0] [i] dp i 0 x[i] x i dp[i][1]+10-x[i] dp[i][1]+10 dp[i][1] [i] dp i 1 10 x[i] x i dp[i+1][1] = min(dp[i][0]+x[i]+1,dp[i][1]+9-x[i]) dp[i+1][1] [i+1] dp i+1 i 1 1 min(dp[i][0]+x[i]+1,dp[i][1]+9-x[i]) min dp[i][0]+x[i]+1 dp[i][0]+x[i] dp[i][0] [i] dp i 0 x[i] x i 1 dp[i][1]+9-x[i] dp[i][1]+9 dp[i][1] [i] dp i 1 9 x[i] x i print(dp[n][0]) print dp[n][0] [n] dp n 0 n = len(x) len(x) n dp = [[0,1] for _ in range(n+1)] [[0,1] for _ in range(n+1)] dp x = list(map(int,list(input()))) list(map(int,list(input()))) x
x = list(map(int,list(input())))
n = len(x)
dp = [[0,1] for _ in range(n+1)]
for i in range(n):
    dp[i+1][0] = min(dp[i][0]+x[i],dp[i][1]+10-x[i])
    dp[i+1][1] = min(dp[i][0]+x[i]+1,dp[i][1]+9-x[i])
print(dp[n][0])
