N_list = [int(i) for i in list(input())]
N_list = N_list[::-1] + [0]

for index in range(0, len(N_list)):
  if N_list[index] >= 6 or (N_list[index] == 5 and N_list[index+1] >= 5) :
    N_list[index] = 10 - N_list[index]
    N_list[index+1] += 1

print(sum(N_list)) int(i) for i in list(input()) for i in list(input()) i list(input()) list input() input for i in list(input()) int(i) int i N_list = [int(i) for i in list(input())] N_list [int(i) for i in list(input())] N_list = N_list[::-1] + [0] N_list N_list[::-1] + [0] N_list[::-1] N_list ::-1 -1 [0] 0 for index in range(0, len(N_list)):
  if N_list[index] >= 6 or (N_list[index] == 5 and N_list[index+1] >= 5) :
    N_list[index] = 10 - N_list[index]
    N_list[index+1] += 1 index range(0, len(N_list)) range 0 len(N_list) len N_list if N_list[index] >= 6 or (N_list[index] == 5 and N_list[index+1] >= 5) :
    N_list[index] = 10 - N_list[index]
    N_list[index+1] += 1 N_list[index] >= 6 or (N_list[index] == 5 and N_list[index+1] >= 5) N_list[index] >= 6 N_list[index] N_list index 6 N_list[index] == 5 and N_list[index+1] >= 5 N_list[index] == 5 N_list[index] N_list index 5 N_list[index+1] >= 5 N_list[index+1] N_list index+1 index 1 5 N_list[index] = 10 - N_list[index] N_list[index] N_list index 10 - N_list[index] 10 N_list[index] N_list index N_list[index+1] += 1 N_list[index+1] N_list index+1 index 1 1 print(sum(N_list)) print sum(N_list) sum N_list N_list = [int(i) for i in list(input())] [int(i) for i in list(input())] N_list N_list = N_list[::-1] + [0] N_list[::-1] + [0] N_list
N_list = [int(i) for i in list(input())]
N_list = N_list[::-1] + [0]

for index in range(0, len(N_list)):
  if N_list[index] >= 6 or (N_list[index] == 5 and N_list[index+1] >= 5) :
    N_list[index] = 10 - N_list[index]
    N_list[index+1] += 1

print(sum(N_list))