Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.

 [Image] 

The combination lock is represented by n rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?


-----Input-----

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of disks on the combination lock.

The second line contains a string of n digits — the original state of the disks.

The third line contains a string of n digits — Scrooge McDuck's combination that opens the lock.


-----Output-----

Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.


-----Examples-----
Input
5
82195
64723

Output
13



-----Note-----

In the sample he needs 13 moves:

  1 disk: $8 \rightarrow 7 \rightarrow 6$  2 disk: $2 \rightarrow 3 \rightarrow 4$  3 disk: $1 \rightarrow 0 \rightarrow 9 \rightarrow 8 \rightarrow 7$  4 disk: $9 \rightarrow 0 \rightarrow 1 \rightarrow 2$  5 disk: $5 \rightarrow 4 \rightarrow 3$

Difficulty: EASY

Solutions:
n = int(input())
s = input()
s2 = input()
rez = 0
for i in range(n):
	t1 = int(s[i])
	t2 = int(s2[i])
	if abs(t1 - t2) > min(t1, t2) + 10 - max(t1, t2):
		rez += min(t1, t2) + 10 - max(t1, t2)
	else:
		rez += abs(t1 - t2)
print(rez)


n = int(input())
a = input()
b = input()
list_a = list(a)
list_b = list(b)
sum = 0
for i in range(n):
	ans = abs(int(list_a[i]) - int(list_b[i]))
	if ans == 6:
		ans = 4
	elif ans == 7:
		ans = 3
	elif ans == 8:
		ans = 2
	elif ans == 9:
		ans = 1
	sum += ans
print(sum)


n = int(input())
l = [int(x) for x in str(input())]
l1 = [int(x) for x in str(input())]
count = 0
for i in range(n):
	x = min(l[i], l1[i])
	y = max(l[i], l1[i])
	m = abs(x + 10 - y)
	v = abs(l[i] - l1[i])
	count = count + min(m, v)
print(count)


n = int(input())
a = input()
b = input()
res = 0
for i in range(n):
	x = int(a[i])
	y = int(b[i])
	res += min(abs(x - y), 10 - abs(x - y))
print(res)


n = int(input())
s1 = input()
s2 = input()
ans = 0
for i in range(n):
	ans += min(abs(int(s1[i]) - int(s2[i])), min(int(s1[i]), int(s2[i])) + 10 - max(int(s1[i]), int(s2[i])))
print(ans)


n = int(input())
word1 = input()
word2 = input()
a = []
b = []
m = 0
for i in range(n):
	a.append(int(word1[i]))
	b.append(int(word2[i]))
for j in range(n):
	m += min(abs(a[j] - b[j]), 10 - abs(a[j] - b[j]))
print(m)


steps = 0
n = int(input())
ip = list(input())
pwd = list(input())
for i in range(0, n):
	diff = abs(int(ip[i]) - int(pwd[i]))
	if diff > 5:
		diff = 10 - diff
	steps += diff
print(steps)


n = int(input())
s1 = str(input())
s2 = str(input())
count = 0
for i in range(n):
	if abs(int(s1[i]) - int(s2[i])) <= 5:
		count += abs(int(s1[i]) - int(s2[i]))
	else:
		count += 10 - abs(int(s1[i]) - int(s2[i]))
print(count)


n = int(input())
a = input()
b = input()
cnt = 0
for i in range(n):
	cnt += min(abs(int(a[i]) - int(b[i])), 10 - abs(int(a[i]) - int(b[i])))
print(cnt)


n = int(input())
s1 = input()
a = [int(i) for i in s1]
s2 = input()
b = [int(i) for i in s2]
sum = 0
for i in range(len(a)):
	ans1 = abs(a[i] - b[i])
	c = max(a[i], b[i])
	d = min(a[i], b[i])
	ans2 = 9 - c + d + 1
	sum = sum + min(ans1, ans2)
print(sum)


n = int(input())
k = input()
f = input()
k = [int(i) for i in k]
f = [int(i) for i in f]
steps = 0
for i in range(n):
	if k[i] != f[i]:
		steps += min(abs(k[i] - f[i]), abs(10 - abs(k[i] - f[i])))
print(steps)


n = int(input())
s1 = input()
s2 = input()
ans = 0
for i in range(n):
	diff = abs(int(s1[i]) - int(s2[i]))
	if diff > 4:
		diff = 10 - diff
	ans += diff
print(ans)


n = int(input())
ps = input()
os = input()
b = []
c = []
tm = 0
for (i, j) in zip(ps, os):
	b.append(int(i))
	c.append(int(j))
for (i, j) in zip(b, c):
	if abs(i - j) > 5:
		tm += 10 - abs(i - j)
	else:
		tm += abs(i - j)
print(tm)


t = int
p = input
n = t(p())
a = p()
b = p()
dic = {6: 4, 7: 3, 8: 2, 9: 1}
an = 0
for i in range(n):
	k = abs(t(a[i]) - t(b[i]))
	an += dic.get(k, k)
print(an)


c = 0
a = int(input())
s1 = input()
s2 = input()
for i in range(a):
	if abs(int(s1[i]) - int(s2[i])) > 10 - abs(int(s1[i]) - int(s2[i])):
		c += 10 - abs(int(s1[i]) - int(s2[i]))
	elif abs(int(s1[i]) - int(s2[i])) < 10 - abs(int(s1[i]) - int(s2[i])):
		c += abs(int(s1[i]) - int(s2[i]))
	else:
		c += abs(int(s1[i]) - int(s2[i]))
print(c)


import math
import os
import sys
import re
import string
import itertools
import functools
import operator
from collections import Counter

def inputint():
	return int(input())
n = inputint()
s1 = map(int, list(input()))
s2 = map(int, list(input()))
res = 0
for (l1, l2) in zip(s1, s2):
	diff = abs(l1 - l2)
	res = res + min(diff, 10 - diff)
print(res)


n = int(input())
[A, B] = [input(), input()]
C = 0
for i in range(n):
	C += min(abs(int(A[i]) - int(B[i])), 10 - abs(int(A[i]) - int(B[i])))
print(C)


(n, s1, s2) = (int(input()), input(), input())
sum1 = 0
for i in range(n):
	sum1 += min(abs(int(s2[i]) - int(s1[i])), 10 - abs(int(s2[i]) - int(s1[i])))
print(sum1)


n = int(input())
a = input()
b = input()
answer = 0
for i in range(n):
	q = int(a[i])
	w = int(b[i])
	if abs(q - w) > 5:
		answer += 10 - abs(q - w)
	else:
		answer += abs(int(a[i]) - int(b[i]))
print(answer)


n = int(input())
arr1 = input()
arr2 = input()
sum = 0
for i in range(0, n):
	m = max(int(arr1[i]), int(arr2[i]))
	n = min(int(arr1[i]), int(arr2[i]))
	if m - n > 5:
		sum = sum + (10 - (m - n))
	else:
		sum = sum + m - n
print(sum)


n = int(input())
s = [int(i) for i in input()]
e = [int(i) for i in input()]
count = 0
for i in range(n):
	if 10 - s[i] + e[i] < ((s[i] - e[i]) ** 2) ** 0.5:
		count += 10 - s[i] + e[i]
	elif 10 - e[i] + s[i] < ((s[i] - e[i]) ** 2) ** 0.5:
		count += 10 - e[i] + s[i]
	else:
		count += ((s[i] - e[i]) ** 2) ** 0.5
count = int(count)
print(count)


def tmove(a):
	return min(a, 10 - a)
n = int(input())
a = list(map(int, list(input())))
b = list(map(int, list(input())))
ans = 0
for i in range(n):
	ans += tmove(abs(a[i] - b[i]))
print(ans)


n = input()
a = input()
a1 = str(a)
a2 = list(a1)
b = input()
b1 = str(b)
b2 = list(b1)
count = 0
for i in range(len(a2)):
	p = abs(int(a2[i]) - int(b2[i]))
	q = 9 - int(b2[i]) + int(a2[i]) + 1
	r = 9 - int(a2[i]) + int(b2[i]) + 1
	count = count + min(p, q, r)
print(count)


n = int(input())
org_state = int(input())
final_state = int(input())
(ans, mul) = (0, 10)
for i in range(n):
	(a, b) = (org_state % mul, final_state % mul)
	org_state //= 10
	final_state //= 10
	tmp = abs(a - b)
	ans += tmp if tmp <= 5 else 10 - tmp
print(ans)


n = int(input())
S1 = input()
S2 = input()
k = 0
for i in range(n):
	if abs(int(S1[i]) - int(S2[i])) < 10 - abs(int(S1[i]) - int(S2[i])):
		k = k + abs(int(S1[i]) - int(S2[i]))
	else:
		k = k + 10 - abs(int(S1[i]) - int(S2[i]))
print(k)


from typing import Tuple

def parse_input() -> Tuple[int, str, str]:
	return (int(input()), input(), input())

def solve(n: int, a: str, b: str) -> int:
	c = 0
	for idx in range(n):
		(ai, bi) = (int(a[idx]), int(b[idx]))
		c += min(abs(ai - bi), 10 - abs(ai - bi))
	return c
(n, a, b) = parse_input()
print(solve(n, a, b))


n = int(input())
s1 = input()
s2 = input()
count = 0
for i in range(n):
	d = int(s1[i]) - int(s2[i])
	d1 = 10 - int(s1[i]) + int(s2[i])
	d2 = 10 - int(s2[i]) + int(s1[i])
	if d1 < 0:
		d1 = -d1
	if d2 < 0:
		d2 = -d2
	if d < 0:
		d = -d
	count += min(d1, d2, d)
print(count)


import sys
local_launch = False
try:
	open('LOCAL').read()
	local_launch = True
except:
	pass
input_data = open('INPUT.txt').read() if local_launch else sys.stdin.read()
done = {'i': 0}
tokens = input_data.split()

def next_token():
	result = tokens[done['i']]
	done['i'] += 1
	return result

def next_int():
	return int(next_token())

def next_str():
	return next_token()
n = next_int()
xx = list(next_str())
yy = list(next_str())
z = 0
count = 0

def round(x, y):
	u = abs(x - y)
	return min(u, 10 - u)
for (x, y) in zip(xx, yy):
	z += round(int(x), int(y))
print(z)


import math
n = int(input())
a = list(input())
b = list(input())
count = 0
for i in range(0, n):
	count = count + min(abs(int(a[i]) - int(b[i])), 10 - abs(int(a[i]) - int(b[i])))
print(count)


n = int(input())
init = list(map(int, input()))
pas = list(map(int, input()))
tot = 0
for (i, p) in zip(init, pas):
	tot += min(abs(i - p), 10 - abs(i - p))
print(tot)


n = int(input())
origin = list(input())
later = list(input())
count = 0
for i in range(n):
	a = abs(int(origin[i]) - int(later[i]))
	count += min(a, 10 - a)
print(count)


N = input()
startPosition = input()
finalPosition = input()
countOfActions = 0
for i in range(0, int(N)):
	startNum = int(startPosition[i])
	finalNum = int(finalPosition[i])
	countOfActions += min(abs(finalNum - startNum), finalNum + 10 - startNum, startNum + 10 - finalNum)
print(countOfActions)


n = int(input())
a = input()
b = input()
s = 0
for i in range(n):
	if abs(int(a[i]) - int(b[i])) <= 5:
		s = s + abs(int(a[i]) - int(b[i]))
	else:
		s = s + (10 - max(int(a[i]), int(b[i]))) + min(int(a[i]), int(b[i]))
print(s)


n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
count = 0
for i in range(n):
	count += min(abs(a[i] - b[i]), min(a[i], b[i]) + 10 - max(a[i], b[i]))
print(count)


n = int(input())
o = input()
f = input()
r = 0
for i in range(n):
	oi = int(o[i])
	fi = int(f[i])
	re = max(oi, fi) - min(oi, fi)
	su = 10 - re
	r += min(re, su)
print(r)


input()
print(sum((min(abs(int(x) - int(y)), 10 - abs(int(x) - int(y))) for (x, y) in zip(input(), input()))))


n = int(input())
k1 = input()
k2 = input()
a = []
b = []
for i in k1:
	a.append(int(i))
for i in k2:
	b.append(int(i))
ans = 0
for j in range(n):
	ans += min(abs(a[j] - b[j]), 10 - abs(a[j] - b[j]))
print(ans)


def solve(n, x, s):
	a = 0
	for i in range(n):
		d = abs(s[i] - x[i])
		a += min(d, 10 - d)
	return a

def main():
	n = int(input())
	x = list(map(int, input()))
	s = list(map(int, input()))
	print(solve(n, x, s))
main()


n = int(input())
count = 0
combinations = [[], []]

def calc_difference(one, two):
	difference = abs(one - two)
	if difference > 5:
		return 10 - difference
	else:
		return difference
for comb in combinations:
	for x in input():
		comb.append(int(x))
for i in range(n):
	count += calc_difference(combinations[0][i], combinations[1][i])
print(count)


n = int(input())
a = list(input())
b = list(input())
s = 0
for i in range(n):
	x = abs(int(a[i]) - int(b[i]))
	if x >= 5:
		s += 10 - x
	else:
		s += x
print(s)


import sys
import math
import bisect
import itertools
import random

def query_distance(a, b):
	d1 = abs(a - b)
	d2 = 10 - d1
	return min(d1, d2)

def main():
	n = int(input())
	A = list((int(a) for a in input()))
	B = list((int(a) for a in input()))
	ans = 0
	for i in range(n):
		val = query_distance(A[i], B[i])
		ans += val
	print(ans)
main()


n = int(input())
in1 = input()
in2 = input()
s = 0
for i in range(n):
	a = int(in1[i])
	b = int(in2[i])
	s = s + min(10 - abs(a - b), abs(a - b))
print(s)


n = int(input())
s = input()
t = input()
total = 0
for i in range(n):
	a = (int(s[i]) - int(t[i])) % 10
	b = (int(t[i]) - int(s[i])) % 10
	if a < b:
		total += a
	else:
		total += b
print(total)


z = int(input())
x = input()
v = input()
d = 0
w = 0
c = 0
for i in x:
	a = int(i)
	b = int(i)
	for o in range(18):
		if a == int(v[c]) or b == int(v[c]):
			w += d
			d = 0
			break
		if a == 9:
			a = -1
		if b == 0:
			b = 10
		a += 1
		b -= 1
		d += 1
	c += 1
print(w)


n = int(input())
s1 = input()
s2 = input()
count = 0
for i in range(n):
	m = abs(int(s1[i]) - int(s2[i]))
	mw = min(m, 10 - m)
	count += mw
print(count)


number = int(input(''))
original = input('')
combination = input('')

def split(word):
	return list(word)
count = 0
originallist = split(original)
combinationlist = split(combination)
for f in range(0, number):
	currentoriginal = originallist[f]
	currentcombination = combinationlist[f]
	currentoriginal = int(currentoriginal)
	currentcombination = int(currentcombination)
	if abs(currentoriginal - currentcombination) > 5:
		count = count + (10 - abs(currentoriginal - currentcombination))
	else:
		count = count + abs(currentoriginal - currentcombination)
print(count)


numbers = int(input())
initialstate = list(input())
combo = list(input())
runningtotal = 0
for i in range(0, numbers):
	difference = abs(int(initialstate[i]) - int(combo[i]))
	if difference <= 5:
		runningtotal += difference
	else:
		runningtotal += 10 - difference
print(repr(runningtotal))


input()
combs = [input() for _ in range(2)]
turns = 0
for (x, y) in zip(*combs):
	diff = abs(int(x) - int(y))
	turns = turns + min(diff, 10 - diff)
print(turns)


n = int(input())
s = input()
s = list(s)
c = input()
c = list(c)
k = 0
for i in range(n):
	d = int(s[i]) - int(c[i])
	if d < 0:
		d = -d
	else:
		d = d
	if d > 5:
		x = 9 - d
		x = x + 1
		k = k + x
	else:
		k = k + d
print(k)


import math
n = int(input())
p = input()
s = input()
i = 0
out = 0
while i < n:
	out += min(abs(int(p[i]) - int(s[i])), abs(10 + int(p[i]) - int(s[i])), abs(10 + int(s[i]) - int(p[i])))
	i += 1
print(out)


n = int(input())
s = input()
o = input()
l = []
for i in range(n):
	d = abs(int(s[i]) - int(o[i]))
	if d <= 5:
		l.append(d)
	else:
		l.append(10 - d)
print(sum(l))


no = int(input())
x = input()
y = input()
move = 0
for i in range(no):
	f = int(x[i])
	n = int(y[i])
	move += min(abs(9 - f + n + 1), abs(f - n), abs(9 - n + 1 + f))
print(move)


def main():
	n = int(input())
	state = [int(_) for _ in input()]
	code = [int(_) for _ in input()]
	n_actions = 0
	for i in range(n):
		distance = abs(state[i] - code[i])
		distance = min(distance, 10 - distance)
		n_actions += distance
	print(n_actions)
main()


n = int(input())
ori = [int(i) for i in str(input())]
key = [int(i) for i in str(input())]
c = 0
for i in range(n):
	x = abs(ori[i] - key[i])
	a = min(x, 10 - x)
	c += a
print(c)


n = int(input())
s = input()
s1 = input()
ans = 0
for i in range(n):
	a = int(min(s[i], s1[i])) + 10 - int(max(s[i], s1[i]))
	b = abs(int(s[i]) - int(s1[i]))
	ans += min(a, b)
print(ans)


n = int(input())
ini = input()
fin = input()
times_to_rotate = 0
for j in range(n):
	i = int(ini[j])
	f = int(fin[j])
	times_to_rotate += min(max(i, f) - min(i, f), 10 - max(i, f) + min(i, f))
print(times_to_rotate)


n = int(input())
initial = input()
final = input()
count = 0
for i in range(n):
	if initial[i] > final[i]:
		count += min(abs(int(initial[i]) - int(final[i])), 9 - int(initial[i]) + int(final[i]) + 1)
	else:
		count += min(abs(int(final[i]) - int(initial[i])), 9 - int(final[i]) + int(initial[i]) + 1)
print(count)


n = int(input())
old = input()
new = input()
old = list(old)
new = list(new)
count = 0
for i in range(n):
	delta = abs(int(old[i]) - int(new[i]))
	deltaAdd10 = 10 - delta
	count += min(delta, deltaAdd10)
print(count)


input()
k = 0
for (a, b) in zip(input(), input()):
	(a, b) = map(int, (a, b))
	if a > b:
		if a - b > 5:
			k += 10 + b - a
		else:
			k += a - b
	elif b - a > 5:
		k += 10 + a - b
	else:
		k += b - a
print(k)


q = int(input())
w = input()
e = input()
r = 0
for i in range(q):
	r += min(abs(int(w[i]) - int(e[i])), min(int(w[i]), int(e[i])) + 10 - max(int(w[i]), int(e[i])))
print(r)


def move(a, b):
	return min(abs(a - b), 10 - abs(a - b))
n = int(input())
start = str(input())
end = str(input())
moves = 0
for i in range(n):
	moves += move(int(start[i]), int(end[i]))
print(moves)


x = int(input())
a = input()
b = input()
s = 0
for i in range(len(a)):
	if int(a[i]) >= int(b[i]):
		if int(a[i]) - int(b[i]) <= 10 - int(a[i]) + int(b[i]):
			s = s + int(a[i]) - int(b[i])
		else:
			s = s + 10 - int(a[i]) + int(b[i])
	elif int(b[i]) - int(a[i]) <= 10 - int(b[i]) + int(a[i]):
		s = s + int(b[i]) - int(a[i])
	else:
		s = s + 10 - int(b[i]) + int(a[i])
print(s)


def reel(a, b):
	if a > b:
		(a, b) = (b, a)
	return min(b - a, a - b + 10)
n = int(input())
s1 = input()
s2 = input()
res = 0
for i in range(n):
	res += reel(int(s1[i]), int(s2[i]))
print(res)


p = int(input())
q = 0
a = input()
a = list((int(i) for i in str(a)))
b = input()
b = list((int(j) for j in str(b)))
for k in range(p):
	q = q + min(abs(a[k] - b[k]), 10 - abs(a[k] - b[k]))
print(q)


c = int(input())
a = input()
b = input()
l = 0
for i in range(0, c):
	d = abs(int(a[i]) - int(b[i]))
	m = min(d, abs(10 - d))
	l += m
print(l)


x = int(input())
in1 = input()
in2 = input()
str1 = list()
str2 = list()
moves = 0
for i in range(x):
	str1.append(int(in1[i]))
	str2.append(int(in2[i]))
for i in range(x):
	if str1[i] < str2[i]:
		res1 = str2[i] - str1[i]
		res2 = str1[i] + 10 - str2[i]
		if res1 <= res2:
			moves += res1
		else:
			moves += res2
	elif str1[i] > str2[i]:
		res1 = str1[i] - str2[i]
		res2 = str2[i] + 10 - str1[i]
		if res1 <= res2:
			moves += res1
		else:
			moves += res2
print(moves)


i = input
f = lambda : map(int, list(i()))
i()
print(sum([min(abs(a - b), 10 - max(a, b) + min(a, b)) for (a, b) in zip(f(), f())]))


(n, a, b) = (int(input()), input(), input())
solve = 0
for i in range(n):
	if abs(int(a[i]) - int(b[i])) >= 5:
		solve += 10 - abs(int(a[i]) - int(b[i]))
	else:
		solve += abs(int(a[i]) - int(b[i]))
print(solve)


n = int(input())
a = input()
b = input()
s = 0
for i in range(len(a)):
	if abs(int(a[i]) - int(b[i])) <= 4:
		s = s + abs(int(a[i]) - int(b[i]))
	else:
		s = s + (10 - abs(int(a[i]) - int(b[i])))
print(s)


n = int(input())
i = 0
y = int(input())
z = int(input())
b = 0
c = 0
d = 0
x = 0
for a in range(0, n):
	b = y % 10
	c = z % 10
	y //= 10
	z //= 10
	if b > c:
		d = 10 - (b - c)
		if b - c < d:
			x += b - c
		else:
			x += d
	else:
		d = 10 - (c - b)
		if c - b < d:
			x += c - b
		else:
			x += d
print(x)


rolls = int(input())
start = str(input())
finish = str(input())
actions = temp_actions = 0
for i in range(rolls):
	if start[i] > finish[i]:
		temp_actions = int(start[i]) - int(finish[i])
		if temp_actions <= 5:
			actions += temp_actions
		else:
			actions += 10 - temp_actions
	else:
		temp_actions = int(finish[i]) - int(start[i])
		if temp_actions <= 5:
			actions += temp_actions
		else:
			actions += 10 - temp_actions
print(actions)


ret = 0
count1 = 0
count2 = 0
pos = 0
disks = int(input())
original = input()
ans = input('')
original_int = int(original)
ans_int = int(ans)
for i in range(disks):
	pos = int(original[i])
	det = int(ans[i])
	ret = ret + min(abs(pos - (det + 10)), abs(pos - det), pos + 10 - det)
print(ret)


n = int(input())
count = 0
original = list(map(int, input()))
combination = list(map(int, input()))
for i in range(0, n):
	if abs(original[i] - combination[i]) <= 5:
		count = abs(original[i] - combination[i]) + count
	else:
		count = 10 - abs(original[i] - combination[i]) + count
print(count)


n = int(input())
s = input()
s1 = input()
t = 0
for i in range(n):
	x = int(s[i])
	y = int(s1[i])
	t += min(abs(y - x), 10 - max(x, y) + min(x, y))
print(t)


def md(a, b):
	d1 = abs(a - b)
	d2 = 10 - max(a, b) + min(a, b)
	return min(d1, d2)
n = int(input())
a = input()
b = input()
if n == 1:
	if a == b:
		print('0')
	else:
		print(md(int(a), int(b)))
elif a[0] == '0':
	d = md(int(a[0]), int(b[0]))
	a = a[1:]
	b = b[1:]
	a = int(a)
	b = int(b)
	steps = 0
	while a:
		n1 = a % 10
		n2 = b % 10
		steps += md(n1, n2)
		a = a // 10
		b = b // 10
	print(steps + d)
else:
	a = int(a)
	b = int(b)
	steps = 0
	while a:
		n1 = a % 10
		n2 = b % 10
		steps += md(n1, n2)
		a = a // 10
		b = b // 10
	print(steps)


n = int(input())
inst = input().strip()
fist = input().strip()
moves = 0
i = 0
while i < n:
	x = abs(int(fist[i]) - int(inst[i]))
	if x > 5:
		x = 10 - x
	moves += x
	i = i + 1
print(moves)


n = int(input())
a = input()
b = input()
c = 0
for i in range(n):
	c += min(abs(int(a[i]) - int(b[i])), 10 + min(int(a[i]), int(b[i])) - max(int(a[i]), int(b[i])))
print(c)


n = int(input())
original_state = input()
combination = input()
actions = 0
for (i, j) in zip(original_state, combination):
	actions += min(abs(int(i) - int(j)), 10 - abs(int(i) - int(j)))
print(actions)


n = int(input())
a = input()
b = input()
ans = 0
for i in range(n):
	ans += min(abs(int(a[i]) - int(b[i])), abs(int(max(a[i], b[i])) - int('1' + min(a[i], b[i]))))
print(ans)


noOfWheels = int(input())
count = 0
initial = int(input())
final = int(input())
currvalue = 0
for i in range(noOfWheels):
	diff = initial % 10 - final % 10
	if diff < 0:
		diff = -1 * diff
	if diff > 5:
		diff = 10 - diff
	initial = initial // 10
	final = final // 10
	count += diff
print(count)


n = int(input())
p = 0
x = 0
p1 = []
p2 = []
p1 = int(input())
p2 = int(input())
while x < n:
	x1 = p1 % 10
	p1 = p1 // 10
	x2 = p2 % 10
	p2 = p2 // 10
	a1 = abs(x1 - x2)
	a2 = abs(x1 + 10 - x2)
	a3 = abs(x2 + 10 - x1)
	p = p + min(a1, a2, a3)
	x = x + 1
print(p)


n = int(input())
s = input()
s1 = input()
arr1 = [i for i in s]
arr2 = [i for i in s1]
sum = 0
for i in range(n):
	if abs(int(arr1[i]) - int(arr2[i])) <= 5:
		sum += abs(int(arr1[i]) - int(arr2[i]))
	else:
		sum += abs(9 - max(int(arr1[i]), int(arr2[i])) + min(int(arr1[i]), int(arr2[i])) + 1)
print(sum)


n = int(input())
nach = input().rstrip()
nach = [int(nach[i]) for i in range(n)]
need = input().rstrip()
need = [int(need[i]) for i in range(n)]
s = 0
for i in range(n):
	s += min(abs(nach[i] - need[i]), 10 - abs(nach[i] - need[i]))
print(s)


n = int(input())
(a, b) = map(lambda x: [int(c) for c in x], (input(), input()))
r = sum((min(abs(x - y), abs(y - x), abs(x + 10 - y), abs(y + 10 - x)) for (x, y) in zip(a, b)))
print(r)


z = list(map(int, input().split()))
n = z[0]
inp = list(input())
out = list(input())
ans = 0
for i in range(n):
	if abs(int(inp[i]) - int(out[i])) > 5:
		ans += 10 - abs(int(inp[i]) - int(out[i]))
	else:
		ans += abs(int(inp[i]) - int(out[i]))
print(ans)


n = int(input())
a = [int(d) for d in input()]
b = [int(d) for d in input()]
s = 0
for i in range(n):
	x = abs(a[i] - b[i])
	y = 9 - max(a[i], b[i]) + min(a[i], b[i]) + 1
	s = s + min(x, y)
print(s)


n = int(input())
a = list(input())
b = list(input())
c = 0
for i in range(n):
	z = abs(int(a[i]) - int(b[i]))
	if z <= 5:
		c += z
	else:
		c += 10 - z
print(c)


def get_value():
	digits = int(input())
	initial_pos = input()
	pass_lock = input()
	count = 0
	for i in range(digits):
		if initial_pos[i] == pass_lock[i]:
			continue
		first_version = abs(int(initial_pos[i]) - int(pass_lock[i]))
		second_version = 9 - max([int(initial_pos[i]), int(pass_lock[i])]) + (1 + min([int(initial_pos[i]), int(pass_lock[i])]))
		count += min([first_version, second_version])
	return count
print(get_value())


n = int(input())
s = input()
s1 = input()
steps = 0
for _ in range(n):
	diff = abs(int(s[_]) - int(s1[_]))
	steps += min(diff, 10 - diff)
print(steps)


t = int(input())
p = 0
a = input()
b = input()
n = 0
while p < t:
	e = int(a[p])
	f = int(b[p])
	c = abs(e - 9) + abs(f) + 1
	d = abs(f - 9) + abs(e) + 1
	n = n + min(abs(e - f), c, d)
	p = p + 1
print(n)


n = int(input())
w = [int(i) for i in input()]
o = [int(i) for i in input()]
res = 0
for i in range(n):
	res += min(abs(w[i] - o[i]), 10 - abs(w[i] - o[i]))
print(res)


n = int(input())
g = input()
ans = input()
total = 0
for i in range(n):
	a = int(g[i])
	b = int(ans[i])
	if abs(a - b) > 5:
		total += min(a, b) + 10 - max(a, b)
	else:
		total += abs(a - b)
print(total)


import math
n = int(input())
a = str(input())
b = str(input())
ans = 0
for i in range(n):
	x = int(a[i])
	y = int(b[i])
	if math.fabs(x - y) > 5:
		ans += math.fabs(math.fabs(x - y) - 10)
	else:
		ans += math.fabs(x - y)
print(int(ans))


def f1(x, y):
	(a, b) = (0, 0)
	if x > y:
		(a, b) = (x - y, y + 10 - x)
	elif x < y:
		(a, b) = (10 - y + x, y - x)
	if a <= b:
		return a
	else:
		return b

def f2(x, y):
	total = 0
	for i in range(len(x)):
		(a, b) = (int(x[i]), int(y[i]))
		total += f1(a, b)
	return total
n = int(input())
x = input()
y = input()
print(f2(x, y))


class lock:
	from sys import stdin, stdout
	n = int(stdin.readline().rstrip(), 10)
	num1 = stdin.readline().rstrip()
	num2 = stdin.readline().rstrip()
	a = [int(x) for x in str(num1)]
	b = [int(x) for x in str(num2)]
	cnt = 0
	for x in range(0, n):
		dif = abs(a[x] - b[x])
		cnt += min(dif, 10 - dif)
	stdout.write(str(cnt) + '\n')


loop = input()
o_disk = input()
c_disk = input()
moves = 0
list = [0, 0]
for i in range(int(loop)):
	list[0] = abs(int(o_disk[i]) - int(c_disk[i]))
	list[1] = 10 - list[0]
	moves += min(list)
print(moves)


n = int(input())
inp1 = input()
inp2 = input()
res = 0
for (a, b) in zip(inp1, inp2):
	a = int(a)
	b = int(b)
	res += min(abs(b - a), abs(10 + b - a), abs(10 + a - b))
print(res)


n = int(input())
s = input().strip()[:n]
l = input().strip()[:n]
j = 0
for x in range(len(s)):
	p = abs(int(s[x]) - int(l[x]))
	if p >= 5:
		if l[x] > s[x]:
			p = 10 + int(s[x]) - int(l[x])
		elif s[x] > l[x]:
			p = 10 + int(l[x]) - int(s[x])
	j = j + p
print(j)


x = int(input())
(a, b) = (input(), input())
d = 0
for i in range(x):
	d += min(abs(int(a[i]) - int(b[i])), min(int(a[i]), int(b[i])) + 10 - max(int(a[i]), int(b[i])))
print(d)


n = int(input())
l = list(input())
f = list(input())
for i in range(n):
	l[i] = int(l[i])
	f[i] = int(f[i])
k = 0

def mod(x):
	if x >= 0:
		return x
	else:
		return -x

def mini(a, b):
	if a > b:
		(a, b) = (b, a)
	if mod(a - b) > mod(9 - b + 1 + a):
		return mod(9 - b + 1 + a)
	else:
		return mod(a - b)
for i in range(n):
	if l[i] == f[i]:
		continue
	else:
		k += mini(l[i], f[i])
print(k)


import sys
n = int(sys.stdin.readline())
start = sys.stdin.readline().strip()
end = sys.stdin.readline().strip()
count = 0
for i in range(n):
	(x, y) = (int(start[i]), int(end[i]))
	if x == y:
		continue
	if x > y:
		count += min(x - y, y + 10 - x)
	else:
		count += min(y - x, x + 10 - y)
print(count)


n = int(input())
s = int(input())
d = int(input())
c = 0
for i in range(n):
	s1 = s % 10
	d1 = d % 10
	t = max(s1, d1) - min(s1, d1)
	c += min(t, 10 - t)
	s = s // 10
	d //= 10
print(c)


com = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

def check(a, b):
	aa = max(a, b)
	bb = min(a, b)
	if aa - bb > 5:
		return 10 - aa + bb
	return aa - bb
n = int(input())
kil = 0
a = list(input())
b = list(input())
for i in range(n):
	kil += check(int(a[i]), int(b[i]))
print(kil)


import math
n = int(input())
(s, t) = (input(), input())
sum = 0
for i in range(n):
	a = int(s[i])
	b = int(t[i])
	mini = int(abs(a - b))
	sum += min(mini, 10 - mini)
print(sum)


def dis(a, b):
	if a < b:
		(a, b) = (b, a)
	return min(a - b, 10 - a + b)
n = int(input())
str1 = input()
str2 = input()
ans = 0
for i in range(0, n):
	a = ord(str1[i]) - ord('0')
	b = ord(str2[i]) - ord('0')
	ans += dis(a, b)
print(ans)


N = int(input())
str1 = input()
str2 = input()
sum1 = 0
for i in range(N):
	if int(str1[i]) > int(str2[i]):
		(max, min) = (int(str1[i]), int(str2[i]))
	else:
		(max, min) = (int(str2[i]), int(str1[i]))
	if max - min > 5:
		sum1 += 10 - (max - min)
	else:
		sum1 += max - min
print(sum1)


n = int(input())
first = input()
second = input()
count = 0
for x in range(n):
	num = abs(int(first[x]) - int(second[x]))
	count += min(num, 10 - num)
print(count)


import math
n = int(input())
a = [int(x) for x in input()]
b = [int(x) for x in input()]
c = 0
for i in range(n):
	r = math.fabs(a[i] - b[i])
	if r > 5:
		r = 10 - r
	c += r
print(int(c))


t = int(input())
a = input()
b = input()
sum = 0
for i in range(t):
	if abs(int(b[i]) - int(a[i])) >= 0 and abs(int(b[i]) - int(a[i])) <= 5:
		sum = sum + abs(int(b[i]) - int(a[i]))
	else:
		sum = sum + (10 - abs(int(b[i]) - int(a[i])))
print(sum)


d = int(input())
sta = list(input())
target = list(input())
count = 0
total = 0
while count < d:
	m1 = abs(int(sta[count]) - int(target[count]))
	if int(sta[count]) > 5:
		m2 = 10 - int(sta[count]) + int(target[count])
	else:
		m2 = int(sta[count]) + (10 - int(target[count]))
	if m1 < m2:
		total += m1
	else:
		total += m2
	count += 1
print(total)


n = int(input())
a = input()
b = input()
f = 0
count = 0
for i in range(n):
	f = abs(int(a[i]) - int(b[i]))
	count += min(f, 10 - f)
print(count)


n = int(input())
a = input()
b = input()
c = 0
for i in range(n):
	k = int(a[i]) - int(b[i])
	if k < 0:
		k = -k
	if k > 5:
		k = 10 - k
	c += k
print(c)


n = int(input())
pos = list(input())
des = list(input())
d = {6: 4, 7: 3, 8: 2, 9: 1}
ans = 0
for i in range(n):
	a = int(pos[i])
	b = int(des[i])
	k = abs(b - a)
	if k in d.keys():
		ans += d[k]
	else:
		ans += k
print(ans)


n = int(input())
nums1 = [int(i) for i in list(input())]
nums2 = [int(i) for i in list(input())]
mx = 0
mn = 0
steps = 0
for i in range(n):
	mx = max(nums1[i], nums2[i])
	mn = min(nums1[i], nums2[i])
	steps += min(mx - mn, mn + 10 - mx)
print(steps)


n = int(input())
original = [int(x) for x in input()]
password = [int(x) for x in input()]

def distance(a, b):
	dist = abs(a - b)
	return min(dist, 10 - dist)
print(sum((distance(a, b) for (a, b) in zip(original, password))))


n = int(input())
mas1 = [int(x) for x in list(input())]
mas2 = [int(x) for x in list(input())]
x = 0
for i in range(n):
	x += min(abs(mas1[i] - mas2[i]), min(mas1[i], mas2[i]) + 10 - max(mas1[i], mas2[i]))
print(x)


n = int(input())
orig = input()
final = input()
total = 0
for i in range(n):
	origI = int(orig[i])
	finalI = int(final[i])
	if abs(origI - finalI) <= 5:
		total += abs(origI - finalI)
	else:
		total += 10 - abs(origI - finalI)
print(total)


l = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
s = 0
for i in range(l):
	d = abs(a[i] - b[i])
	if d <= 5:
		s += d
	else:
		c = 10 - d
		s += c
print(s)


import math
import os
import random
import re
import sys
a = int(input())
b = str(input())
v = str(input())
l1 = []
l2 = []
for x in range(a):
	l1.append(int(b[x]))
	l2.append(int(v[x]))
c = 0
for y in range(a):
	if abs(l1[y] - l2[y]) > 5:
		c = c + 10 - abs(l1[y] - l2[y])
	else:
		c = c + abs(l1[y] - l2[y])
print(c)


r = int(input())
num1 = input()
num2 = input()
w = 0
for i in range(r):
	c = abs(int(num1[i]) - int(num2[i]))
	if c > 5:
		w += 10 - c
	else:
		w += c
print(w)


n = input()
str1 = input()
str2 = input()
s = sum([5 - abs(abs(int(str1[i]) - int(str2[i])) - 5) for i in range(0, int(n))])
print(s)


n = int(input())
s1 = input()
s2 = input()
count = 0
for i in range(n):
	a = int(s1[i])
	b = int(s2[i])
	if a > b:
		if a - b > 5:
			count = count + 10 - a + b
		else:
			count = count + a - b
	if b > a:
		if b - a > 5:
			count = count + 10 - b + a
		else:
			count = count + b - a
	if a == b:
		count = count
print(count)


l = int(input())
a = input()
b = input()
t = 0
for i in range(len(a)):
	c = int(a[i])
	d = int(b[i])
	diff = abs(c - d)
	if diff > 5:
		diff = 10 - diff
	t += diff
print(t)


steps = 0
n = int(input())
original = list(input())
final = list(input())
dict = {6: 4, 7: 3, 8: 2, 9: 1}
for i in range(0, n):
	a = abs(int(final[i]) - int(original[i]))
	if a <= 5:
		steps += a
	else:
		steps += dict[a]
print(steps)


num = int(input())
data1 = input()
data2 = input()
moves = 0
for i in range(num):
	m = abs(int(data1[i]) - int(data2[i]))
	moves += min(m, 10 - m)
print(moves)


import math
x = input()
y = input()
z = input()
a = list(y)
b = list(z)
t = 0
rounds = 0
while t < int(x):
	m = abs(int(a[t]) - int(b[t]))
	n = 10 - m
	rounds += min(m, n)
	t += 1
print(rounds)


n = int(input())
s1 = str(input())
s2 = str(input())
S = 0
for i in range(n):
	t = abs(int(s1[i]) - int(s2[i]))
	if t > 5:
		t = 10 - t
	S += t
print(S)


l = int(input())
s1 = list(map(int, input().replace('', ' ').split()))
s2 = list(map(int, input().replace('', ' ').split()))
res = 0
for i in range(l):
	res += min(abs(s1[i] - s2[i]), 10 - abs(s1[i] - s2[i]))
print(res)


digits = int(input())
current_state = input()
original_state = input()
total_moves = 0
for i in range(len(current_state)):
	current = int(current_state[i])
	original = int(original_state[i])
	difference = abs(current - original)
	if difference >= 6:
		difference = 6 - abs(6 - difference) - 2
	total_moves += difference
print(total_moves)


n = input()
n = int(n)
a = input()
b = input()
ans = 0
for i in range(0, len(a)):
	d = a[i]
	d = int(d)
	e = b[i]
	e = int(e)
	ss = d - e
	if ss < 0:
		ss = ss * -1
	ans = ans + min(ss, 10 - ss)
print(ans)


n = int(input())
now = input()
key = input()
t = 0
for i in range(n):
	(n, k) = (int(now[i]), int(key[i]))
	if n > k:
		t += min(n - k, k + (10 - n))
	else:
		t += min(k - n, 10 - k + n)
print(t)


n = int(input())
a = input()
b = input()
total = 0
for i in range(0, n):
	n = int(a[i])
	m = int(b[i])
	if n > m:
		t = n - m
		k = 9 - n + (m + 1)
		total = total + min(t, k)
	elif m > n:
		t = m - n
		k = n - 1 + (11 - m)
		total = total + min(t, k)
	elif m == n:
		total = total + 0
print(total)


n = int(input())
c = input()
ans = input()
moves = 0
for i in range(0, n):
	(num1, num2) = (int(c[i]), int(ans[i]))
	h1 = abs(num1 - num2)
	h2 = 10 - max(num1, num2) + min(num1, num2)
	moves += min(h1, h2)
print(moves)


N = int(input())
S1 = input()
S2 = input()
ans = 0
for (s1, s2) in zip(S1, S2):
	ss1 = int(s1)
	ss2 = int(s2)
	tmp = min(abs(ss1 - ss2), 10 - abs(ss1 - ss2))
	ans += tmp
print(ans)


n = int(input())
a = input()
b = input()
a1 = []
b1 = []
s = 0
for i in range(n):
	a1.append(int(a[i]))
	b1.append(int(b[i]))
for i in range(n):
	if a1[i] <= b1[i]:
		k = a1[i] + 10 - b1[i]
		c = b1[i] - a1[i]
		s = s + min(k, c)
	else:
		k = min(b1[i] + 10 - a1[i], a1[i] - b1[i])
		s = s + k
print(s)


l = int(input())
a = input()
b = input()
s = 0
for i in range(l):
	m = int(a[i]) - int(b[i])
	if m < 0:
		m = -m
	if m > 5:
		m = 10 - m
	s = s + m
print(s)


num_disks = int(input())
orig_state = [int(i) for i in input()]
last_state = [int(i) for i in input()]

def unlock(num_disks, orig_state, last_state):
	l = [last_state[i] - orig_state[i] for i in range(num_disks)]
	result = 0
	for i in range(num_disks):
		if abs(l[i]) > 5:
			l[i] = 10 - abs(l[i])
		result += abs(l[i])
	return result
print(unlock(num_disks, orig_state, last_state))


n = int(input())
A = map(int, input())
B = map(int, input())
print(sum((min(abs(x - y), 10 - abs(x - y)) for (x, y) in zip(A, B))))


n = int(input())
a = [int(c) for c in input()]
b = [int(c) for c in input()]
counter = 0
for i in range(n):
	aa = min(a[i], b[i])
	bb = max(a[i], b[i])
	counter += min(bb - aa, 10 + aa - bb)
print(counter)


n = int(input())
st = input()
st2 = input()
l1 = [int(i) for i in st]
l2 = [int(i) for i in st2]
total = 0
for i in range(n):
	d = abs(l1[i] - l2[i])
	if d > 5:
		d = 10 - d
	total += d
print(total)


n = int(input())
s1 = input()
s2 = input()
k = 0
for i in range(len(s1)):
	d1 = int(s1[i])
	d2 = int(s2[i])
	if d1 > d2:
		k += min(d1 - d2, d2 + 10 - d1)
	else:
		k += min(d2 - d1, d1 + 10 - d2)
print(k)


n = int(input())
f = int(input())
s = int(input())
(a, b) = (0, 0)
sum = 0
for i in range(n):
	a = f % 10
	b = s % 10
	if abs(a - b) > 5:
		sum += 10 - abs(a - b)
	else:
		sum += abs(a - b)
	f = f // 10
	s = s // 10
print(sum)


input()
a = input()
b = input()
i = 0
ans = 0
while i < len(a):
	if abs(int(a[i]) - int(b[i])) > abs(10 - abs(int(a[i]) - int(b[i]))):
		ans = ans + abs(10 - abs(int(a[i]) - int(b[i])))
	else:
		ans = ans + abs(int(a[i]) - int(b[i]))
	i = i + 1
print(ans)


def sultan(x, y):
	(x, y) = (int(x), int(y))
	if x > y:
		t = x
		x = y
		y = t
	return min(y - x, 10 - y + x)
n = int(input())
s = input()
t = input()
ans = 0
for i in range(n):
	ans += sultan(s[i], t[i])
print(ans)


n = int(input())
s1 = input()
s2 = input()
c = 0
for i in range(n):
	v = [ord(s1[i]), ord(s2[i])]
	v.sort()
	c += min(v[1] - v[0], v[0] + 10 - v[1])
print(c)


n = int(input())
L1 = [int(t) for t in list(input())]
L = [int(t) for t in list(input())]
v = 0
for i in range(n):
	t = min(abs(L[i] - L1[i]), 10 - abs(L[i] - L1[i]))
	v += t
print(v)


a = int(input())
b = input()
c = input()
s = []
t = []
x = 0
for i in range(a):
	s.append(int(b[i]))
	t.append(int(c[i]))
for j in range(a):
	if abs(s[j] - t[j]) <= 5:
		x = x + abs(s[j] - t[j])
	else:
		x = x + 10 - abs(s[j] - t[j])
print(x)


n = int(input())
l = int(input())
m = int(input())
c = 0
while n:
	a = l % 10
	b = m % 10
	if a == b:
		l = l // 10
		m = m // 10
	elif a < b:
		c += min(abs(a - b), a + 9 - b + 1)
		l = l // 10
		m = m // 10
	else:
		c += min(abs(a - b), 9 - a + b + 1)
		l = l // 10
		m = m // 10
	n -= 1
print(c)


n = int(input())
code_old = input()
code_new = input()
steps = 0
for i in range(n):
	steps_i = abs(int(code_new[i]) - int(code_old[i]))
	if steps_i > 5:
		steps_i = 10 - steps_i
	steps += steps_i
print(steps)


n = int(input())
k = 0
a = input()
b = input()
for i in range(len(a)):
	old = int(a[i])
	new = int(b[i])
	k += min(10 - old + new, min(abs(old - new), abs(old + 10 - new)))
print(k)


n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
print(sum([min(abs(a[i] - b[i] + 10) % 10, abs(b[i] - a[i] + 10) % 10) for i in range(n)]))


n = int(input())
c = input()
key = input()
c = [int(i) for i in c]
key = [int(i) for i in key]
k = 0
for i in range(n):
	k += min(abs(c[i] - key[i]), 10 - abs(c[i] - key[i]))
print(k)


def lock(string1, string2):
	total = 0
	for i in range(len(string1)):
		minimum = min(abs(int(string1[i]) - int(string2[i])), 10 - abs(int(string1[i]) - int(string2[i])))
		total = total + minimum
	return total
n = int(input())
string1 = list(input())
string2 = list(input())
print(lock(string1, string2))


n = int(input())
s1 = input()
s2 = input()
s = 0
for i in range(n):
	d = abs(int(s1[i]) - int(s2[i]))
	c = 10 - max(int(s1[i]), int(s2[i])) + min(int(s1[i]), int(s2[i]))
	s += min(c, d)
print(s)


n = int(input())
original = input()
target = input()
ans = 0
for i in range(n):
	d1 = int(original[i])
	d2 = int(target[i])
	ans += min(abs(d1 - d2), min(d1, d2) + 10 - max(d1, d2))
print(ans)


n = int(input())
ans = 0
a = input()
b = input()
temp = [5, 4, 3, 2, 1]
for i in range(len(a)):
	data = abs(int(str(a[i])) - int(str(b[i])))
	if data > 5:
		data = data % 5
		ans += temp[data]
	else:
		ans += data
print(ans)


def turnsCount(arr1, arr2):
	count = 0
	for i in range(len(arr1)):
		count += min(abs(arr1[i] - arr2[i]), abs(10 - abs(arr1[i] - arr2[i])))
	return count
n = int(input())
arr1 = list(map(int, list(input())))
arr2 = list(map(int, list(input())))
print(turnsCount(arr1, arr2))


si = int(input())
s1 = input()
l1 = [int(x) for x in str(s1)]
s2 = input()
c = 0
l2 = [int(x) for x in str(s2)]
for i in range(0, si):
	r1 = abs(l1[i] - l2[i])
	if l1[i] > l2[i]:
		r2 = l2[i] + (9 - l1[i]) + 1
	else:
		r2 = l1[i] + 1 + (9 - l2[i])
	if r1 > r2:
		c = c + r2
	else:
		c = c + r1
print(c)


n = int(input())
a = input()
b = input()
ans = 0
for i in range(n):
	aa = int(a[i])
	bb = int(b[i])
	d = abs(aa - bb)
	if d <= 5:
		ans += d
	elif aa < bb:
		g = 10 + aa - bb
		ans += g
	elif aa > bb:
		h = 10 + bb - aa
		ans += h
print(ans)


disks = int(input())
state = input()
combination = input()
pad = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
suma = 0
for n in range(disks):
	left = right = 0
	inicio = int(state[n])
	final = int(combination[n])
	curr_pos = pad.index(inicio)
	for n in range(10):
		if pad[curr_pos] == final:
			break
		else:
			curr_pos -= 1
			left += 1
	right = 10 - left
	if right <= left:
		suma = suma + right
	else:
		suma = suma + left
print(suma)


n = int(input())
s = input()
password = input()
moves = 0
for i in range(n):
	S = int(s[i])
	P = int(password[i])
	if S > P:
		moves += min(S - P, 10 - S + P)
	elif S < P:
		moves += min(P - S, S + 10 - P)
print(moves)


x = int(input())
s1 = input()
s2 = input()
k = 0
for i in range(x):
	k = k + min(abs(int(s1[i]) - int(s2[i])), 10 - abs(int(s1[i]) - int(s2[i])))
print(k)


input()
s1 = input()
s2 = input()
ans = 0
for f in range(len(s1)):
	if max(int(s1[f]), int(s2[f])) - min(int(s1[f]), int(s2[f])) <= 5:
		ans += max(int(s1[f]), int(s2[f])) - min(int(s1[f]), int(s2[f]))
	else:
		ans += min(int(s1[f]), int(s2[f])) + 10 - max(int(s1[f]), int(s2[f]))
print(ans)


n = int(input())
s = input()
s1 = input()
count = 0
for i in range(len(s)):
	if 10 - abs(int(s[i]) - int(s1[i])) >= abs(int(s[i]) - int(s1[i])):
		count += abs(int(s[i]) - int(s1[i]))
	else:
		count += 10 - abs(int(s[i]) - int(s1[i]))
print(count)


def func(a, b):
	array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
	if a != b:
		return min(abs(a - b), min(abs((10 + a - b) % 10), abs((10 + b - a) % 10)))
	return 0
n = int(input())
s1 = list(map(int, list(input())))
s2 = list(map(int, list(input())))
counter = 0
for i in range(len(s1)):
	counter += func(s1[i], s2[i])
print(counter)


T = int(input())
s1 = input()
s2 = input()
jarak = 0
for i in range(T):
	kondisi = []
	kondisi.append(abs(int(s1[i]) - int(s2[i])))
	kondisi.append(abs(9 - int(s1[i]) + int(s2[i]) + 1))
	kondisi.append(abs(9 - int(s2[i]) + int(s1[i]) + 1))
	jarak += min(kondisi)
print(jarak)


n = int(input())
a = input()
b = input()
r = 0
for i in range(n):
	(x, y) = (int(a[i]), int(b[i]))
	if x < y:
		w = min(y - x, x + 9 - y + 1)
	else:
		w = min(x - y, y + 9 - x + 1)
	r += w
print(r)


n = int(input())
ish = [int(i) for i in input()]
cmb = [int(i) for i in input()]
res = 0
for k in range(n):
	if ish[k] - cmb[k] <= 5 and ish[k] - cmb[k] >= -5:
		res += abs(ish[k] - cmb[k])
	else:
		res += 10 - abs(ish[k] - cmb[k])
print(res)


n = input()
a = input()
b = input()
s = 0
for i in range(int(n)):
	p = abs(int(a[i]) - int(b[i]))
	q = abs(int(b[i]) - int(a[i]))
	if p > 5:
		p = 10 - p
	s += p
print(s)


n = int(input())
s = list(input())
e = list(input())
an = 0
for i in range(len(s)):
	m1 = max(int(s[i]), int(e[i]))
	m2 = min(int(s[i]), int(e[i]))
	an += min(m1 - m2, m2 + 10 - m1)
print(an)


n = int(input())
s = input()
t = input()
v = 0
for i in range(n):
	x = int(s[i]) - int(t[i])
	a = x % 10
	b = (10 - x) % 10
	v += min(a, b)
print(v)


(n, lst) = (int(input()), list(zip(input(), input())))
print(sum([min(abs(int(lst[i][0]) - int(lst[i][1])), 10 - abs(int(lst[i][0]) - int(lst[i][1]))) for i in range(n)]))


n = int(input())
s1 = input()
s2 = input()
ans = 0
for i in range(n):
	a = int(s1[i])
	b = int(s2[i])
	ans += min(abs(a - b), abs(a - b + 10), abs(a - b - 10))
print(ans)


n = int(input())
code1 = [int(char) for char in input()]
code2 = [int(char) for char in input()]
N = 0
for i in range(n):
	if code2[i] > code1[i]:
		d = code2[i] - code1[i]
		N += min(d, 10 - d)
	else:
		d = code1[i] - code2[i]
		N += min(d, 10 - d)
print(N)


n = int(input())
disc_1 = input()
disc_2 = input()
s = 0
for i in range(n):
	s += min(abs(int(disc_1[i]) - int(disc_2[i])), 10 - abs(int(disc_1[i]) - int(disc_2[i])))
print(s)


n = int(input())
a = input()
b = input()

def cnt(a, b):
	(a, b) = (int(a), int(b))
	(a, b) = (min(a, b), max(a, b))
	return min(b - a, a + 10 - b)
ans = 0
for i in range(n):
	ans += cnt(a[i], b[i])
print(ans)


n = int(input())
x = input()
ans = input()
answer = 0
b = 0
c = 0
for i in range(0, n):
	if abs(int(x[i]) - int(ans[i])) <= 5:
		answer = answer + abs(int(x[i]) - int(ans[i]))
	else:
		a = 10 - abs(int(x[i]) - int(ans[i]))
		answer = answer + a
print(answer)


def diff(a, b):
	temp = abs(a - b)
	if temp > 5:
		return 10 - temp
	else:
		return temp
n = int(input())
total = 0
original = [int(x) for x in input()]
lock = [int(x) for x in input()]
for i in range(len(lock)):
	total += diff(original[i], lock[i])
print(total)


n = int(input())
a = input()
b = input()
f = 0
count = 0
for i in range(n):
	f = abs(int(a[i]) - int(b[i]))
	if f > 5:
		f = 10 - f
	count += f
print(count)


n = int(input())
p = input()
q = input()
cnt = 0
for i in range(0, n):
	if p[i] > q[i]:
		ans = int(p[i]) - int(q[i])
		if ans <= 5:
			cnt = cnt + ans
		else:
			ans = 10 - ans
			cnt = cnt + ans
	else:
		ans = int(q[i]) - int(p[i])
		if ans <= 5:
			cnt = cnt + ans
		else:
			ans = 10 - ans
			cnt = cnt + ans
print(cnt)


size = int(input())
a = input()
b = input()
ans = 0
for i in range(size):
	ans += min(10 - abs(int(a[i]) - int(b[i])), abs(int(a[i]) - int(b[i])))
print(ans)


from sys import stdout
num = int(input())
xRaw = input()
yRaw = input()
out = 0
for i in range(0, num):
	x = int(xRaw[i])
	y = int(yRaw[i])
	clk = abs(x - y if x > y else y - x)
	ctClk = abs(x - (y + 10) if x > y else y - (x + 10))
	out += clk if clk < ctClk else ctClk
stdout.write(str(out))


n = int(input())
l1 = list(map(int, input()))
l2 = list(map(int, input()))
res1 = []
res2 = []
x = 0
for i in range(n):
	res1.append(max(l1[i], l2[i]) - min(l1[i], l2[i]))
	res2.append(9 - max(l1[i], l2[i]) + min(l1[i], l2[i]) + 1)
	x += min(res1[i], res2[i])
print(x)


n = int(input())
st = input()
st2 = input()
cnt = cnt1 = 0
li = [str(x) for x in range(0, 10)]
c = v = 0
for i in range(n):
	ind = li.index(st[i])
	while li[ind] != st2[i]:
		if li[ind] == '9':
			ind = -1
		ind += 1
		c += 1
	ind = li.index(st[i])
	while li[ind] != st2[i]:
		ind -= 1
		v += 1
	if c > v:
		cnt += v
	else:
		cnt += c
	c = v = 0
print(cnt)


x = eval(input())
y = input()
z = input()
c = 0
i = 0
while i < x:
	m = int(y[i])
	n = int(z[i])
	if m > n:
		k = m - n
		o = 9 - m + n + 1
		if o >= k:
			c += k
		else:
			c += o
	elif m == n:
		c += 0
	elif n > m:
		k = n - m
		o = 9 - n + m + 1
		if o >= k:
			c += k
		else:
			c += o
	i += 1
print(c)


(n, a, b) = [input() for _ in ' ' * 3]
c = sum((min(abs(int(a[i]) - int(b[i])), 10 - int(a[i]) + int(b[i]), 10 - int(b[i]) + int(a[i])) for i in range(int(n))))
print(c)


n = int(input())
k = 0
a = list(map(int, list(input())))
b = list(map(int, list(input())))
for i in range(n):
	if abs(a[i] - b[i]) <= 5:
		k += abs(a[i] - b[i])
	elif abs(a[i] - b[i]) > 5:
		k += 10 - abs(a[i] - b[i])
print(k)


n = int(input())
(aa, bb) = (input(), input())
count = 0
for i in range(n):
	(a, b) = (int(aa[i]), int(bb[i]))
	t = abs(a - b)
	count += min(t, 10 - t)
print(count)


import math
n = int(input())
a = [int(i) for i in input()]
b = [int(i) for i in input()]
res = 0
for i in range(n):
	res += min(abs(a[i] - b[i]), 10 - abs(a[i] - b[i]))
print(res)


temp = input('')
a = input('')
b = input('')
res = 0
for (pos, num) in enumerate(a):
	s = int(num)
	e = int(b[pos])
	res = res + int(min(abs(s + 10 - e), abs(s - e), abs(s + 10 - e - 20)))
print(res)


n = int(input())
a = input()[0:n]
b = input()[0:n]
c = list(a)
d = list(b)
e = 0
for i in range(len(c)):
	f = 0
	x = 0
	if int(c[i]) == int(d[i]):
		e = e + 0
	elif int(c[i]) <= 5 and int(d[i]) <= 5:
		e = e + abs(int(c[i]) - int(d[i]))
	elif int(c[i]) >= 5 and int(d[i]) >= 5:
		e = e + abs(int(c[i]) - int(d[i]))
	elif int(c[i]) == 5 and int(d[i]) == 5:
		e = e + 0
	elif int(c[i]) <= 5 and int(d[i]) >= 5:
		x = x + (9 - int(d[i])) + 1 + int(c[i])
		f = f + (int(d[i]) - int(c[i]))
		e = e + min(x, f)
	elif int(c[i]) >= 5 and int(d[i]) <= 5:
		x = x + (9 - int(c[i]) + 1 + int(d[i]))
		f = f + (int(c[i]) - int(d[i]))
		e = e + min(x, f)
print(e)


n = int(input())
first = input()
second = input()
sum = 0
for i in range(n):
	b = abs(int(first[i]) - int(second[i]))
	if b > 5:
		b = 10 - b
	sum += b
print(sum)


n = int(input())
origin = input()
secret = input()
moves = 0
for i in range(n):
	move1 = abs(int(origin[i]) - int(secret[i]))
	move2 = 10 - move1
	moves = moves + min(move1, move2)
print(moves)


n = int(input())
s = input()
l = list(s)
t = input()
m = list(t)
c = 0
for i in range(n):
	if int(l[i]) >= 5 and int(m[i]) >= 5 or (int(l[i]) <= 5 and int(m[i]) <= 5):
		c += abs(int(l[i]) - int(m[i]))
	else:
		d = abs(int(min(l[i], m[i])) - int(0)) + abs(int(max(l[i], m[i])) - int(10))
		e = abs(int(l[i]) - int(m[i]))
		c += min(e, d)
print(c)


import math
n = int(input())
s1 = list(input())
s2 = list(input())
answer = 0
for i in range(n):
	a = int(s1[i])
	b = int(s2[i])
	answer += min(abs(a - b), 10 - max(a, b) + min(a, b))
print(answer)


def main():
	n = int(input())
	s = input()
	o = input()
	sum = 0
	for i in range(n):
		diff = abs(int(o[i]) - int(s[i]))
		sum += min(diff, 10 - diff)
	print(sum)
main()


n = int(input())
st = list((int(i) for i in input()))
fn = list((int(i) for i in input()))
t = 0
for j in range(n):
	if st[j] != fn[j]:
		t += min(max(st[j], fn[j]) - min(st[j], fn[j]), min(st[j], fn[j]) + 10 - max(st[j], fn[j]))
		st[j] = fn[j]
print(t)


n = int(input())
a = input()
b = input()
e = 0
c = []
for i in range(len(a)):
	e = abs(int(a[i]) - int(b[i]))
	if e <= 5:
		c = c + [e]
	else:
		c = c + [10 - e]
print(sum(c))


input()
m = list(map(int, input()))
n = list(map(int, input()))
a = 0
for i in range(len(m)):
	a += min(abs(m[i] - n[i]), abs(10 - abs(m[i] - n[i])))
print(a)


disk = int(input())
start = input()
target = input()
ans = 0
for i in range(disk):
	ans += min(abs(int(target[i]) - int(start[i])), 10 - max(int(target[i]), int(start[i])) + min(int(target[i]), int(start[i])))
print(ans)


n = int(input())
s1 = input()
s2 = input()
count = 0
for i in range(n):
	if s2[i] < s1[i]:
		a = int(s1[i]) - int(s2[i])
		b = 9 - int(s1[i]) + 1 + int(s2[i])
	else:
		a = int(s2[i]) - int(s1[i])
		b = 9 - int(s2[i]) + 1 + int(s1[i])
	if a < b:
		count += a
	else:
		count += b
print(count)


n = int(input())
l = list(map(int, input()))
k = list(map(int, input()))
c = 0
for i in range(n):
	if l[i] >= k[i]:
		m = l[i]
		c = c + min(abs(l[i] - k[i]), 10 - m + k[i])
	else:
		m = k[i]
		c = c + min(abs(l[i] - k[i]), 10 - m + l[i])
print(c)


n = int(input())
first_string = input()
second_string = input()
steps = 0
for i in range(n):
	a = int(first_string[i])
	b = int(second_string[i])
	steps += min([abs(a - b), abs(a + 10 - b), abs(a - (b + 10))])
print(steps)


(disks, lock1, lock2) = (int(input()), input(), input())
moves = 0
for pin in range(disks):
	(the1, the2) = (int(lock1[pin]), int(lock2[pin]))
	(max_, min_) = (max(the1, the2), min(the1, the2))
	a = max_ - min_
	b = 9 - max_ + min_ + 1
	moves += min(a, b)
print(moves)


n = int(input())
initial = input()
end = input()
sum = 0
for i in range(n):
	a = int(end[i])
	b = int(initial[i])
	sum += min(abs(a - b), abs(min(a, b) + 10 - max(a, b)))
print(sum)


n = int(input())
disk = input()
code = input()
j = 0
sum = 0
for i in disk:
	razn = abs(int(i) - int(code[j]))
	if razn <= 5:
		sum = sum + razn
	else:
		sum += 10 - razn
	j = j + 1
print(sum)


n = int(input())
currstate = str(input())
finalstate = str(input())
count = 0
for i in range(n):
	count += min(abs(int(currstate[i]) - int(finalstate[i])), 9 - abs(int(currstate[i]) - int(finalstate[i])) + 1)
print(count)


n = input()
m = input()
k = input()
turns = 0
for i in range(int(n)):
	x = int(k[i])
	y = int(m[i])
	if abs(x - y) < abs(10 - abs(x - y)):
		turns += abs(x - y)
	else:
		turns += abs(10 - abs(x - y))
print(turns)


n = int(input())
s = input()
z = input()
c = 0
for i in range(n):
	c = c + min(abs(int(s[i]) - int(z[i])), 10 - abs(int(s[i]) - int(z[i])))
print(c)


n = int(input())
start = list(input())
end = list(input())
total = 0
for i in range(0, n):
	d = int(start[i]) - int(end[i])
	if d < -5:
		total += 10 + d
	elif d < 0:
		total += -d
	elif d < 5:
		total += d
	else:
		total += 10 - d
print(total)


n = int(input())
s1 = input()
s2 = input()
d = 0
for i in range(n):
	number1 = int(s1[i])
	number2 = int(s2[i])
	d1 = abs(number1 - number2)
	d2 = 10 - number1 + number2
	d3 = 10 - number2 + number1
	d += min(d1, d2, d3)
print(d)


n = int(input())
start = tuple(map(int, tuple(input())))
end = tuple(map(int, tuple(input())))
td = 0
for i in range(0, n):
	diff = abs(end[i] - start[i])
	if diff > 4:
		diff = 10 - diff
	td += diff
print(td)


n = int(input())
start = int(input())
final = int(input())
count = 0
while n > 0:
	digitone = start % 10
	digittwo = final % 10
	big = max(digitone, digittwo)
	small = min(digitone, digittwo)
	turns = min(big - small, small + 10 - big)
	count = count + turns
	start = start // 10
	final = final // 10
	n = n - 1
print(count)


n = int(input())
lock = input()
unlock = input()
lst = [int(x) for x in range(10)]
c = 0
for i in range(n):
	n1 = int(lock[i])
	n2 = int(unlock[i])
	if n1 <= n2:
		k1 = int(str('1' + str(n1)))
		k = min(n2 - n1, k1 - n2)
		c += k
	else:
		k1 = int(str('1' + str(n2)))
		k = min(n1 - n2, k1 - n1)
		c += k
print(c)


n = int(input())
a = input()
b = input()
k = 0
for i in range(n):
	m = abs(int(a[i]) - int(b[i]))
	if m < 5:
		k += m
	else:
		k += 10 - m
print(k)


n = int(input())
c = 0
n1 = input()
n2 = input()
for i in range(n):
	c += min(abs(int(n1[i]) - int(n2[i])), abs(abs(int(n1[i]) - int(n2[i])) - 10))
print(c)


n = int(input())
z = input()
k = input()
s = 0
for (i, f) in zip(z, k):
	(i, f) = map(int, (i, f))
	s = s + min(abs(i - f), min(i, f) + 10 - max(i, f))
print(s)


n = int(input())
s1 = input()
s2 = input()
s = 0
for i in range(len(s1)):
	s = s + min(abs(int(s1[i]) - int(s2[i])), abs(int(s1[i]) + 9 - int(s2[i]) + 1), abs(9 - int(s1[i]) + int(s2[i]) + 1))
print(s)


N = int(input())
A = input()
B = input()
ans = 0
for i in range(N):
	a = int(A[i])
	b = int(B[i])
	ans += min(abs(a - b), 10 - abs(a - b))
print(ans)


import math
from collections import *
import sys
from functools import reduce

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
n = int(input())
s = input()
t = input()
ans = 0
for i in range(n):
	first = int(s[i])
	secon = int(t[i])
	diff = max(first, secon) - min(first, secon)
	ans += min(diff, 10 - diff)
print(ans)


n = int(input())
wrong = [int(i) for i in input()]
right = [int(i) for i in input()]
number = 0
for i in range(n):
	number += min(abs(wrong[i] - right[i]), 10 - wrong[i] + right[i], 10 - right[i] + wrong[i])
print(number)


n = int(input())
lock1 = input()
lock2 = input()
res = 0
for i in range(n):
	n1 = int(lock1[i])
	n2 = int(lock2[i])
	if n1 == n2:
		continue
	elif n1 > n2:
		a = 9 - n1 + 1 + n2
		b = n1 - n2
	else:
		a = n2 - n1
		b = n1 + 1 + 9 - n2
	res += min(a, b)
print(str(res))


disks = int(input())
originalState = [int(i) for i in list(input())]
openingState = [int(i) for i in list(input())]
minMoves = 0
for (i, digit) in enumerate(originalState):
	minMoves = minMoves + min(abs(originalState[i] - openingState[i]), 10 - abs(originalState[i] - openingState[i]))
print(minMoves)


x = int(input())
i = input()
f = input()
t = 0
for n in range(x):
	if int(i[n]) > int(f[n]):
		p = int(i[n]) - int(f[n])
		q = 10 - p
		if p <= q:
			t = t + p
		elif p > q:
			t = t + q
	elif int(i[n]) < int(f[n]):
		p = int(f[n]) - int(i[n])
		q = 10 - p
		if p <= q:
			t = t + p
		elif p > q:
			t = t + q
	elif int(i[n]) == int(f[n]):
		t = t + 0
print(t)


n = input()
a = input()
b = input()
print(sum(((lambda v: min(v, 10 - v))(abs(ord(i) - ord(j))) for (i, j) in zip(a, b))))


n = int(input())
a = [int(i) for i in list(str(input()))]
b = [int(j) for j in list(str(input()))]
count = 0
for k in range(n):
	x = min(a[k], b[k])
	y = max(a[k], b[k])
	z = min(y - x, 10 + x - y)
	count += z
print(count)


n = int(input())
l = list(input())
c = list(input())
s = 0
for i in range(n):
	l[i] = int(l[i])
	c[i] = int(c[i])
	m = abs(l[i] - c[i])
	if m < 5:
		s = s + m
	elif m >= 5:
		s = s + 10 - m
print(s)


n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
res = 0
for i in range(n):
	if a[i] > b[i]:
		if a[i] - b[i] < 5:
			res += a[i] - b[i]
		elif a[i] - b[i] >= 5:
			while a[i] != 9:
				res += 1
				a[i] += 1
			if a[i] == 9:
				res += 1
				c = b[i]
				res += c
	elif b[i] > a[i]:
		if b[i] - a[i] < 5:
			res += b[i] - a[i]
		elif b[i] - a[i] >= 5:
			while b[i] != 9:
				res += 1
				b[i] += 1
			if b[i] == 9:
				res += 1
				c = a[i]
				res += c
	else:
		res += 0
print(res)


n = int(input())
m = input()
o = input()
p = 0
for i in range(n):
	l = int(m[i])
	k = int(o[i])
	a = min(10 + l - k, 10 - l + k)
	b = abs(k - l)
	j = min(a, b)
	p += j
print(p)


import math
n = int(input())
a = int(input())
b = int(input())
c = 0
for i in range(n):
	t1 = a % 10
	t2 = b % 10
	t = abs(t1 - t2)
	if t <= 5:
		c += t
	else:
		c += 9 - max(t1, t2) + min(t1, t2) + 1
	a = a // 10
	b = b // 10
print(c)


def function1(s, e):
	k = 0
	for i in range(len(s)):
		(a, b) = (int(s[i]), int(e[i]))
		if b > a:
			(a, b) = (b, a)
		if a - b > 4:
			k += 10 - a + b
		else:
			k += a - b
	return k

def main():
	input()
	start = input()
	end = input()
	print(function1(start, end))
main()


n = int(input())
start = input()
target = input()
res = 0
for i in range(n):
	diff = abs(int(start[i]) - int(target[i]))
	if diff <= 5:
		res += diff
	else:
		res += 10 - diff
print(res)


len_n = int(input())
num1 = list(input())
num2 = list(input())
sum_num = []
for i in range(len_n):
	n = abs(int(num1[i]) - int(num2[i]))
	if n > 5:
		n = 10 - n
	sum_num.append(n)
print(sum(sum_num))


input()
State1 = list(map(int, input()))
State2 = list(map(int, input()))
Moves = 0
for i in range(State1.__len__()):
	(Curr1, Curr2) = (State1[i], State1[i])
	while Curr1 != State2[i] and Curr2 != State2[i]:
		Curr1 = (Curr1 + 1) % 10
		Curr2 = 9 if Curr2 - 1 < 0 else Curr2 - 1
		Moves += 1
print(Moves)


l = int(input())
random = input()
password = input()
s = str(random) + str(password)

def main(l, s):
	count = 0
	for i in range(len(s) - l):
		if int(s[i]) > int(s[i + l]):
			a = int(s[i]) - int(s[i + l])
			b = int(s[i + l]) + 10 - int(s[i])
			if a > b:
				count = count + b
			else:
				count = count + a
		else:
			a = int(s[i + l]) - int(s[i])
			b = int(s[i]) + 10 - int(s[i + l])
			if a > b:
				count = count + b
			else:
				count = count + a
	return count
print(main(l, s))


n = int(input())
a = [int(x) for x in input()]
b = [int(x) for x in input()]
s = len(a)
t = 0
for i in range(0, s):
	t = t + min(abs(a[i] - b[i]), 10 - abs(a[i] - b[i]))
print(t)


n = int(input())
x = input()
y = input()
count = 0
for i in range(0, n, 1):
	rotate1 = 10 - abs(int(x[i]) - int(y[i]))
	rotate2 = abs(int(x[i]) - int(y[i]))
	if rotate1 > rotate2:
		count += rotate2
	else:
		count += rotate1
print(count)


x = input()
k = 0
n1 = int(input())
n2 = int(input())
while n1 > 0 or n2 > 0:
	if abs(n1 % 10 - n2 % 10) < 10 - abs(n1 % 10 - n2 % 10):
		z = abs(n1 % 10 - n2 % 10)
		k += z
	else:
		y = 10 - abs(n1 % 10 - n2 % 10)
		k += y
	n1 //= 10
	n2 //= 10
print(int(k))


def diff(a, b):
	return min((int(a) - int(b) + 10) % 10, (int(b) - int(a) + 10) % 10)

def __starting_point():
	n = int(input())
	total = 0
	source = input()
	target = input()
	for i in range(len(source)):
		total += diff(source[i], target[i])
	print(total)
__starting_point()


n = input()
one = input()
two = input()
one = map(int, list(one))
two = map(int, list(two))
count = 0
for (x, y) in zip(one, two):
	count += min(abs(x - y), 10 - abs(x - y))
print(count)


n = int(input())
origin = input()
key = input()
count = 0
for i in range(n):
	org = int(origin[i])
	ky = int(key[i])
	a = abs(org - ky)
	b = 10 - max(org, ky) + min(org, ky)
	count += min(a, b)
print(count)


n = int(input())
s1 = input()
g1 = input()
count = 0
for i in range(n):
	s = int(s1[i])
	g = int(g1[i])
	count += min(abs(s - g), abs(10 + s - g), abs(10 + g - s))
print(count)


n = int(input())
num = input()
num2 = input()
num3 = 0
for i in range(n):
	temp = abs(int(num[i]) - int(num2[i]))
	num3 += min(temp, 10 - temp)
print(num3)


n = int(input())
arr1 = list(map(int, [i for i in input()]))
arr2 = list(map(int, [i for i in input()]))
ans = 0
for i in range(len(arr1)):
	ans += min(abs(arr1[i] - arr2[i]), 10 - abs(arr1[i] - arr2[i]))
print(ans)


ans = 0
n = int(input())
a = list(input())
b = list(input())
for i in range(len(a)):
	l1 = int(a[i])
	l2 = int(b[i])
	ans += min(abs(l1 - l2), 10 - abs(l1 - l2))
print(ans)
exit()


n = int(input())
s1 = input()
s2 = input()
ans = 0
for i in range(0, n):
	if int(s1[i]) > int(s2[i]):
		if int(s1[i]) - int(s2[i]) <= 9 - int(s1[i]) + int(s2[i]) + 1:
			ans += int(s1[i]) - int(s2[i])
		else:
			ans += 9 - int(s1[i]) + int(s2[i]) + 1
	elif int(s1[i]) < int(s2[i]):
		if int(s2[i]) - int(s1[i]) <= 9 - int(s2[i]) + int(s1[i]) + 1:
			ans += int(s2[i]) - int(s1[i])
		else:
			ans += 9 - int(s2[i]) + int(s1[i]) + 1
print(ans)


input()
current = [int(i) for i in list(input())]
target = [int(i) for i in list(input())]
actions = 0
for (i, j) in zip(current, target):
	difference = abs(i - j)
	actions += min(difference, abs(10 - difference))
print(actions)


a = int(input(''))
inputs = []
for value in range(2):
	inputs.append(input(''))

def scrubLord(a, b):
	c = max(a, b)
	d = min(a, b)
	g = c - d
	e = 10 - g
	return min(g, e)
ans = 0
for val in range(a):
	ans = ans + scrubLord(int(inputs[0][val]), int(inputs[1][val]))
print(ans)


n = int(input())
list1 = list(map(int, list(input())))
list2 = list(map(int, list(input())))
count = 0
for i in range(n):
	count += min(abs(list1[i] - list2[i]), abs(10 + list2[i] - list1[i]), abs(10 + list1[i] - list2[i]))
print(count)


n = int(input())
x = input()
y = input()
z = 0
for i in range(n):
	z = z + min(abs(int(x[i]) - int(y[i])), abs(abs(int(x[i]) - int(y[i])) - 10))
print(int(z))


def code(s1, s2):
	result = 0
	for i in range(len(s1)):
		result += min(abs(int(s1[i]) - int(s2[i])), min(int(s1[i]), int(s2[i])) + 10 - max(int(s1[i]), int(s2[i])))
	return result
n = int(input())
t1 = input()
t2 = input()
print(code(t1, t2))


from sys import stdin
i = [x.rstrip() for x in stdin.readlines()]
(l1, l2) = (i[1], i[2])
s = sum((min(abs(int(x) - int(y)), abs(10 + int(x) - int(y)), abs(-10 + int(x) - int(y))) for (x, y) in zip(l1, l2)))
print(s)


n = int(input())
c = input()
l = input()
moves = 0
for i in range(n):
	f = abs(int(c[i]) - int(l[i]))
	s = abs(10 - f)
	moves += min(f, s)
print(moves)


numdisk = int(input())
n1 = int(input())
n2 = int(input())
res = 0
for i in range(numdisk):
	tmp = n1 % 10
	tmp2 = n2 % 10
	diff = abs(tmp2 - tmp)
	if diff > 5:
		diff = 10 - diff
	res = res + diff
	n1 //= 10
	n2 //= 10
print(res)


n = int(input())
a = input()
b = input()
w = 0
for i in range(n):
	p = min(int(a[i]), int(b[i]))
	q = max(int(a[i]), int(b[i]))
	w += min(q - p, 10 + p - q)
print(w)


n = int(input())
d = 0
x = 0
y = 0
l1 = list(map(int, input()))
l2 = list(map(int, input()))
for i in range(n):
	x = max(l1[i], l2[i]) - min(l1[i], l2[i])
	y = min(l1[i], l2[i]) + 10 - max(l1[i], l2[i])
	if y >= x:
		d = d + x
	else:
		d = d + y
print(d)


n = int(input())
x = input()
y = input()
count = 0
for i in range(n):
	ab = abs(int(x[i]) - int(y[i]))
	if x[i] > y[i]:
		back = 9 - int(x[i]) + int(y[i]) + 1
	else:
		back = 9 - int(y[i]) + int(x[i]) + 1
	count += min([ab, back])
print(count)


n = int(input())
a = input()
b = input()
res = 0
for i in range(n):
	res += min(10 - abs(ord(a[i]) - ord(b[i])), abs(ord(a[i]) - ord(b[i])))
print(res)


n = int(input())
s1 = input()
s2 = input()
ans = 0
for i in range(n):
	if s1[i] >= s2[i]:
		ans += min(ord(s1[i]) - ord(s2[i]), 10 - ord(s1[i]) + ord(s2[i]))
	else:
		ans += min(ord(s2[i]) - ord(s1[i]), 10 - ord(s2[i]) + ord(s1[i]))
print(ans)


def main():
	n = int(input())
	totalMoves = 0
	initComb = input()
	finalComb = input()
	for i in range(n):
		initDigit = int(initComb[i])
		finalDigit = int(finalComb[i])
		difference = abs(initDigit - finalDigit)
		if difference > 5:
			difference = 10 - difference
		totalMoves += difference
	print(totalMoves)
	return ()
main()


n = int(input())
x = list(input())
x = list(map(int, x))
y = list(input())
y = list(map(int, y))
a = 0
for i in range(n):
	if x[i] <= y[i] and y[i] - x[i] <= 4:
		a += y[i] - x[i]
	elif x[i] < y[i]:
		a += 10 - y[i] + x[i]
	elif x[i] > y[i] and x[i] - y[i] <= 4:
		a += x[i] - y[i]
	else:
		a += 10 - x[i] + y[i]
print(a)


a = int(input())
b = list(input())
c = list(input())
d = 0
for i in range(a):
	e = int(b[i])
	f = int(c[i])
	g = abs(e - f)
	if g <= 5:
		d += g
	else:
		d += 10 - g
print(d)


def op(a, b):
	return min(abs(a - b), 10 - abs(a - b))
(n, q, k, ans) = (int(input()), input(), input(), 0)
for i in range(n):
	ans += op(int(q[i]), int(k[i]))
print(ans)


size = int(input())
curr = input()
original = input()
count = 0
for m in range(len(curr)):
	x = int(curr[m])
	y = int(original[m])
	a = abs(x - y)
	b = abs(x - 0) + abs(9 - y)
	c = abs(y - 0) + abs(9 - x)
	j = min(a, b, c)
	if a > min(b, c):
		count += j + 1
	else:
		count += j
print(count)


input()
k = 0
for (a, b) in zip(input(), input()):
	(a, b) = map(int, (a, b))
	m = abs(a - b)
	if m <= 5:
		k += m
	else:
		k += 10 - m
print(k)


def run():
	n = int(input())
	mine = str(input())
	target = str(input())
	summ = 0
	for i in range(n):
		a = int(mine[i])
		b = int(target[i])
		summ += min(abs(a - b), abs(10 + min(a, b) - max(a, b)))
	print(summ)
	return
run()


n = int(input())
l1 = list(map(int, input()))
l2 = list(map(int, input()))
k = []
for i in range(n):
	min1 = abs(l1[i] - l2[i])
	min2 = 10 - abs(l1[i] - l2[i])
	k.append(min(min1, min2))
print(sum(k))


n = int(input())
string1 = input()
string2 = input()
answer = 0
for i in range(n):
	answer += min(abs(int(string1[i]) - int(string2[i])), 10 - abs(int(string1[i]) - int(string2[i])))
print(answer)


import sys

def codes(inp, out, n):
	r = 0
	a = [int(i) for i in inp]
	b = [int(i) for i in out]
	for i in range(0, n):
		r += min(abs(a[i] - b[i]), 10 - abs(a[i] - b[i]))
	return r
n = int(input())
a = input()
b = input()
if len(a) != n or len(b) != n:
	sys.exit()
else:
	print(codes(a, b, n))


a = int(input())
b = int(input())
c = int(input())
sum = 0
while a > 0:
	val1 = b % 10
	val2 = c % 10
	b //= 10
	c //= 10
	a1 = abs(val1 - val2)
	a2 = min(val1, val2) + 10 - max(val1, val2)
	sum += min(a1, a2)
	a -= 1
print(sum)


n = int(input())
s1 = input()
s2 = input()
c = 0
for i in range(n):
	x = abs(int(s1[i]) - int(s2[i]))
	if x > 10 - x:
		c += 10 - x
	else:
		c += x
print(c)


N = int(input())
l1 = list(input())
l2 = list(input())
res = 0
for i in range(N):
	mi = min(int(l1[i]), int(l2[i]))
	ma = max(int(l1[i]), int(l2[i]))
	res += min(ma - mi, 10 + mi - ma)
print(res)


n = int(input())
s = input()
t = input()
ans = 0
for x in range(n):
	ans += min(abs(int(s[x]) - int(t[x])), 10 - abs(int(s[x]) - int(t[x])))
print(ans)


from sys import stdin
res = 0
in1 = 0
in2 = 0
in3 = 0
in4 = 0
disk1 = list('0123456789')
disk2 = list('5432109876')
n = int(input())
fs = list(str(input()))
se = list(str(input()))
for i in range(n):
	if fs[i] != se[i]:
		in1 = disk1.index(fs[i]) + 1
		in2 = disk1.index(se[i]) + 1
		in3 = disk2.index(fs[i]) + 1
		in4 = disk2.index(se[i]) + 1
		res += min(abs(in1 - in2), abs(in3 - in4))
print(res)


n = int(input())
result = sum((min(abs(x - y), 10 - abs(x - y)) for (x, y) in zip(map(int, input()), map(int, input()))))
print(result)


n = int(input())
o = input()
c = input()
i = 0
original = []
combination = []
while i < n:
	x = int(o[i])
	original.append(x)
	y = int(c[i])
	combination.append(y)
	i += 1
h = 0
for s in range(n):
	v = original[s] - combination[s]
	k = 10 - abs(v)
	if k < abs(v):
		h += k
	else:
		h += abs(v)
print(h)


cnt = 0
n = int(input())
a = int(input())
b = int(input())
while a != 0 or b != 0:
	a1 = a % 10
	b1 = b % 10
	x = abs(a1 - b1)
	if a1 > b1:
		y = 10 - a1 + b1
	elif b1 > a1:
		y = 10 - b1 + a1
	else:
		y = 10
	if x > y:
		cnt += y
	elif y > x:
		cnt += x
	else:
		cnt += x
	a = a // 10
	b = b // 10
print(cnt)


n = int(input())
start = input()
end = input()
count = 0
for i in range(n):
	a = start[i]
	b = end[i]
	if abs(int(a) - int(b)) > 10 - abs(int(a) - int(b)):
		count = count + (10 - abs(int(a) - int(b)))
	else:
		count = count + abs(int(a) - int(b))
print(count)


n = int(input())
s = input()
p = input()
k = 0
pas = 0
for i in range(n):
	if abs(int(s[i]) - int(p[i])) < 6:
		pas += abs(int(s[i]) - int(p[i]))
	else:
		k = 10 - abs(int(s[i]) - int(p[i]))
		pas += k
print(pas)


n = int(input())
initial = input()
final = input()
x = 0
for i in range(n):
	if abs(int(initial[i]) - int(final[i])) > 5:
		x = x + 10 - abs(int(initial[i]) - int(final[i]))
	else:
		x = x + abs(int(initial[i]) - int(final[i]))
print(x)


n = int(input())
cur = input()
passwd = input()
res = 0
for i in range(n):
	x = abs(int(cur[i]) - int(passwd[i]))
	res += x if x <= 5 else 10 - x
print(res)


n = int(input())
org = input()
com = input()
orglst = list(org)
comlst = list(com)
ans = 0
for i in range(n):
	sa = abs(int(orglst[i]) - int(comlst[i]))
	ans += min(sa, 10 - sa)
print(ans)


import math
n = int(input())
a = input()
b = input()
c = 0
D = 5
for i in range(0, n):
	x = math.fabs(int(a[i]) - int(b[i]))
	c += x if x <= D else 2 * D - x
print(int(c))


n = int(input())
fake = input()
actual = input()
count = 0
for (x, y) in zip(fake, actual):
	left = int(x) + 9 - int(y) + 1 if int(x) < int(y) else int(y) + 9 - int(x) + 1
	right = abs(int(x) - int(y))
	count += left if left < right else right
print(count)


n = int(input())
initial = input()
open_seq = input()
moves = 0
for i in range(n):
	init = int(initial[i])
	digit = int(open_seq[i])
	moves += min(abs(init - digit), 9 - max(init, digit) + min(init, digit) + 1)
print(moves)


T = int(input(''))
T1 = input('')
T2 = input('')
cont = 0

def mayor(a, b):
	if a > b:
		return (a, b)
	else:
		return (b, a)
for k in range(T):
	if T1[k] != T2[k]:
		(m, n) = mayor(int(T1[k]), int(T2[k]))
		mov = abs(10 - m + n)
		mov1 = abs(m - n)
		(c, d) = mayor(mov, mov1)
		cont += d
print(cont)


n = int(input())
a = input()
b = input()
cnt = 0
for i in range(n):
	first = abs(int(a[i]) - int(b[i]))
	d = min(int(a[i]), int(b[i]))
	e = max(int(a[i]), int(b[i]))
	second = abs(e - 10) + abs(d)
	c = min(first, second)
	cnt = cnt + c
print(cnt)


n = int(input())
o = input()
a = input()
s = 0
for i in range(n):
	s += min(abs(int(o[i]) - int(a[i])), 10 - abs(int(o[i]) - int(a[i])))
print(s)


n = input('')
a = input('')
b = input('')
i = 1
ans = 0
while i <= int(n):
	x = int(a) % 10
	y = int(b) % 10
	a = int(a) // 10
	b = int(b) // 10
	if abs(x - y) > 5:
		ans = ans + 10 - abs(x - y)
	else:
		ans = ans + abs(x - y)
	i = i + 1
print(str(ans) + '\n')


def turns(n, x, y):
	c = 0
	for i in range(n):
		a = abs(int(x[i]) - int(y[i]))
		if a > 5:
			a = 10 - a
		c += a
	return c
n = int(input())
x = input()
y = input()
print(turns(n, x, y))


n = int(input())
o = input()
p = input()
m = 0
for i in range(n):
	d = abs(int(o[i]) - int(p[i]))
	m += min(d, 10 - d)
print(m)


n = int(input())
a = list(str(input()))
b = list(str(input()))
answer = 0
for i in range(n):
	a[i] = int(a[i])
	b[i] = int(b[i])
	f = abs(a[i] - b[i])
	if a[i] < b[i]:
		r = 10 - b[i] + a[i]
	else:
		r = 10 - a[i] + b[i]
	answer += min(f, r)
print(answer)


n = int(input())
a = input()
b = input()
cost = 0
for i in range(n):
	x = abs(int(a[i]) - int(b[i]))
	cost += min(x, abs(9 - x) + 1)
print(cost)


n = int(input())
a = list(input())
b = list(input())
n1 = [int(i) for i in a]
n2 = [int(i) for i in b]

def best(a, b):
	if a > b:
		(a, b) = (b, a)
	return min(b - a, a + 10 - b)
r = 0
for i in range(n):
	r += best(n1[i], n2[i])
print(r)


n = int(input())
origin = input()
code = input()
move = 0
for i in range(n):
	d = abs(int(origin[i]) - int(code[i]))
	move += min(d, 10 - d)
print(move)


n = int(input())
a = input()
b = input()
counter = 0
for i in range(n):
	if int(a[i]) >= int(b[i]):
		c = min(int(a[i]) - int(b[i]), int(b[i]) + 10 - int(a[i]))
	else:
		c = min(int(b[i]) - int(a[i]), int(a[i]) + 10 - int(b[i]))
	counter += c
print(counter)


n = int(input())
available = input()
lock = input()
res = 0
for a in range(n):
	res = res + min(abs(int(available[a]) - int(lock[a])), abs(min(int(available[a]), int(lock[a])) + 10 - max(int(available[a]), int(lock[a]))))
print(res)


n = int(input())
(s1, s2) = (str(input()), str(input()))
s = 0
for i in range(n):
	x = abs(int(s1[i]) - int(s2[i]))
	s += min(x, 10 - x)
print(s)


input()
s = list(input())
s2 = list(input())
s = [int(x) for x in s]
s2 = [int(x) for x in s2]
count = 0
for i in range(len(s)):
	dif = abs(s[i] - s2[i])
	if dif >= 5:
		count += 10 - dif
	else:
		count += dif
print(count)


n = int(input())
(n1, n2) = (int(input()), int(input()))
c = 0
while n1 > 0 or n2 > 0:
	r1 = n1 % 10
	r2 = n2 % 10
	n1 = n1 // 10
	n2 = n2 // 10
	c += min(abs(r1 - r2), 9 - max(r1, r2) + min(r1, r2) + 1)
print(c)


input()
n1 = input()
n2 = input()
m = map(lambda a, b: abs(int(a) - int(b)), n1, n2)
s = sum(map(lambda x: x if x < 6 else 10 - x, m))
print(s)


def optimalMove(a, b):
	if a == b:
		return 0
	elif a > b:
		if a - b < 10 + b - a:
			return a - b
		else:
			return 10 + b - a
	elif b - a < 10 + a - b:
		return b - a
	else:
		return 10 + a - b
n = int(input())
initial = input()
final = input()
moves = 0
for i in range(n):
	moves += optimalMove(int(initial[i]), int(final[i]))
print(moves)


n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
res = 0
for i in range(n):
	mi = min(a[i], b[i])
	ma = max(a[i], b[i])
	s1 = ma - mi
	s2 = mi - ma + 10
	res += min(s1, s2)
print(res)


n = int(input())
s = input()
c = input()
count = 0
for i in range(n):
	a = int(s[i])
	b = int(c[i])
	d = abs(a - b)
	e = min(a, b)
	f = max(a, b)
	e = e + 10
	cnt = abs(f - e)
	count = count + min(cnt, d)
print(count)


n = int(input())
s_a = str(input())
s_b = str(input())
t = []
for (x, y) in zip(s_a, s_b):
	if abs(int(x) - int(y)) > 5:
		t.append(10 - abs(int(x) - int(y)))
	else:
		t.append(abs(int(x) - int(y)))
print(sum(t))


n = int(input())
m = list(input())
l = list(input())
N = 0
for i in range(n):
	if int(m[i]) > int(l[i]):
		N1 = int(m[i]) - int(l[i])
	else:
		N1 = int(l[i]) - int(m[i])
	if N1 < 5:
		N = N1 + N
	else:
		N = N + 10 - N1
print(N)


n = int(input())
s1 = input()
s2 = input()
sum = 0
for i in range(len(s1)):
	sum += min(abs(int(s2[i]) - int(s1[i])), abs(int(s2[i]) + 10 - int(s1[i])), abs(int(s1[i]) + 10 - int(s2[i])))
print(sum)


_ = int(input())
curr = map(int, input())
final = map(int, input())
diff = lambda x, y: min(abs(x - y), abs(10 - x) + y, abs(10 - y) + x)
print(sum((diff(x, y) for (x, y) in zip(curr, final))))


def func(n):
	k = list(map(int, input()))
	l = list(map(int, input()))
	counter = 0
	for i in range(n):
		counter += min(abs(k[i] - l[i]), 10 - abs(k[i] - l[i]))
	print(counter)
n = int(input())
func(n)


n = int(input())
s1 = input()
s2 = input()
summ = 0
for i in range(n):
	if abs(int(s1[i]) - int(s2[i])) <= 5:
		summ += abs(int(s1[i]) - int(s2[i]))
	else:
		summ += 10 - abs(int(s1[i]) - int(s2[i]))
print(summ)


input()
print(sum((min(abs(current - target), 10 - abs(current - target)) for (current, target) in ((int(a), int(b)) for (a, b) in zip(input(), input())))))


n = int(input())
first = input()
second = input()
count = 0
i = 0
while i < n:
	digit1 = int(first[i])
	digit2 = int(second[i])
	count += min(abs(digit2 - digit1), abs(digit2 + 10 - digit1), abs(digit1 + 10 - digit2))
	i += 1
print(count)


import math
n = input()
original_state = input()
target_state = input()
o_num = int(original_state)
t_num = int(target_state)
n = int(n)
res = 0
for i in range(n):
	g1 = o_num % 10
	g2 = t_num % 10
	step = min(abs(g1 - g2), min(g1, g2) + 10 - max(g1, g2))
	res += step
	o_num = o_num // 10
	t_num = t_num // 10
print(res)


def make_new_list(current_combination, final_combination):
	new_list = []
	for i in range(len(current_combination)):
		new_value = abs(current_combination[i] - final_combination[i])
		if new_value > 5:
			new_value = 10 - new_value
		new_list.append(new_value)
	return new_list

def find_sum_of_list(new_list):
	sum = 0
	for i in new_list:
		sum = sum + i
	return sum
number_of_locks = int(input())
current_combination = list(map(int, input()))
final_combination = list(map(int, input()))
new_list = make_new_list(current_combination, final_combination)
sum = find_sum_of_list(new_list)
print(sum)


n = int(input())
s = str(input())
t = str(input())
sum = 0
for i in range(0, n):
	sum += min(abs(int(t[i]) - int(s[i])), abs(10 + int(t[i]) - int(s[i])), abs(-10 + int(t[i]) - int(s[i])))
print(sum)


n = int(input())
s1 = input()
s2 = input()
total = 0
for i in range(len(s1)):
	if int(s1[i]) > int(s2[i]):
		total += min(int(s1[i]) - int(s2[i]), 10 - int(s1[i]) + int(s2[i]))
	else:
		total += min(int(s2[i]) - int(s1[i]), int(s1[i]) + 10 - int(s2[i]))
print(total)


def solve():
	n = int(input())
	s = [int(k) for k in input()]
	s2 = [int(k) for k in input()]
	ans = 0
	for i in range(n):
		ans += min(abs(s2[i] - s[i]), abs(10 + s2[i] - s[i]), abs(10 + s[i] - s2[i]))
	print(ans)
solve()


n = int(input())
origin = [int(k) for k in list(input())]
message = [int(k) for k in list(input())]
answer = 0
for i in range(n):
	clockwise = (message[i] - origin[i]) % 10
	unclockwise = (origin[i] - message[i]) % 10
	answer = answer + min(clockwise, unclockwise)
print(answer)


n = int(input())
now = list(map(int, input()))
ans = list(map(int, input()))
sum = 0
for i in range(len(now)):
	steps = abs(now[i] - ans[i])
	if steps > 5:
		steps = 10 - steps
	sum += steps
print(sum)


l = int(input())
start = input()
finish = input()
counter = 0
for i in range(l):
	if abs(int(start[i]) - int(finish[i])) < 6:
		counter += abs(int(start[i]) - int(finish[i]))
	else:
		counter += 10 - abs(int(start[i]) - int(finish[i]))
print(counter)


l = int(input())
o_l = input()
w_l = input()
s = 0
for i in range(l):
	s += min((10 + int(o_l[i]) - int(w_l[i])) % 10, (10 + int(w_l[i]) - int(o_l[i])) % 10)
print(s)


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	a = S()
	b = S()
	ans = 0
	for i in range(n):
		x = int(a[i])
		y = int(b[i])
		ans1 = abs(x - y)
		(x, y) = sorted([x, y])
		ans2 = x
		ans2 += 10 - y
		ans += min(ans1, ans2)
	return ans
print(main())


n = int(input())
vh = list(input())
vih = list(input())
kombovombo = 0
for i in range(len(vh)):
	if abs(int(vh[i]) - int(vih[i])) <= 5:
		kombovombo += abs(int(vh[i]) - int(vih[i]))
	elif abs(int(vh[i]) - int(vih[i])) > 5:
		if int(vh[i]) > 5:
			kombovombo += 10 - int(vh[i]) + int(vih[i])
		else:
			kombovombo += abs(10 - int(vih[i]) + int(vh[i]))
print(kombovombo)


n = int(input())
s = input()
s2 = input()
sum1 = 0
for i in range(len(s)):
	if abs(int(s[i]) - int(s2[i])) <= 5:
		sum1 += abs(int(s[i]) - int(s2[i]))
	else:
		sum1 += min(int(s[i]), int(s2[i])) + 10 - max(int(s[i]), int(s2[i]))
print(sum1)


def rtm(x, y):
	c1 = x - y
	if c1 < 0:
		c1 += 10
	c2 = y - x
	if c2 < 0:
		c2 += 10
	return min(c2, c1)
n = int(input())
a = input()
b = input()
cnt = 0
for i in range(n):
	cnt += rtm(int(a[i]), int(b[i]))
print(cnt)


n = int(input())
a = input()
b = input()
count = 0
for (i, j) in zip(a, b):
	diff = abs(int(j) - int(i))
	count += min(diff, 10 - diff)
print(count)


n = int(input())
s1 = input()
s2 = input()
k = 0
for i in range(n):
	d = abs(int(s1[i]) - int(s2[i]))
	k += min(d, 10 - d)
print(k)


n = int(input())
a = []
b = []
j = 0
sigma = 0
strinput = ''
strinput = input()
for j in range(n):
	x = int(strinput[j])
	a.append(x)
strinput = input()
for j in range(n):
	x = int(strinput[j])
	b.append(x)
for i in range(n):
	delta = abs(a[i] - b[i])
	delta = min(delta, 10 - delta)
	sigma += delta
print(sigma)


a = int(input())
b = input()
c = input()
tot = 0
for x in range(0, len(b)):
	if b[x] != c[x]:
		minn = min(int(b[x]), int(c[x]))
		maxx = max(int(b[x]), int(c[x]))
		tot += min(maxx - minn, minn + 10 - maxx)
print(tot)


n = int(input())
b = input()
c = input()
z = 0
for i in range(n):
	p = 0
	m = int(c[i]) - int(b[i])
	p = min(abs(m), 10 - abs(m))
	z += p
print(z)


n = int(input())
k1 = [int(i) for i in list(input())]
k2 = [int(j) for j in list(input())]
cnt = 0
(temp1, temp2, a) = (0, 0, 0)
for i in range(n):
	temp1 = abs(k1[i] - k2[i])
	temp2 = 10 - temp1
	a = min(temp1, temp2)
	cnt += a
print(cnt)


x = int(input())
y = int(input())
z = int(input())
c = 0
for i in range(0, x):
	n = y % 10
	y //= 10
	m = z % 10
	z //= 10
	mi = min(m, n)
	ma = max(n, m)
	c += min(ma - mi, mi + 10 - ma)
print(c)


n = int(input().strip())
t = input().strip()
s = input().strip()
l = 0
for i in range(n):
	l = l + min(abs(int(s[i]) - int(t[i])), abs(max(int(s[i]), int(t[i])) - 10 - min(int(s[i]), int(t[i]))))
print(l)


__author__ = 'emcenrue'
from math import floor
n = int(input())
s1 = list(map(int, input()))
s2 = list(map(int, input()))
ans = 0
for i in range(n):
	diff = abs(s1[i] - s2[i])
	ans += min(diff, 10 - diff)
print(ans)


n = int(input())
current = input()
code = input()
result = 0
for (initial, end) in zip(current, code):
	if int(initial) >= int(end):
		(initial, end) = (int(initial), int(end))
	else:
		(end, initial) = (int(initial), int(end))
	if abs(initial - end) >= abs(initial - (end + 10)):
		result += abs(initial - (end + 10))
	else:
		result += abs(initial - end)
print(result)


n = int(input())
a = str(input())
b = str(input())
ans = 0
for i in range(n):
	ans += min(max(int(a[i]), int(b[i])) - min(int(a[i]), int(b[i])), min(int(a[i]), int(b[i])) + 10 - max(int(a[i]), int(b[i])))
print(ans)


n = int(input())
x = int(input())
y = int(input())
s = 0
while n != 0:
	i = x % 10
	j = y % 10
	if j > i:
		(i, j) = (j, i)
	if i - j < j + 9 - i + 1:
		s = s + i - j
	else:
		s = s + j + 9 - i + 1
	x //= 10
	y //= 10
	n -= 1
print(s)


def func(n, a, b):
	c = 0
	for i in range(n):
		d = abs(int(a[i]) - int(b[i]))
		c += min(d, 10 - d)
	print(c)
n = int(input())
a = input()
b = input()
func(n, a, b)


__author__ = 'Utena'
n = int(input())
m = list(map(int, input()))
s = list(map(int, input()))
t = 0
for i in range(n):
	t += min(abs(m[i] - s[i]), 10 - abs(s[i] - m[i]))
print(t)


n = int(input())
org = input()
comb = input()
res = 0
for i in range(n):
	temp1 = int(org[i])
	temp2 = int(comb[i])
	temp3 = abs(temp1 - temp2)
	if temp3 > 5:
		res += 9 % abs(temp1 - temp2) + 1
	else:
		res += temp3
print(res)


def turn_around(origin, password):
	temp = 0
	count1 = 0
	a = origin
	while a != password:
		a -= 1
		if a == -1:
			a = 9
		count1 += 1
	temp = count1
	count1 = 0
	a = origin
	while a != password:
		a += 1
		if a == 10:
			a = 0
		count1 += 1
	if count1 < temp:
		return count1
	return temp
n = int(input())
origin = input()
password = input()
total = 0
for i in range(n):
	total += turn_around(int(origin[i]), int(password[i]))
print(total)


n = int(input())
A = list(input())
B = list(input())
cnt = 0
for i in range(n):
	if abs(int(A[i]) - int(B[i])) <= 5:
		cnt = cnt + abs(int(A[i]) - int(B[i]))
	else:
		a = max(int(A[i]), int(B[i]))
		b = 10 - a + min(int(A[i]), int(B[i]))
		cnt = cnt + b
print(cnt)


def main():
	lon = int(input())
	first = input()
	second = input()
	acc = 0
	for index in range(lon):
		firstdigit = int(first[index])
		seconddigit = int(second[index])
		needed = min(((firstdigit - seconddigit) % 10, (seconddigit - firstdigit) % 10))
		acc += needed
	print(acc)
main()


n = int(input())
s1 = input()
s2 = input()
c = 0
for i in range(n):
	(x, y) = (min(int(s1[i]), int(s2[i])), max(int(s1[i]), int(s2[i])))
	d1 = abs(x - y)
	d2 = abs(x - y + 10)
	d3 = abs(x - y - 10)
	c += min(d1, d2, d3)
print(c)


from sys import stdin, exit
import math
n = int(stdin.readline())
s = stdin.readline().rstrip()
t = stdin.readline().rstrip()
c = 0
for i in range(len(s)):
	sd = int(s[i])
	td = int(t[i])
	f_moves = 0
	cur = sd
	while cur != td:
		cur += 1
		cur %= 10
		f_moves += 1
	b_moves = 0
	cur = sd
	while cur != td:
		cur -= 1
		if cur == -1:
			cur = 9
		b_moves += 1
	c += min(f_moves, b_moves)
print(c)


def solve(disks, original_state, code):
	moves = 0
	for i in range(disks):
		if abs(original_state[i] - code[i]) > 5:
			moves += 10 - abs(original_state[i] - code[i])
		else:
			moves += abs(original_state[i] - code[i])
	return moves
n = int(input())
o = list(map(int, input()))
c = list(map(int, input()))
print(solve(n, o, c))


import math
n = int(input())
x = input()
y = input()
s = 0
for i in range(n):
	z = abs(int(x[i]) - int(y[i]))
	if z < 10 - z:
		s = s + z
	else:
		s = s + (10 - z)
print(s)


import sys
n = int(input())
start = str(input())
end = str(input())
answer = 0
for index in range(n):
	number_start = int(start[index])
	number_end = int(end[index])
	diff_1 = number_start - number_end
	if diff_1 < 0:
		diff_1 = -diff_1
	if number_start < number_end:
		diff_2 = 10 + number_start - number_end
	else:
		diff_2 = 10 + number_end - number_start
	if diff_2 < 0:
		diff_2 = -diff_2
	if diff_1 <= diff_2:
		answer += diff_1
	else:
		answer += diff_2
print(answer)


n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
s = 0
for i in range(n):
	if a[i] > b[i]:
		if a[i] - b[i] > 5:
			s += b[i] + 10 - a[i]
		else:
			s += a[i] - b[i]
	elif b[i] > a[i]:
		if b[i] - a[i] > 5:
			s += a[i] + 10 - b[i]
		else:
			s += b[i] - a[i]
print(s)


n = int(input())
s1 = input()
s2 = input()
count = 0
for i in range(len(s1)):
	if abs(int(s1[i]) - int(s2[i])) == 1:
		count += abs(int(s1[i]) - int(s2[i]))
	if abs(int(s1[i]) - int(s2[i])) == 2:
		count += abs(int(s1[i]) - int(s2[i]))
	if abs(int(s1[i]) - int(s2[i])) == 3:
		count += abs(int(s1[i]) - int(s2[i]))
	if abs(int(s1[i]) - int(s2[i])) == 4:
		count += abs(int(s1[i]) - int(s2[i]))
	if abs(int(s1[i]) - int(s2[i])) == 5:
		count += abs(int(s1[i]) - int(s2[i]))
	if abs(int(s1[i]) - int(s2[i])) == 6:
		count += abs(int(s1[i]) - int(s2[i])) - 2
	if abs(int(s1[i]) - int(s2[i])) == 7:
		count += abs(int(s1[i]) - int(s2[i])) - 4
	if abs(int(s1[i]) - int(s2[i])) == 8:
		count += abs(int(s1[i]) - int(s2[i])) - 6
	if abs(int(s1[i]) - int(s2[i])) == 9:
		count += abs(int(s1[i]) - int(s2[i])) - 8
print(count)


a = int(input())
b = str(input()[:a])
c = str(input()[:a])
count = 0
for i in range(a):
	if b[i] != c[i]:
		b1 = int(b[i]) - int(c[i])
		b1 = abs(b1)
		if b1 == 9:
			b1 = 1
		elif b1 == 8:
			b1 = 2
		elif b1 == 7:
			b1 = 3
		elif b1 == 6:
			b1 = 4
		count += b1
print(count)


n = int(input())
a = input()
b = input()
c = 0
for i in range(n):
	x = int(a[i])
	y = int(b[i])
	d = max(x, y) - min(x, y)
	c += min(d, 10 - d)
print(c)


n = input()
start = input()
need = input()
count = 0
for i in range(len(start)):
	(x, y) = (int(start[i]), int(need[i]))
	if abs(y - x) < 10 - abs(y - x):
		count += abs(y - x)
	else:
		count += 10 - abs(y - x)
print(count)


n = int(input())
l1 = input()
l2 = input()
z = 0
for i in range(n):
	r = []
	r.append(abs(int(l1[i]) - int(l2[i])))
	r.append(abs(10 + int(l1[i]) - int(l2[i])))
	r.append(abs(int(l1[i]) - (10 + int(l2[i]))))
	z += min(r)
print(z)


n = int(input())
count = 0
ps = input()
cs = input()
for i in range(n):
	t = abs(int(cs[i]) - int(ps[i]))
	count += min(t, 10 - t)
print(count)


a = int(input())
b = input()
c = input()
count = 0
for i in range(0, a):
	temp = int(b[i])
	temp1 = int(c[i])
	if temp - temp1 < -5 or temp - temp1 > 5:
		count += 10 - abs(temp - temp1)
	else:
		count += abs(temp - temp1)
print(count)


d = int(input())
f = str(input())
s = str(input())
sum = 0
for i in range(0, len(s)):
	x = int(f[i])
	y = int(s[i])
	sum += min(abs(x - y), abs(x + 10 - y), abs(y + 10 - x))
print(sum)


n = int(input())
original = input()
desired = input()
moves = 0

def min_moves(o, d):
	return min(abs(o - d), abs(o + 10 - d), abs(d + 10 - o))
for i in range(n):
	moves += min_moves(int(original[i]), int(desired[i]))
print(moves)


n = int(input())
n1 = input()
n2 = input()
set = 0
for i in range(n):
	if abs(int(n1[i]) - int(n2[i])) < 5:
		set += abs(int(n1[i]) - int(n2[i]))
	elif abs(int(n1[i]) - int(n2[i])) == 5:
		set += 5
	elif abs(int(n1[i]) - int(n2[i])) == 6:
		set += 4
	elif abs(int(n1[i]) - int(n2[i])) == 7:
		set += 3
	elif abs(int(n1[i]) - int(n2[i])) == 8:
		set += 2
	elif abs(int(n1[i]) - int(n2[i])) == 9:
		set += 1
print(set)


n = int(input())
s = input()
d = input()
k = 0
for i in range(n):
	k += min(abs(int(s[i]) - int(d[i])), 10 - abs(int(s[i]) - int(d[i])))
print(k)


def diff(x, y):
	a = int(x)
	b = int(y)
	return min(abs(b + 10 - a), abs(a - b), abs(a - b + 10))

def main():
	n = int(input())
	_from = input()
	_to = input()
	total = 0
	for i in range(n):
		total += diff(_from[i], _to[i])
	print(total)
main()


n = int(input())
z = input().rjust(n)
x = input().rjust(n)
r = 0
for i in range(n):
	if int(z[i]) != int(x[i]):
		r = r + min(max(int(z[i]), int(x[i])) - min(int(z[i]), int(x[i])), 10 - max(int(z[i]), int(x[i])) + min(int(z[i]), int(x[i])))
print(r)


n = input('')
a = input('')
s = input('')
a = list(a)
s = list(s)
i = 0
sum = 0
for x in a:
	x = int(x)
	z = int(s[i])
	y = min(x, z)
	x = max(x, z)
	if x - y < 9 - x + (y + 1):
		sum += x - y
	else:
		sum += 9 - x + (y + 1)
	i += 1
print(sum)


def distance(a, b):
	return min(abs(b - a), 10 - abs(b - a))
n = int(input())
a = input()
b = input()
s = 0
for i in range(n):
	s += distance(int(a[i]), int(b[i]))
print(s)


from math import fabs
j = int(input())
a = input()
b = input()
c = 0
for i in range(j):
	d = (int(a[i]) - int(b[i])) % 10
	c += min(d, 10 - d)
print(c)


import math
n = int(input())
a = input()
b = input()
summ = 0
k = 0
for i in range(0, n):
	if int(a[i]) > int(b[i]):
		k = int(a[i]) - int(b[i])
	else:
		k = -(int(a[i]) - int(b[i]))
	if k >= 6:
		k = 10 - k
	summ += k
print(summ)


n = int(input())
s1 = input()
s2 = input()
c = 0
for i in range(len(s1)):
	I = int(s1[i])
	J = int(s2[i])
	if max(I, J) - min(I, J) > 5:
		c += 10 - (max(I, J) - min(I, J))
	else:
		c += max(I, J) - min(I, J)
print(c)


x = int(input())
a = input()
b = input()
s = 0
for i in range(x):
	c = abs(int(a[i]) - int(b[i]))
	s += min(c, 10 - c)
print(s)


n = int(input())
s = [int(x) for x in input()]
l = [int(x) for x in input()]
length = []
for i in range(n):
	m = abs(s[i] - l[i])
	length.append(min(m, 10 - m))
print(sum(length))


import math
n = eval(input())
a = input()
b = input()
sum = 0
for i in range(n):
	temp = abs(eval(a[i]) - eval(b[i]))
	if temp > 4:
		sum += 10 - temp
	else:
		sum += temp
print(sum)


import math
n = int(input())
a = input()
b = input()
ans = 0
for i in range(0, len(a)):
	dif = abs(ord(a[i]) - ord(b[i]))
	if 10 - dif < dif:
		dif = 10 - dif
	ans += dif
print(ans)


n = int(input(''))
x = input('')
y = input('')
d = 0
for i in range(0, n):
	m = int(x[i])
	p = int(y[i])
	if m != p:
		if m > p:
			if 10 + p - m > abs(p - m):
				d = d + abs(p - m)
			else:
				d = d + 10 + p - m
		elif 10 + m - p > abs(m - p):
			d = d + abs(m - p)
		else:
			d = d + 10 + m - p
print(d)


n = int(input())
x = input()
y = input()
count = 0
for i in range(0, n):
	a = int(x[i])
	b = int(y[i])
	z = min(a, b) + 10
	count += min(abs(a - b), z - max(a, b))
print(count)


n = input()
m = list(input())
m = [int(i) for i in m]
z = list(input())
z = [int(g) for g in z]
c = 0
for r in range(int(n)):
	if abs(m[r] - z[r]) > 5:
		c += abs(10 - abs(m[r] - z[r]))
	else:
		c += abs(m[r] - z[r])
print(c)


n = int(input())
n1 = list(input())
n2 = list(input())
c = 0
for i in range(len(n1)):
	if abs(int(n1[i]) - int(n2[i])) <= 5:
		c = c + abs(int(n1[i]) - int(n2[i]))
	else:
		x = min(int(n1[i]), int(n2[i]))
		y = max(int(n1[i]), int(n2[i]))
		x = x + 10
		c = c + abs(y - x)
print(c)


n = int(input())
s1 = input()
s2 = input()
s = '0123456789'
count = 0
for i in range(n):
	a = int(s1[i])
	b = int(s2[i])
	x = abs(a - b)
	y = abs(10 - a + b)
	z = abs(a + 10 - b)
	count += min(x, y, z)
print(count)


length = int(input())
now = input()
secret = input()
total = 0
for i in range(0, length):
	a = int(now[i])
	b = int(secret[i])
	diff = abs(a - b)
	if diff > 5:
		diff = 10 - diff
	total += diff
print(total)


def code_step(code1, code2, n):
	steps = 0
	for pos in range(n):
		num1 = int(code1[pos])
		num2 = int(code2[pos])
		first = abs(min(num1, num2) + 10 - max(num1, num2))
		second = abs(num1 - num2)
		steps += min(first, second)
	print(steps)

def main():
	n = int(input())
	code1 = input()
	code2 = input()
	code_step(code1, code2, n)
main()


numdiscos = int(input())
numorigen = input()
numclave = input()
movimientos = 0
for i in range(numdiscos):
	num_o = int(numorigen[i])
	num_c = int(numclave[i])
	resta = abs(num_o - num_c)
	if resta > 5:
		resta = 10 - abs(num_c - num_o)
	movimientos = movimientos + resta
print(movimientos)


input()
m = lambda : map(int, input())
print(sum((min(abs(x - y), 10 - abs(x - y)) for (x, y) in zip(m(), m()))))


n = int(input())
(a, b, l) = (input(), input(), 0)
a = list(map(int, a))
b = list(map(int, b))
for i in range(n):
	if b[i] >= a[i]:
		if b[i] - a[i] <= 5:
			l += b[i] - a[i]
		if b[i] - a[i] > 5:
			l += 9 - b[i] + a[i] + 1
	if a[i] >= b[i]:
		if a[i] - b[i] <= 5:
			l += a[i] - b[i]
		if a[i] - b[i] > 5:
			l += 9 - a[i] + b[i] + 1
print(l)


nr_of_disks = input()
original = input()
opening_combination = input()
moves = 0
for disk in range(len(original)):
	if original[disk] != opening_combination[disk]:
		if abs(int(original[disk]) - int(opening_combination[disk])) <= 5:
			moves = moves + abs(int(original[disk]) - int(opening_combination[disk]))
		elif int(original[disk]) - int(opening_combination[disk]) + 10 <= 5:
			moves = moves + int(original[disk]) - int(opening_combination[disk]) + 10
		elif int(opening_combination[disk]) - int(original[disk]) + 10 <= 5:
			moves = moves + int(opening_combination[disk]) - int(original[disk]) + 10
print(moves)


n = int(input())
state = list(map(int, list(input())))
correct = list(map(int, list(input())))
count = 0

def countMove(start, end):
	if start == end:
		return 0
	if start > end:
		return start - end
	else:
		return start + (9 - end) + 1
for i in range(0, n):
	count += min(countMove(correct[i], state[i]), countMove(state[i], correct[i]))
print(count)


n = int(input())
current_state = [int(x) for x in list(input())]
open_state = [int(x) for x in list(input())]
c = 0
for i in range(n):
	c += min([9 - current_state[i] + 1 + open_state[i], abs(current_state[i] - open_state[i]), current_state[i] + 1 + 9 - open_state[i]])
print(c)


from math import *
n = int(input())
s = input()
b = input()
cntr = 0
for i in range(n):
	cntr += min(abs(int(s[i]) - int(b[i])), 10 - abs(int(s[i]) - int(b[i])))
print(cntr)


banyak = input()
numb1 = input()
numb2 = input()
total = 0
index = 0
for i in numb1:
	total += min(10 - abs(int(i) - int(numb2[index])), abs(int(i) - int(numb2[index])))
	index += 1
print(total)


n = int(input())
s = input()
t = input()
ans = 0
for i in range(n):
	a = int(s[i])
	b = int(t[i])
	if a >= b:
		ans += min(a - b, 10 + b - a)
	else:
		ans += min(b - a, 10 + a - b)
print(ans)


n = int(input())
a = input()
b = input()
p1 = 0
p2 = 0
p3 = 0
result = 0
an = [int(k) for k in a]
bn = [int(m) for m in b]
for index in range(n):
	p1 = abs(an[index] - bn[index])
	p2 = abs(an[index] - bn[index] + 10)
	p3 = abs(an[index] - bn[index] - 10)
	c = min(p1, p2)
	d = min(c, p3)
	result += d
print(result)


n = int(input())
arr = list(input())
brr = list(input())
total = 0
for i in range(n):
	total += min(10 - abs(int(arr[i]) - int(brr[i])), abs(int(arr[i]) - int(brr[i])))
print(total)


import math

def diff(current, answer):
	first = abs(int(current) - int(answer))
	second = 10 - first
	return min(first, second)
passlen = int(input())
current = input()
answer = input()
steps = 0
for n in range(passlen):
	if current[n] != answer[n]:
		steps = steps + diff(current[n], answer[n])
print(steps)


from __future__ import division, print_function
from collections import *
from math import *
from itertools import *
from time import time
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	n = int(input())
	original = input()
	password = input()
	order = '0123456789012345'
	count = 0
	for i in range(n):
		num1 = original[i]
		num2 = password[i]
		dummy = abs(order.find(num1) - order.find(num2))
		dummy2 = abs(order.rindex(num1) - order.rindex(num2))
		count += min(dummy, dummy2)
	print(count)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


input()
source = list(map(int, list(input())))
dest = list(map(int, list(input())))
moves = 0
for i in range(len(source)):
	moves += min(abs(10 + min(dest[i], source[i]) - max(dest[i], source[i])), abs(dest[i] - source[i]))
print(moves)


n = int(input())
A = input()
B = input()
Ans = 0
for (a, b) in zip(A, B):
	a = int(a)
	b = int(b)
	Diff = abs(a - b)
	if Diff > 5:
		Ans += 10 - Diff
	else:
		Ans += Diff
print(Ans)


n = int(input())
s1 = input()
s2 = input()
l1 = []
l2 = []
l3 = []
l4 = []
l5 = []
l6 = []
for i in range(0, n):
	l1.append(int(s1[i]))
	l2.append(int(s2[i]))
for i in range(0, n):
	l3.append(abs(l1[i] - l2[i]))
	l4.append(9 - l1[i] + l2[i] + 1)
	l5.append(9 - l2[i] + l1[i] + 1)
	l6.append(min(abs(l1[i] - l2[i]), 9 - l1[i] + l2[i] + 1, 9 - l2[i] + l1[i] + 1))
print(min(sum(l3), sum(l4), sum(l5), sum(l6)))


n = int(input())
state = list(map(int, input()))
need_state = list(map(int, input()))
summary = 0
for i in range(len(state)):
	if abs(state[i] - need_state[i]) > 5:
		summary += 10 - abs(state[i] - need_state[i])
	else:
		summary += abs(state[i] - need_state[i])
print(summary)


n = int(input())
state = input()
pwd = input()
cnt = 0
for i in range(0, n):
	s = int(state[i])
	p = int(pwd[i])
	if s > p:
		if s - p > 9 - s + p:
			cnt = cnt + 9 - s + p + 1
		else:
			cnt = cnt + s - p
	elif s < p:
		if p - s > 9 - p + s:
			cnt = cnt + 9 - p + s + 1
		else:
			cnt = cnt + p - s
print(cnt)


n = int(input())
a = input()
b = input()
p = 0
for i in range(n):
	s = int(a[i])
	h = int(b[i])
	p += min(abs(s - h) % 10, abs(10 - abs(s - h)) % 10)
print(p)


n = int(input())
org = input()
key = input()
coN = 0
for i in range(n):
	t = int(org[i])
	p = int(key[i])
	l = max(t, p)
	k = min(t, p)
	coN += min(abs(t - p), 10 - l + k)
print(coN)


def no_of_steps(start, end, n):
	res = 0
	for i in range(n):
		st = int(start[i])
		en = int(end[i])
		res += min((st - en) % 10, (en - st) % 10)
	return res
n = int(input())
start = input()
end = input()
print(no_of_steps(start, end, n))


def MinTrack(Objetivo, Originial):
	(a, b) = (Objetivo, Originial)
	if Objetivo > Originial:
		a = Originial
		b = Objetivo
	rutaIzq = a + 9 - b + 1
	rutaDer = b - a
	return min(rutaIzq, rutaDer)
n = int(input())
cadenaOriginal = input()
cadenaObjetivo = input()
respuesta = 0
for i in range(n):
	respuesta += MinTrack(int(cadenaObjetivo[i]), int(cadenaOriginal[i]))
print(respuesta)


x = int(input())
y = input()
z = input()
summy = 0
k1 = 0
k2 = 0
for i in range(len(y)):
	k1 = abs(int(y[i]) - int(z[i]))
	if int(y[i]) < int(z[i]):
		k2 = int(y[i]) + 10 - int(z[i])
	else:
		k2 = int(z[i]) + 10 - int(y[i])
	if k1 > k2:
		summy = summy + k2
	else:
		summy = summy + k1
print(summy)


n = input()
curpass = input()
outpass = input()

def f(a, b):
	if abs(a - b) > 5:
		return 10 - abs(a - b)
	elif abs(a - b) < 5:
		return abs(a - b)
	else:
		return 5
mov = 0
i = 0
while i < int(n):
	mov += f(int(curpass[i]), int(outpass[i]))
	i += 1
print(mov)


a = int(input())
l = list(map(int, input()))
k = list(map(int, input()))
sum = 0
for i in range(0, a):
	p = min(abs(l[i] - k[i]), 10 - abs(l[i] - k[i]))
	sum += p
print(sum)


n = int(input())
s1 = input()
s2 = input()
k = 0
for i in range(0, n):
	c1 = int(s1[i])
	c2 = int(s2[i])
	dc = abs(c1 - c2)
	if dc > 5:
		k += 10 - dc
	else:
		k += dc
print(k)


lenn = int(input())
start = list(input())
end = list(input())
moves = 0
for i in range(lenn):
	s = int(start[i])
	e = int(end[i])
	dif = abs(s - e)
	if dif > 5:
		moves += 10 - dif
	else:
		moves += dif
print(moves)


n = int(input())
d = list(input())
d1 = list(map(int, d))
d2 = list(input())
d2 = list(map(int, d2))
c = 0
for i in range(n):
	while d1[i] != d2[i]:
		while d1[i] > d2[i]:
			if d1[i] - d2[i] > 5:
				while d1[i] < 10:
					d1[i] += 1
					c += 1
				if d1[i] == 10:
					d1[i] = 0
					while d1[i] != d2[i]:
						d1[i] += 1
						c += 1
			else:
				while d1[i] != d2[i]:
					d1[i] -= 1
					c += 1
		while d1[i] < d2[i]:
			if d2[i] - d1[i] > 5:
				while d1[i] > -1:
					d1[i] -= 1
					c += 1
				if d1[i] == -1:
					d1[i] = 9
					while d1[i] != d2[i]:
						d1[i] -= 1
						c += 1
			else:
				while d1[i] != d2[i]:
					d1[i] += 1
					c += 1
print(c)


n = int(input())
original = input()
correct = input()
s = 0
for i in range(n):
	x = abs(int(original[i]) - int(correct[i]))
	if x > 5:
		x = 10 - x
	s += x
print(s)


d = int(input())
inicial = input()
final = input()
s = 0
for i in range(d):
	n1 = int(inicial[i])
	n2 = int(final[i])
	if abs(n1 - n2) < 5:
		nr = abs(n1 - n2)
	else:
		nr = 10 - abs(n1 - n2)
	s = s + nr
print(s)


n = int(input())
orignal = list(map(int, input()))
code = list(map(int, input()))
x = 0
move = 0
for i in range(n):
	if abs(orignal[i] - code[i]) > 5:
		w = 9 - abs(orignal[i] - code[i]) + 1
		move += w
	else:
		move += abs(orignal[i] - code[i])
print(move)


n = int(input())
cur = input()
cor = input()
c = 0
for i in range(n):
	diff = abs(int(cur[i]) - int(cor[i]))
	c += min(diff, 10 - diff)
print(c)


n = int(input())
s1 = input()
s2 = input()
total = 0
for i in range(len(s1)):
	n1 = int(s1[i])
	n2 = int(s2[i])
	if n1 == n2:
		pass
	elif n1 < n2:
		total += min(n2 - n1, n1 + 10 - n2)
	elif n1 > n2:
		total += min(n1 - n2, n2 + 10 - n1)
print(total)


n = int(input())
start = input()
code = input()
opers = 0
for k in range(n):
	opers += min(abs(int(code[k]) - int(start[k])), min(10 - int(start[k]) + int(code[k]), 10 - int(code[k]) + int(start[k])))
print(opers)


n = int(input())
ls1 = list(map(int, list(input())))
ls2 = list(map(int, list(input())))
cnt = 0
for i in range(n):
	cnt += min((ls1[i] - ls2[i]) % 10, (ls2[i] - ls1[i]) % 10)
print(cnt)


inp = int(input())
inp1 = input()
inp2 = input()
counter = 0
for x in range(inp):
	if inp1[x] > inp2[x]:
		up = 10 - int(inp1[x]) + int(inp2[x])
		down = abs(int(inp1[x]) - int(inp2[x]))
		if up < down:
			counter += up
		else:
			counter += down
	else:
		up = 10 - int(inp2[x]) + int(inp1[x])
		down = abs(int(inp1[x]) - int(inp2[x]))
		if up < down:
			counter += up
		else:
			counter += down
print(counter)


x = int(input())
y = list(input())
z = list(input())
sum = 0
for i in range(len(y)):
	sum += min(abs(int(y[i]) - int(z[i])), 10 - abs(int(y[i]) - int(z[i])))
print(sum)


n = int(input())
num1 = int(input())
num2 = int(input())
count = 0
for i in range(n):
	n1 = num1 % 10
	n2 = num2 % 10
	num1 = num1 // 10
	num2 = num2 // 10
	if abs(n1 - n2) > 5:
		count += 10 - abs(n1 - n2)
	else:
		count += abs(n1 - n2)
print(count)


def f(p):
	(a, b) = (min(p), max(p))
	return min(b - a, 10 - b + a)
_ = int(input())
a = map(int, list(input()))
b = map(int, list(input()))
print(sum(map(f, zip(a, b))))


n = input()
o = input()
p = input()
ans = 0
for (i, j) in zip(o, p):
	if abs(int(i) % 10 - int(j) % 10) > 10 - abs(int(i) % 10 - int(j) % 10):
		ans += 10 - abs(int(i) % 10 - int(j) % 10)
	else:
		ans += abs(int(i) % 10 - int(j) % 10)
print(ans)


n = int(input())
a = input()
b = input()
count = 0
for i in range(n):
	m = abs(int(a[i]) - int(b[i]))
	if m == 5:
		count += 5
	elif m < 5:
		count += m
	elif m > 5:
		count += 10 - m
print(count)


n = int(input())
s1 = input()
s2 = input()
lst1 = []
lst2 = []
s = 0
for i in range(n):
	lst1.append(int(s1[i]))
	lst2.append(int(s2[i]))
for i in range(n):
	if lst1[i] > lst2[i] and lst1[i] - lst2[i] <= 5:
		s = s + (lst1[i] - lst2[i])
	elif lst1[i] > lst2[i] and lst1[i] - lst2[i] > 5:
		s = s + (10 - lst1[i]) + lst2[i]
	elif lst1[i] < lst2[i] and lst2[i] - lst1[i] <= 5:
		s = s + (lst2[i] - lst1[i])
	elif lst2[i] > lst1[i] and lst2[i] - lst1[i] > 5:
		s = s + (10 - lst2[i]) + lst1[i]
print(s)


n = int(input())
p = input()
q = input()
c = 0
for i in range(n):
	a = abs(int(p[i]) - int(q[i]))
	if a <= 5:
		c = c + a
	else:
		c = c + 10 - a
print(c)


rings = int(input())
original_state = [int(x) for x in input()]
key = [int(x) for x in input()]
result = 0
for i in range(rings):
	tmp = abs(original_state[i] - key[i])
	if tmp <= 5:
		result += tmp
	else:
		result += 5 - (tmp - 5)
print(result)


n = int(input())
a1 = int(input())
a2 = int(input())
s = 0
for i in range(0, n):
	k1 = a1 % 10
	k2 = a2 % 10
	a1 = a1 // 10
	a2 = a2 // 10
	k = k1 - k2
	if k < 0:
		k = k * -1
	if k > 5:
		k = 10 - k
	s = s + k
print(s)


n = int(input())
s = input()
k = input()
cnt = 0
for i in range(n):
	cnt += min(abs(int(s[i]) - int(k[i])), abs(9 - int(k[i])) + int(s[i]) + 1, abs(9 - int(s[i])) + int(k[i]) + 1)
print(cnt)


n = int(input())
a = input()
b = input()
x = 0
res = 0
for i in range(n):
	c = int(a[i])
	d = int(b[i])
	if abs(c - d) > 5:
		if c < d:
			while c != 0:
				c -= 1
				x += 1
			res += x + (10 - d)
			x = 0
		elif c > d:
			while c != 9:
				c += 1
				x += 1
			res += x + d + 1
			x = 0
	else:
		while c != d:
			if c > d:
				c -= 1
				x += 1
			else:
				c += 1
				x += 1
		res += x
		x = 0
print(res)


input()
t = 0
s = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
x = list(map(int, input()))
y = list(map(int, input()))
for i in range(len(x)):
	if abs(x[i] - y[i]) > 5:
		t = t + (9 - max(x[i], y[i])) + (s.index(min(x[i], y[i])) + 1)
	else:
		t = t + abs(x[i] - y[i])
print(t)


from itertools import starmap

def intirize(nl):
	return list(map(lambda x: int(x), list(nl)))

def solution():
	n = input()
	init_state = intirize(input())
	key = intirize(input())
	fun = lambda x, y: min(abs(x - y), -abs(x - y) % 10)
	return sum(starmap(fun, zip(init_state, key)))
print(solution())


n = int(input())
state = list(map(int, input()))
code = list(map(int, input()))
moves = 0
for i in range(n):
	if state[i] == 0:
		state[i] = 10
	if code[i] == 0:
		code[i] = 10
for i in range(n):
	if abs(state[i] - code[i]) <= 5:
		moves += abs(state[i] - code[i])
	elif state[i] < 5:
		moves += state[i] + (10 - code[i])
	elif state[i] > 5:
		moves += 10 - state[i] + code[i]
print(moves)


n = int(input())
x = list(input())
y = list(input())
for i in range(n):
	x[i] = int(x[i])
	y[i] = int(y[i])
t = 0
for i in range(n):
	t = t + min((y[i] - x[i] + 10) % 10, (x[i] - y[i] + 10) % 10)
print(t)


t = int(input())
n = input()
m = input()
l = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
(i, j, count) = (0, 0, 0)
while i < t:
	index1 = l.index(n[i])
	index2 = l.index(m[i])
	if abs(index1 - index2) <= 5:
		count += abs(index1 - index2)
	else:
		count += 10 - abs(index1 - index2)
	i += 1
print(count)


n = int(input())
l = input()
m = input()
c = 0
for i in range(n):
	s = int(l[i]) - int(m[i])
	if s < 0:
		s = -s
	if s > 5:
		x = 9 - s + 1
		c = c + x
	else:
		c = c + s
print(c)


n = int(input())
a = input()
b = input()
my_list1 = []
my_list2 = []
count = 0
for i in a:
	my_list1.append(int(i))
for v in b:
	my_list2.append(int(v))
for k in range(n):
	new_list = []
	if my_list1[k] - my_list2[k] < 0:
		new_list.append(-1 * (my_list1[k] - my_list2[k]))
	else:
		new_list.append(my_list1[k] - my_list2[k])
	if my_list1[k] < my_list2[k]:
		new_list.append(10 + my_list1[k] - my_list2[k])
	else:
		new_list.append(10 + my_list2[k] - my_list1[k])
	count += min(new_list)
print(count)


x = int(input())
c = 0
y = input()
z = input()
for i in range(x):
	if abs(int(y[i]) - int(z[i])) < 10 - abs(int(y[i]) - int(z[i])):
		c = c + abs(int(y[i]) - int(z[i]))
	else:
		c = c + (10 - abs(int(y[i]) - int(z[i])))
print(c)


x = int(input())
a = list(map(int, str(input())))
b = list(map(int, str(input())))
count = 0
for i in range(x):
	count += min(10 - abs(a[i] - b[i]), abs(a[i] - b[i]))
print(count)


n = int(input())
s = input()
s1 = input()
sum1 = 0
for i in range(n):
	a = abs(int(s1[i]) - int(s[i]))
	if a > 5:
		a = 10 - a
	sum1 += a
print(sum1)


n = int(input())
s = list(map(int, input()))
s1 = list(map(int, input()))
a = 0
for i in range(n):
	a += min(abs(s[i] - s1[i]), 10 - abs(s[i] - s1[i]))
print(a)


n = int(input())
a = input()
b = input()
s = 0
for i in range(n):
	num = abs(int(a[i]) - int(b[i]))
	s += min(num, 10 - num)
print(str(s))


n = int(input())
a = int(input())
b = int(input())
sum = 0
while n:
	n -= 1
	x = a % 10
	y = b % 10
	z = abs(x - y)
	if z > 5:
		maxi = max(x, y)
		mini = min(x, y)
		sum += 10 - maxi + mini
	else:
		sum += z
	a //= 10
	b //= 10
print(sum)


n = int(input())
str1 = str(input())
str2 = str(input())
a = [int(i) for i in str1]
b = [int(k) for k in str2]
sum = 0
for i in range(n):
	if abs(a[i] - b[i]) <= 5:
		sum += abs(a[i] - b[i])
	else:
		sum += 10 - abs(a[i] - b[i])
print(sum)


import sys
cases = int(sys.stdin.readline().strip())
a = sys.stdin.readline().strip()
b = sys.stdin.readline().strip()
counter = 0
for i in range(len(a)):
	curA = int(a[i])
	curB = int(b[i])
	counter += min(abs(curA - curB), 10 - abs(curA - curB))
print(counter)


x = int(input())
q = list(input())
z = list(input())
s = 0
for v in range(x):
	b = abs(int(q[v]) - int(z[v]))
	c = 1 + int(z[v]) + abs(9 - int(q[v]))
	d = 1 + int(q[v]) + abs(9 - int(z[v]))
	g = [b, c, d]
	g.sort()
	s += int(g[0])
print(s)


number_of_disks = int(input())
state = [int(x) for x in input().strip()]
combination = [int(x) for x in input().strip()]
buffer_list = [abs(a - b) for (a, b) in zip(state, combination)]
buffer_list = map(lambda x: 5 - (x - 5) if x > 5 else x, buffer_list)
num_turns = sum(buffer_list)
print(num_turns)


n = int(input())
origin = [int(a) for a in input()]
code = [int(b) for b in input()]
move = 0
for i in range(n):
	c = max(code[i], origin[i])
	d = min(code[i], origin[i])
	move += min(abs(code[i] - origin[i]), 9 - c + 1 + d)
print(move)


n = int(input())
foo = list(map(int, list(input())))
bar = list(map(int, list(input())))
count = 0
for i in range(n):
	a = foo[i] - bar[i]
	if a < 0:
		a = 10 + a
	b = bar[i] - foo[i]
	if b < 0:
		b = 10 + b
	count += min(a, b)
print(count)


n = int(input())
s = input()
c = input()
t = 0
for i in range(n):
	x = max(int(s[i]), int(c[i]))
	y = min(int(s[i]), int(c[i]))
	if x - y <= 5:
		t += x - y
	else:
		t += 10 - x + y
print(t)


def trial():
	num = int(input())
	first = input()
	second = input()
	counter = 0
	for i in range(num):
		if abs(int(first[i]) - int(second[i])) <= 5:
			counter += abs(int(first[i]) - int(second[i]))
		elif int(first[i]) > int(second[i]):
			counter += int(second[i]) + 10 - int(first[i])
		else:
			counter += int(first[i]) + 10 - int(second[i])
	return print(counter)
trial()


n = int(input())
state = [int(x) for x in input()]
key = [int(x) for x in input()]
out = []
for i in range(n):
	(a, b) = (state[i], key[i])
	diff = abs(a - b)
	other = min(a, b) + 10 - max(a, b)
	out.append(min(diff, abs(other)))
print(sum(out))


a = int(input())
b = input()
c = input()
res = 0
for k in range(a):
	sum = 0
	m = min(int(b[k]), int(c[k]))
	ma = max(int(b[k]), int(c[k]))
	while m != ma:
		sum += 1
		m += 1
	res += min(sum, 10 - sum)
print(res)


(n, a, b) = (int(input()), input(), input())
ans = sum((5 - abs(abs(int(a[i]) - int(b[i])) - 5) for i in range(n)))
print(ans)


n = eval(input())
ori = input()
rel = input()
cnt = 0
for i in range(n):
	a = abs(int(ori[i]) - int(rel[i]))
	if a < 5:
		cnt += a
	else:
		cnt += 10 - a
print(cnt)


n = int(input())
inp = input()
secret = input()
ans = 0
for i in range(len(inp)):
	ans += min(10 - abs(int(inp[i]) - int(secret[i])), abs(int(inp[i]) - int(secret[i])))
print(ans)


n = int(input())
s1 = list(map(int, input()))
s2 = list(map(int, input()))
c = 0
for i in range(n):
	c += min(abs(s2[i] - s1[i]), abs(10 + s2[i] - s1[i]), abs(10 + s1[i] - s2[i]))
print(c)


discs = input()
discs = int(discs)
original = input()
correct = input()
sum = 0
for i in range(discs):
	dis = abs(int(original[i]) - int(correct[i]))
	if dis > 5:
		dis = 10 - dis
	sum += dis
print(sum)


n = int(input())
a = str(input())
b = str(input())
hsl = 0
for i in range(n):
	hsl += min(abs(int(a[i]) - int(b[i])), 10 - abs(int(a[i]) - int(b[i])))
print(hsl)


n = int(input())
first = input()
last = input()
c_of_m = 0
c = 0
for i in range(n):
	if int(first[i]) > int(last[i]) or int(first[i]) < int(last[i]):
		f = int(first[i])
		l = int(last[i])
		while f > l:
			l = l + 1
			c = c + 1
		while f < l:
			f = f + 1
			c = c + 1
		if c <= 5:
			c_of_m = c_of_m + c
		elif c == 6:
			c_of_m = c_of_m + 4
		elif c == 7:
			c_of_m = c_of_m + 3
		elif c == 8:
			c_of_m = c_of_m + 2
		elif c == 9:
			c_of_m = c_of_m + 1
		c = 0
	else:
		continue
print(c_of_m)


num_disks = int(input())
a = input()
b = input()
moves = 0
for i in range(num_disks):
	(x, y) = (int(a[i]), int(b[i]))
	through = abs(x - y)
	around = min(x, y) + (9 - max(x, y)) + 1
	moves += min(through, around)
print(moves)


n = int(input())
s1 = input()
s2 = input()
e = 0
for i in range(n):
	a = int(s1[i])
	b = int(s2[i])
	r = min(9 + a - b, 9 - a + b)
	if r < abs(a - b):
		e += 1
	e += min(abs(a - b), r)
print(e)


_ = input()
original = input()
target = input()
turns = 0
for (idx, disk) in enumerate(original):
	diff = abs(int(disk) - int(target[idx]))
	turns += min(diff, 10 - diff)
print(turns)


n = int(input())
o = list(input())
m = list(input())
s = 0
for i in range(n):
	a = int(o[i])
	b = int(m[i])
	tr = abs(a - b)
	stp = min(tr, 10 - tr)
	s += stp
print(s)


t = int(input())
l = []
m = []
l = list(map(int, input()))
m = list(map(int, input()))
count = 0
for i in range(t):
	count += min(abs(l[i] - m[i]), 10 - abs(l[i] - m[i]))
print(count)


n = int(input())
a = int(input())
b = int(input())
m = 0
for i in range(n):
	x = a % 10
	y = b % 10
	p = abs(x - y)
	q = abs(10 - p)
	r = min(p, q)
	m = m + r
	a = a // 10
	b = b // 10
print(m)


x = int(input())
y = input()
z = input()
w1 = 0
w2 = 0
t = 0
for i in range(x):
	(q, a) = (int(y[i]), int(z[i]))
	(w1, w2) = (abs(a - q), min(q, a) + (10 - max(a, q)))
	t += min(w1, w2)
print(t)


a = input()
b = input()
c = input()
turn = 0
for i in range(int(a)):
	newturn = abs(int(b[i]) - int(c[i]))
	if newturn > 5:
		newturn = 10 - newturn
	turn += newturn
print(turn)


import math
n = int(input())
a = input()
b = input()
a = tuple(a)
b = tuple(b)
count = 0
for x in range(len(a)):
	temp = math.fabs(int(a[x]) - int(b[x]))
	if temp > 5:
		count += 10 - temp
	else:
		count += temp
print(int(count))


a = int(input())
x = input()
y = input()
s = 0
for i in range(a):
	q = abs(int(x[i]) - int(y[i]))
	w = abs(int(x[i]) + 10 - int(y[i]) if y[i] > x[i] else int(y[i]) + 10 - int(x[i]))
	if q > w:
		s += w
	else:
		s += q
print(s)


n = int(input())
a = input()
b = input()
c = int(0)
for i in range(n):
	c1 = abs(int(a[i]) - int(b[i]))
	c2 = abs(int('1' + str(a[i])) - int(b[i]))
	c3 = abs(int('1' + str(b[i])) - int(a[i]))
	c = int(c) + min(c1, c2, c3)
print(c)


def rotation(start, final):
	start = int(start)
	final = int(final)
	return min((start + 10 - final) % 10, (final + 10 - start) % 10)

def start():
	n = int(input())
	originalState = input()
	code = input()
	numberRotation = 0
	for i in range(n):
		numberRotation += rotation(originalState[i], code[i])
	print(numberRotation)
start()


n = int(input())
first = input()
last = input()
count = 0
for i in range(n):
	a = int(first[i])
	b = int(last[i])
	count += min(10 - max(a, b) + min(a, b), abs(a - b))
print(count)


n = int(input())
s1 = [int(i) for i in list(input())]
s2 = [int(i) for i in list(input())]
ncount = 0
for i in range(n):
	ncount += min(abs(s1[i] - s2[i]), 10 - abs(s1[i] - s2[i]))
print(ncount)


n = int(input())
a = input()
b = input()
count = 0
numbers = '123456789012345678901234567890'
for i in range(n):
	if a[i] != b[i]:
		start_idx = numbers[10:20].index(a[i]) + 10
		(forwards, backwards) = (0, 0)
		for k in numbers[start_idx + 1:]:
			forwards += 1
			if k == b[i]:
				break
		for l in numbers[:start_idx][::-1]:
			backwards += 1
			if l == b[i]:
				break
		count += min(forwards, backwards)
print(count)


n = int(input())
w = input()
c = input()
s = 0
for i in range(n):
	a = w[i]
	a = int(a)
	b = c[i]
	b = int(b)
	d = a - b
	if d < 0:
		d = d * -1
	if d >= 6:
		d = 10 - d
	s = s + d
print(s)


act = 0
n = int(input())
curr = [int(i) for i in list(input())]
password = [int(i) for i in list(input())]
for i in range(n):
	act += min(abs(curr[i] - password[i]), abs(password[i] + 10 - curr[i]), abs(curr[i] + 10 - password[i]))
print(act)


n = int(input())
a = input()
b = input()
c = 0
for i in range(n):
	if abs(int(a[i]) - int(b[i])) > abs(10 - abs(int(a[i]) - int(b[i]))):
		c += abs(10 - abs(int(a[i]) - int(b[i])))
	else:
		c += abs(int(a[i]) - int(b[i]))
print(c)


a = int(input())
s1 = input()
s2 = input()
ans = 0
for i in range(a):
	s = int(s1[i])
	ss = int(s2[i])
	ans += min(abs(s - ss), 10 - abs(s - ss))
print(ans)


import math
input_s = int(input())
input_l = input()
input_m = input()
result = 0
for i in range(input_s):
	r = abs(int(input_l[i]) - int(input_m[i]))
	result += r if r <= 5 else 10 - r
print(result)


n = int(input())
src = input()
dst = input()
tot = 0
for (i, j) in zip(src, dst):
	d = abs(int(i) - int(j))
	if d > 5:
		d = 10 - d
	tot += d
print(tot)


number_of_disks = int(input())
original_state = input()
desired_state = input()
current_index = 0

def calculate_min_distance(source, destination):
	source_as_number = int(source)
	destination_as_number = int(destination)
	min_number = min(source_as_number, destination_as_number)
	max_number = max(source_as_number, destination_as_number)
	return min(max_number - min_number, 9 - max_number + min_number + 1)
total_distance = 0
while current_index < number_of_disks:
	total_distance += calculate_min_distance(original_state[current_index], desired_state[current_index])
	current_index += 1
print(total_distance)


n = int(input())
s = input()
a = []
for i in range(0, n):
	a.append(int(s[i]))
s = input()
b = []
for i in range(0, n):
	b.append(int(s[i]))
ans = 0
for i in range(0, n):
	ans += min(abs(a[i] - b[i]), 10 - abs(a[i] - b[i]))
print(ans)


__author__ = 'WildHamster'
from math import fabs
n = int(input())
s = input()
t = input()
ans = 0
for i in range(n):
	ans = ans + min(abs(int(s[i]) - int(t[i])), 10 - abs(int(s[i]) - int(t[i])))
print(ans)


n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
total = 0
for i in range(n):
	total += min((a[i] - b[i]) % 10, -(a[i] - b[i]) % 10)
print(total)


nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
n = int(input())
mix = [int(s) for s in input()]
sort = [int(s) for s in input()]
moves = 0
for i in range(n):
	x = nums.index(mix[i])
	y = nums.index(sort[i])
	if x != y:
		L1 = abs(x - y)
		L2 = abs(10 - L1)
		if L1 > L2:
			moves += L2
		else:
			moves += L1
	else:
		moves += 0
print(moves)


n = int(input())
a = [int(i) for i in input()]
b = [int(i) for i in input()]
(c, d, e) = (0, 0, [])
for i in a:
	if abs(i - b[c]) <= 5:
		d += abs(i - b[c])
	else:
		if i > b[c]:
			f = b[c]
			g = i
		else:
			f = i
			g = b[c]
		ve1 = [i for i in range(f, g + 1)]
		ve = [i for i in range(10)]
		d += 1 + len(set(ve) - set(ve1))
	c += 1
print(d)


n = int(input())
s1 = input()
s2 = input()
start = []
end = []
answer = 0
for i in range(n):
	start.append(int(s1[i]))
	end.append(int(s2[i]))
for i in range(n):
	temp = start[i] - end[i]
	if temp < 0:
		temp = -temp
		if temp > 10 + start[i] - end[i]:
			temp = 10 + start[i] - end[i]
	elif temp > 10 + end[i] - start[i]:
		temp = 10 + end[i] - start[i]
	answer = answer + temp
print(answer)


a = int(input())
b = str(input())
c = str(input())
x = d = s = int(0)
while x < a:
	d = abs(int(b[x]) - int(c[x]))
	if d > 5:
		d = 10 - d
	s = s + d
	x = x + 1
print(s)


n = int(input())
x = input()
y = input()
sum = 0
while n:
	n -= 1
	a = abs(ord(x[n]) - ord(y[n]))
	if a > 5:
		sum += 10 - a
	else:
		sum += a
print(sum, end='')


n = int(input())
a = list(input())
b = list(input())
res = 0
for i in range(n):
	temp = abs(int(a[i]) - int(b[i]))
	res += min(temp, 10 - temp)
print(res)


n = int(input())
o = list(map(int, list(input())))
s = list(map(int, list(input())))
t = 0
for i in range(n):
	t += min(abs(o[i] - s[i]), abs(o[i] + 10 - s[i]), abs(o[i] - (s[i] + 10)))
print(t)


n = int(input())
m = input()
q = input()
time = 0
for i in range(n):
	xiao = min(int(m[i]), int(q[i]))
	da = max((int(m[i]), int(q[i])))
	time += min(xiao + 10 - da, da - xiao)
print(time)


k = int(input())
A = input()
while len(A) != k:
	A = input()
B = input()
while len(B) != k:
	B = input()
m = 0
for i in range(0, k):
	x = min(abs(int(A[i]) - int(B[i])), 10 - abs(int(A[i]) - int(B[i])))
	m += x
print(m)


n = int(input())
ori_state = input()
sec_state = input()
times = 0
for i in range(n):
	k = abs(int(ori_state[i]) - int(sec_state[i]))
	if k > 5:
		times += 10 - k
	else:
		times += k
print(times)


n = int(input())
st = list(map(int, input()))
lt = list(map(int, input()))
t = 0
for i in range(n):
	s = abs(st[i] - lt[i])
	if s > 5:
		s = 10 - s
		t = t + s
	else:
		t = t + s
print(t)


n = int(input())
s1 = input()
s2 = input()
s1 = list(s1)
s2 = list(s2)
m = 0
for i in range(n):
	k = abs(int(s1[i]) - int(s2[i]))
	k2 = 10 - k
	if k >= k2:
		m = m + k2
	else:
		m = m + k
print(m)


n = int(input())
pres = [int(i) for i in input()]
pasw = [int(i) for i in input()]
count = 0
for i in range(n):
	count = count + min(abs(pasw[i] - pres[i]), 10 - abs(pres[i] - pasw[i]))
print(count)


a = int(input())
n = list(input())
m = list(input())
count = 0
for i in range(a):
	count += min(abs(int(n[i]) - int(m[i])), 10 - abs(int(n[i]) - int(m[i])))
print(count)


N = int(input())
A = input()
B = input()
a = []
b = []
for k in A:
	a.append(int(k))
for i in B:
	b.append(int(i))
c = 0
for i in range(N):
	if a[i] <= b[i]:
		a1 = 10 + a[i] - b[i]
		a2 = b[i] - a[i]
	else:
		a1 = 10 + b[i] - a[i]
		a2 = a[i] - b[i]
	if a1 <= a2:
		c += a1
	else:
		c += a2
print(c)


n = int(input())
b = input()
c = input()
count = 0
for i in range(n):
	if abs(int(b[i]) - int(c[i])) <= 5:
		count += abs(int(b[i]) - int(c[i]))
	else:
		count += 10 - abs(int(b[i]) - int(c[i]))
print(count)


n = int(input())
a = list(str(input()))
b = list(str(input()))
i = 0
cnt = 0
while n > i:
	z = abs(int(a[i]) - int(b[i]))
	y = 10 - z
	cnt += min([y, z])
	i += 1
print(cnt)


numbers = int(input())
start = [int(s) for s in input().replace('', ' ').strip().split()]
toUn = [int(t) for t in input().replace('', ' ').strip().split()]
ans = 0
for i in range(numbers):
	if abs(start[i] - toUn[i]) > 5:
		if start[i] >= toUn[i]:
			ans += 9 - start[i] + toUn[i] + 1
		else:
			ans += start[i] + (9 - toUn[i]) + 1
	else:
		ans += abs(start[i] - toUn[i])
print(ans)


input()
a = input()
b = input()
steps = 0
for (i, j) in zip(a, b):
	x = abs(int(i) - int(j))
	if x > 5:
		steps += 10 - x
	else:
		steps += x
print(steps)


def combination(cur, pas):
	ans = 0
	for (c, p) in zip(cur, pas):
		big = max(int(c), int(p))
		smol = min(int(c), int(p))
		val1 = big - smol
		val2 = smol + 10 - big
		ans += min(val1, val2)
	return ans
n = int(input())
cur = list(input())
pas = list(input())
print(combination(cur, pas))


n = int(input())
InpList = [None] * n
OutpList = [None] * n
InpList = list(map(str, input()))
OutpList = list(map(str, input()))
index = 0
minus = 0
plus = 0
res = 0
while index < n:
	x = int(InpList[index])
	y = int(OutpList[index])
	while x != y:
		x = x - 1
		if x == -1:
			x = 9
		minus = minus + 1
	x = int(InpList[index])
	y = int(OutpList[index])
	while x != y:
		x = x + 1
		if x == 10:
			x = 0
		plus = plus + 1
	if plus >= minus:
		res = res + minus
	else:
		res = res + plus
	minus = 0
	plus = 0
	index = index + 1
print(res)


n = int(input())
o = input()
k = input()
count = 0
for i in range(n):
	x = o[i]
	y = k[i]
	if abs(int(x) - int(y)) > 10 - abs(int(x) - int(y)):
		count = count + (10 - abs(int(x) - int(y)))
	else:
		count = count + abs(int(x) - int(y))
print(count)


a = int(input())
b = list(input())
c = list(input())
i = 0
count = 0
while i < a:
	if abs(int(b[i]) - int(c[i])) <= 5:
		count += abs(int(b[i]) - int(c[i]))
	else:
		count += 10 - abs(int(b[i]) - int(c[i]))
	i += 1
print(count)


n = int(input())
org = list(map(int, input()))
need = list(map(int, input()))
moves = 0
for i in range(n):
	moves += min(abs(org[i] - need[i]), 10 - abs(org[i] - need[i]))
print(moves)


from math import *
n = input()
s1 = input()
s2 = input()
ans = 0
for i in range(len(s1)):
	a = int(s1[i])
	b = int(s2[i])
	if a > b:
		(a, b) = (b, a)
	ans += min(b - a, a + 9 - b + 1)
print(ans)


n = int(input())
s = input()
l = input()
k = 0
for i in range(n):
	x = abs(int(l[i]) - int(s[i]))
	k += min(x, 10 - x)
print(k)


i = lambda : map(ord, input())
i()
print(sum((min(abs(a - b), 10 - abs(b - a)) for (a, b) in zip(i(), i()))))


n = input()
n = int(n)
a = input()
b = input()
a = list(str(a))
b = list(str(b))
c = [int(i) for i in a]
d = [int(j) for j in b]
moves = 0
for i in range(n):
	move = abs(c[i] - d[i])
	if move > 5:
		move = 10 - move
	moves = moves + move
print(moves)


a = int(input())
x = input()
y = input()
c = 0
for i in range(a):
	z = []
	z.append(int(x[i]))
	z.append(int(y[i]))
	b = max(z) - min(z)
	if b > 4:
		b = 9 - max(z) + (min(z) + 1)
	c += b
print(c)


n = int(input())
initial = input()
final = input()
moves = 0
for i in range(n):
	difference = abs(int(final[i]) - int(initial[i]))
	moves += min(difference, 10 - difference)
print(moves)


n = int(input())
given = input()
target = input()
count = 0
for i in range(n):
	shoja = abs(int(given[i]) - int(target[i]))
	beka = 10 - shoja
	if shoja <= beka:
		count = count + shoja
	else:
		count = count + beka
print(int(count))


(a, b, c, d) = (int(input()), input(), input(), 0)
for i in range(a):
	d += min(abs(int(b[i]) - int(c[i])), abs(int(b[i])) + abs(9 - int(c[i])) + 1, abs(10 - int(b[i])) + abs(int(c[i])))
print(d)


n = eval(input())
z = 0
a = list(map(int, input()))
b = list(map(int, input()))
for (e1, e2) in zip(a, b):
	z = z + min(abs(e1 - e2), 10 - abs(e1 - e2))
print(z)


x = int(input())
str1 = input()
str2 = input()
i = 0
sum = 0
while i < len(str1):
	c = abs(int(str1[i]) - int(str2[i]))
	if c > 4:
		sum += 10 - max(int(str1[i]), int(str2[i])) + min(int(str1[i]), int(str2[i]))
	else:
		sum += c
	i += 1
print(sum)


n = int(input())
a = input()
b = input()
x = [min(abs(int(a[i]) - int(b[i])), 10 - abs(int(a[i]) - int(b[i]))) for i in range(n)]
print(sum(x))


n = int(input())
comb1 = input()
comb2 = input()
move = 0
for i in range(n):
	a = min(int(comb1[i]), int(comb2[i]))
	b = max(int(comb1[i]), int(comb2[i]))
	diff = min(b - a, 10 + a - b)
	move = move + diff
print(move)


t = int(input())
os = input()
ds = input()
cost = 0
for i in range(len(os)):
	o = int(os[i])
	d = int(ds[i])
	if o > d:
		c1 = o - d
		c2 = 9 - o + (d - 0) + 1
		cost += min(c1, c2)
	else:
		c1 = d - o
		c2 = 9 - d + (o - 0) + 1
		cost += min(c1, c2)
print(cost)


n = int(input())
a = input()
b = input()
r = 0
for i in range(n):
	t = abs(int(a[i]) - int(b[i]))
	r += min(t, 10 - t)
print(r)


import math
n = int(input())
sum1 = 0
x = input()
l = list(x)
y = input()
m = list(y)
for i in range(n):
	a = abs(int(l[i]) - int(m[i]))
	if a > 5:
		sum1 += 10 - a
	else:
		sum1 += a
print(sum1)


n = int(input())
s1 = input()
s2 = input()
answer = 0
for i in range(n):
	c1 = ord(s1[i])
	c2 = ord(s2[i])
	answer += min(abs(c1 - c2), 10 - abs(c1 - c2))
print(answer)


n = int(input())
s = str(input())
t = str(input())
ans = 0
for i in range(n):
	ans += min(abs(ord(s[i]) - ord(t[i])), 10 - abs(ord(s[i]) - ord(t[i])))
print(ans)


a = int(input())
b = input()
c = input()
x = list(b)
y = list(c)
i = 0
k = 0
while i < a:
	p = int(x[i])
	q = int(y[i])
	r = max(p, q)
	s = min(p, q)
	e = r - s
	f = 10 + s - r
	if e <= f:
		k = k + e
	elif e > f:
		k = k + f
	i = i + 1
print(k)


n = int(input())
a = input()
b = input()
count = 0
for i in range(len(a)):
	n1 = int(a[i])
	n2 = int(b[i])
	P = n1 - n2
	P = abs(P)
	P = int(P)
	if P > 4:
		count += 9 - P + 1
	else:
		count += P
print(count)


n = int(input())
a = list(input())
b = list(input())
s = 0
for i in range(n):
	a[i] = int(a[i])
	b[i] = int(b[i])
	x = abs(a[i] - b[i])
	if x <= 5:
		s += x
	else:
		x = abs(9 - max(a[i], b[i])) + abs(0 - min(a[i], b[i])) + 1
		s += x
print(s)


n = int(input())
s = input()
t = input()
c = 0
for i in range(len(s)):
	l = []
	a = int(s[i]) + (9 - int(t[i])) + 1
	d = int(t[i]) + (9 - int(s[i])) + 1
	b = abs(int(s[i]) - int(t[i]))
	l.append(a)
	l.append(b)
	l.append(d)
	c = c + min(l)
print(c)


n = int(input())
ori = list(map(int, list(input())))
target = list(map(int, list(input())))
ans = 0
for i in range(n):
	diff = abs(ori[i] - target[i])
	if diff > 5:
		ans += 10 - diff
	else:
		ans += diff
print(ans)


__author__ = 'myduomilia'
n = input()
s1 = input()
s2 = input()
ans = 0
for i in range(len(s1)):
	t = abs(int(s1[i]) - int(s2[i]))
	ans += min(t, 10 - t)
print(ans)


def main():
	input()
	a = list(map(int, list(input())))
	b = list(map(int, list(input())))
	zipped = zip(a, b)
	output = 0
	for i in zipped:
		diff = abs(i[0] - i[1])
		if diff > 5:
			output += 10 - diff
		else:
			output += diff
	print(output)
main()


n = int(input())
ch1 = input()
ch2 = input()
x = 0
for i in range(n):
	mx = max(int(ch1[i]), int(ch2[i]))
	mn = min(int(ch1[i]), int(ch2[i]))
	x += min(mx - mn, mn + 10 - mx)
print(x)


n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
t_count = 0
for i in range(n):
	m = min(a[i], b[i])
	ma = max(a[i], b[i])
	count_1 = m + 10 - ma
	count_2 = ma - m
	t_count += min(count_1, count_2)
print(t_count)


t = int(input())
x = [int(i) for i in input()]
y = [int(i) for i in input()]
arr = []
for i in range(t):
	dis = min(abs(x[i] - y[i]), 10 - abs(x[i] - y[i]))
	arr.append(dis)
print(sum(arr))


t = int(input())
x = input()
y = input()
x = list(x)
y = list(y)
c = 0
for i in range(t):
	p = abs(int(x[i]) - int(y[i]))
	if p <= 5:
		c += p
	else:
		c += 10 - p
print(c)


n = int(input())
a = input()
b = input()
m = 0
for i in range(n):
	if int(a[i]) < int(b[i]):
		a1 = int(a[i])
		b1 = int(b[i])
	else:
		a1 = int(b[i])
		b1 = int(a[i])
	m1 = b1 - a1
	m2 = 10 + a1 - b1
	m += min(m1, m2)
print(m)


n = int(input())
a = input()
b = input()
up_mov = 0
lo_mov = 0
suma = 0
for i in range(n):
	first = a[i]
	second = b[i]
	if int(first) - int(second) > 0:
		lo_mov = int(first) - int(second)
		up_mov = 10 - int(first) + int(second)
		if lo_mov > up_mov:
			suma = suma + up_mov
		else:
			suma = suma + lo_mov
	elif int(first) - int(second) < 0:
		lo_mov = int(first) + 10 - int(second)
		up_mov = int(second) - int(first)
		if lo_mov > up_mov:
			suma = suma + up_mov
		else:
			suma = suma + lo_mov
print(suma)


n = int(input())
a1 = input()
b1 = input()
a = list(a1)
b = list(b1)
for i in range(len(a)):
	a[i] = int(a[i])
	b[i] = int(b[i])
k = 0
for i in range(len(a)):
	if abs(a[i] - b[i]) <= 5:
		k += abs(a[i] - b[i])
	else:
		k += 10 - abs(a[i] - b[i])
print(k)


n = int(input())
s = input()
s1 = input()
sum = 0
for i in range(n):
	j = abs(int(s[i]) - int(s1[i]))
	sum += min(j, 10 - j)
print(sum)


def digit_distance(a, b):
	(a, b) = (min(a, b), max(a, b))
	dist1 = b - a
	dist2 = 10 + a - b
	return min(dist1, dist2)

def solve(goal, current):
	return sum((digit_distance(a, b) for (a, b) in zip(goal, current)))

def main():
	n = int(input())
	original = [int(c) for c in input().strip()]
	mcduck = [int(c) for c in input().strip()]
	assert n == len(original) == len(mcduck)
	result = solve(original, mcduck)
	print(result)
main()


a = int(input())
l1 = list(map(str, input().split(' ')))
l2 = list(map(str, input().split(' ')))
sum = 0
for i in range(a):
	b = abs(int(l1[0][i]) - int(l2[0][i]))
	if b < 5:
		sum = sum + b
	elif b > 5:
		sum = sum + (10 - b)
	elif b == 5:
		sum = sum + 5
print(sum)


n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
res = 0
for i in range(n):
	res1 = abs(a[i] - b[i])
	res2 = 10 - abs(a[i] - b[i])
	res += min(res1, res2)
print(res)


n = int(input())
s1 = input()
s2 = input()
s = 0
for i in range(n):
	c1 = int(s1[i])
	c2 = int(s2[i])
	s += min(abs(c1 - c2), abs(c2 + 10 - c1), abs(c1 + 10 - c2))
print(s)


def f1(a, b):
	return abs(a - b)

def f2(a, b):
	(a, b) = (max(a, b), min(a, b))
	b += 10
	return b - a
n = int(input())
a = [int(x) for x in list(input())]
b = [int(x) for x in list(input())]
print(sum((min(f1(x, y), f2(x, y)) for (x, y) in zip(a, b))))


n = int(input())
s1 = input()
s2 = input()
s = 0
for i in range(n):
	m = min(abs(int(s1[i]) - int(s2[i])), min(int(s1[i]), 10 - int(s1[i])) + min(int(s2[i]), 10 - int(s2[i])))
	s = s + m
print(s)


input()
print(sum((min(abs(a - b), 10 - abs(a - b)) for (a, b) in zip(map(int, input()), map(int, input())))))


n = int(input())
s = input()
t = input()
mi = 0
for i in range(n):
	mi += min(abs(int(s[i]) - int(t[i])), 10 - abs(int(s[i]) - int(t[i])))
print(mi)


n = int(input())
a = list(map(int, str(input())))
b = list(map(int, str(input())))
s = 0
for i in range(n):
	diff_1 = abs(a[i] - b[i])
	diff_2 = abs(min(a[i], b[i]) + 10 - max(a[i], b[i]))
	s += min(diff_1, diff_2)
print(s)


n = int(input())
s = input()
f = input()
d = 0
for i in range(n):
	if s[i] != f[i]:
		a = abs(int(f[i]) - int(s[i]))
		b = abs(10 - a)
		d += min(a, b)
print(d)


n = int(input())
s = input()
k = input()
o = 0
for i in range(len(s)):
	ch = abs(int(s[i]) - int(k[i]))
	if ch > 5:
		o += 10 - ch
	else:
		o += ch
print(o)


n = int(input())
s1 = str(input())
s2 = str(input())
res = 0
for i in range(n):
	digit1 = ord(s1[i]) - ord('0')
	digit2 = ord(s2[i]) - ord('0')
	choice1 = abs(digit1 - digit2)
	choice2 = 10 - choice1
	res += min(choice1, choice2)
print(res)


def num_moves_to_open_lock(disks, current_state, solution):
	return sum((get_moves_for_disk(x, y) for (x, y) in zip(current_state, solution)))

def get_moves_for_disk(x, y):
	if x < y:
		return min(y - x, x + 10 - y)
	else:
		return min(10 + y - x, x - y)
n = int(input())
current_state = map(int, list(input()))
solution = map(int, list(input()))
print(num_moves_to_open_lock(n, current_state, solution))


n = int(input())
start = input()
end = input()
a = 0
b = 0
sum = 0
for i in range(n):
	a = max(int(start[i]), int(end[i]))
	b = min(int(start[i]), int(end[i]))
	sum += min(a - b, 10 - a + b)
print(sum)


nums = input().split(' ')
nums = int(nums[0])
ks = input()
ks = list(ks)
ks = [int(ks[i]) for i in range(nums)]
ls = input()
ls = list(ls)
ls = [int(ls[i]) for i in range(nums)]
sums = 0
counts = 0
for i in range(nums):
	lens = ks[i] - ls[i]
	if abs(lens) <= 5:
		sums += abs(lens)
	elif abs(lens) > 5:
		sums = sums + 10 - abs(lens)
print(sums)


n = int(input().strip())
n1 = [int(__) for __ in list(input().strip())]
n2 = [int(__) for __ in list(input().strip())]
ans = 0
for i in range(n):
	(a, b) = (n1[i], n2[i])
	ans += min(abs(a - b), 9 - a + b + 1, 9 - b + a + 1)
print(ans)


n = int(input())
a = input()
b = input()
count = 0
for i in range(n):
	an = int(a[i])
	bn = int(b[i])
	count += min(max(an, bn) - min(an, bn), 10 - max(an, bn) + min(an, bn))
print(count)


disks = int(input().strip())
i_set = [int(x) for x in input().strip()]
o_comb = [int(x) for x in input().strip()]
movements = 0
for i in range(disks):
	(min_d, max_d) = (min(i_set[i], o_comb[i]), max(i_set[i], o_comb[i]))
	movements += min(max_d - min_d, min_d + 10 - max_d)
print(movements)


n = int(input())
a = input()
b = input()
count = 0
for i in range(n):
	min_digit = min(int(a[i]), int(b[i]))
	max_digit = max(int(a[i]), int(b[i]))
	count = count + min(max_digit - min_digit, min_digit + 10 - max_digit)
print(count)


m = int(input())
l = list(input())
k = list(input())
l = list(map(int, l))
k = list(map(int, k))
s = 0
for i in range(len(l)):
	if l[i] > k[i]:
		u = l[i] - k[i]
		r = k[i] + 10 - l[i]
	else:
		u = k[i] - l[i]
		r = l[i] + 10 - k[i]
	s = s + min(u, r)
print(s)


import itertools
import sys
from collections import defaultdict, Counter
from math import sqrt
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def s(d):
	dis = 1 + 4 * 2 * 3 * d
	ds = sqrt(dis)
	return (-1 + ds) / 6

def main():
	d = inp()
	v1 = [ord(v) - ord('0') for v in insr()]
	v2 = [ord(v) - ord('0') for v in insr()]
	s = 0
	for i in range(d):
		s1 = max(v1[i], v2[i]) - min(v1[i], v2[i])
		s2 = 10 - max(v1[i], v2[i]) + min(v1[i], v2[i])
		s += min(s1, s2)
	print(s)
main()


n = int(input())
ans = 0
data = input()
code = input()
for i in range(n):
	ans += abs(5 - abs(int(data[i]) - (int(code[i]) + 5) % 10))
print(ans)


n = int(input())
(a, b) = (input(), input())
count = 0
for i in range(n):
	q = abs(int(a[i]) - int(b[i]))
	count += q * (q <= 5) + (10 - q) * (q > 5)
print(count)


n = input()
l1 = input()
l2 = input()
count = 0
for i in range(0, len(l1)):
	x = abs(int(l2[i]) - int(l1[i]))
	if x >= 5:
		x = 10 - x
	count += x
print(count)


n = int(input())
line0 = str(input())
line1 = str(input())
value = 0
for i in range(n):
	curr = abs(int(line0[i]) - int(line1[i]))
	value += min(curr, 10 - curr)
print(value)


a = int(input())
b = input()
c = input()
j = 0
for i in range(a):
	x = abs(int(b[i]) - int(c[i]))
	y = 10 - x
	j += min(x, y)
print(j)


n = input()
state = input()
state2 = input()
a = []
b = []
c = 0
for i in state:
	a.append(int(i))
for i in state2:
	b.append(int(i))
for i in range(len(a)):
	c += min(abs(a[i] - b[i]), 10 - abs(a[i] - b[i]))
print(c)


n = int(input())
s1 = [int(x) for x in input()]
s2 = [int(x) for x in input()]

def min(a, b):
	if a < b:
		return a
	else:
		return b
ans = 0
for i in range(n):
	abso = abs(s1[i] - s2[i])
	ans += min(abso, 10 - abso)
print(ans)


hat = int(input())
s = input()
e = input()
total = 0
for i in range(hat):
	x = abs(int(s[i]) - int(e[i]))
	if x > 5:
		total += 10 - x
	else:
		total += x
print(total)


n = int(input())
act = list(map(int, list(input())))
res = list(map(int, list(input())))
nChanges = 0
for i in range(len(act)):
	a = int(act[i])
	r = int(res[i])
	aux = max(a, r)
	end = min(a, r)
	inv = 0
	while aux != end:
		inv += 1
		aux += 1
		if aux > 9:
			aux = 0
	nChanges += min(abs(a - r), inv)
print(nChanges)


n = int(input())
stringA = input()
stringB = input()
rolls = 0
for i in range(n):
	nA = int(stringA[i])
	nB = int(stringB[i])
	timesA = 0
	tempA = nA
	tempB = nB
	while tempA != tempB:
		timesA += 1
		if tempA == 9:
			tempA = 0
		else:
			tempA += 1
	timesB = 0
	tempA = nA
	tempB = nB
	while tempA != tempB:
		timesB += 1
		if tempA == 0:
			tempA = 9
		else:
			tempA -= 1
	rolls += min(timesA, timesB)
print(rolls)


def min_step(current, target, digit):
	cnt = 0
	cur_list = []
	tar_list = []
	for i in current:
		cur_list.append(int(i))
	for i in target:
		tar_list.append(int(i))
	for i in range(digit):
		if cur_list[i] == tar_list[i]:
			continue
		if cur_list[i] > tar_list[i]:
			cnt += min(abs(cur_list[i] - tar_list[i]), 10 - cur_list[i] + tar_list[i])
		else:
			cnt += min(abs(cur_list[i] - tar_list[i]), 10 - tar_list[i] + cur_list[i])
	return cnt
line_one = int(input())
line_two = str(input())
line_three = str(input())
print(min_step(line_two, line_three, line_one))


disk_num = int(input())
starting_code = input()
ending_code = input()
moves = 0
for i in range(disk_num):
	if starting_code[i] > ending_code[i] and int(starting_code[i]) - int(ending_code[i]) <= 5:
		moves = int(starting_code[i]) - int(ending_code[i]) + moves
	elif ending_code[i] > starting_code[i] and int(ending_code[i]) - int(starting_code[i]) <= 5:
		moves = int(ending_code[i]) - int(starting_code[i]) + moves
	elif starting_code[i] > ending_code[i] and int(starting_code[i]) - int(ending_code[i]) > 5:
		moves = 10 - (int(starting_code[i]) - int(ending_code[i])) + moves
	elif ending_code[i] > starting_code[i] and int(ending_code[i]) - int(starting_code[i]) > 5:
		moves = 10 - (int(ending_code[i]) - int(starting_code[i])) + moves
print(moves)


n = int(input())
s = list(str(input()))
s1 = list(str(input()))
d = 0
for i in range(n):
	(s[i], s1[i]) = (int(s[i]), int(s1[i]))
	a = max(s[i], s1[i]) - min(s[i], s1[i])
	b = min(s[i], s1[i]) + 10 - max(s[i], s1[i])
	d += min(a, b)
print(d)


n = int(input())
a = input()
b = input()
c = []
d = []
ans = 0
for i in a:
	c.append(int(i))
for i in b:
	d.append(int(i))
for i in range(n):
	x = abs(c[i] - d[i])
	if x > 5:
		x = 10 - x
	ans += x
print(ans)


disk = int(input())
orig = str(input())
ans = str(input())
count = 0
for i in range(disk):
	o = int(orig[i])
	a = int(ans[i])
	s = abs(o - a)
	if s > 5:
		s = 10 - s
	count += s
print(count)


n = int(input())
n1 = input()
n2 = input()
s = 0
for i in range(n):
	a = n1[i]
	b = n2[i]
	c = abs(int(a) - int(b))
	if c >= 5:
		d = abs(10 - c)
		s = s + d
	else:
		s = s + c
print(s)


num_digits = int(input())
orig_state = input()
combination = input()
orig_state = [int(a) for a in orig_state]
combination = [int(a) for a in combination]
num_moves = 0
for (o, c) in zip(orig_state, combination):
	temp = 0
	if o < c:
		temp = min(c - o, 9 - c + o + 1)
	elif o > c:
		temp = min(o - c, 9 - o + c + 1)
	num_moves += temp
print(num_moves)


from math import *
n = int(input())
string1 = input()
string2 = input()
counter = 0
for i in range(n):
	x = int(string1[i])
	y = int(string2[i])
	temp1 = abs(x - y)
	if x < y:
		temp2 = abs(x + 10 - y)
	else:
		temp2 = abs(y + 10 - x)
	if temp1 > temp2:
		counter += temp2
	else:
		counter += temp1
print(counter)


def method(char1, char2):
	d = int(char1) - int(char2)
	if abs(d) > 5:
		return 10 - abs(d)
	else:
		return abs(d)
n = int(input())
early = input()
final = input()
sol = []
for i in range(n):
	sol.append(method(early[i], final[i]))
a = sum(sol)
print(a)


a = int(input())
b = list(input())
c = list(input())
step = 0
for i in range(a):
	z = int(b[i])
	k = int(c[i])
	step += min(abs(z - k), 10 - abs(z - k))
print(step)


n = int(input())
a = input()
b = input()
result = 0
for i in range(n):
	if a[i] >= b[i]:
		if int(b[i]) + 10 - int(a[i]) >= 5:
			result += int(a[i]) - int(b[i])
		else:
			result += int(b[i]) + 10 - int(a[i])
	elif int(a[i]) + 10 - int(b[i]) >= 5:
		result += int(b[i]) - int(a[i])
	else:
		result += int(a[i]) + 10 - int(b[i])
print(result)


def solve():
	n = int(input())
	s = input()
	ss = input()
	c = 0
	for i in range(n):
		(a, b) = (int(s[i]), int(ss[i]))
		c += min(abs(a - b), 10 - abs(a - b))
	print(c)
solve()


n = int(input())
original = input()
real = input()
a = 0
for i in range(n):
	x = int(original[i]) - int(real[i])
	if x <= 5 and x > 0:
		a += x
	elif x <= 0 and x > -5:
		a = a - x
	elif x >= -9 and x <= -5:
		a = a + 10 + x
	elif x > 5 and x <= 9:
		a = a + 10 - x
print(a)


def Main():
	n = int(input())
	a = input()
	b = input()
	ans = 0
	for i in range(n):
		x = int(a[i])
		y = int(b[i])
		if x == 0:
			x = 10
		if y == 0:
			y = 10
		min_s = abs(x - y)
		if min_s > 10 - max(x, y) + min(x, y):
			min_s = 10 - max(x, y) + min(x, y)
		ans += min_s
	print(ans)
Main()


number_of_disks = input('')
initial_situation = input('')
unlock_code = input('')
number_of_moves = 0
for c in range(len(unlock_code)):
	if initial_situation[c] != unlock_code[c]:
		if abs(int(initial_situation[c]) - int(unlock_code[c])) <= 5:
			number_of_moves = number_of_moves + abs(int(initial_situation[c]) - int(unlock_code[c]))
		elif abs(int(initial_situation[c]) - int(unlock_code[c])) > 5 and int(initial_situation[c]) < int(unlock_code[c]):
			number_of_moves = number_of_moves + 10 + int(initial_situation[c]) - int(unlock_code[c])
		elif abs(int(initial_situation[c]) - int(unlock_code[c])) > 5 and int(initial_situation[c]) > int(unlock_code[c]):
			number_of_moves = number_of_moves + 10 + int(unlock_code[c]) - int(initial_situation[c])
print(number_of_moves)


n = int(input())
currstate = str(input())
finalstate = str(input())
ans = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
count = 0
for i in range(n):
	count += min(abs(int(currstate[i]) - int(finalstate[i])), 9 - abs(int(currstate[i]) - int(finalstate[i])) + 1)
print(count)


n = int(input())
code1 = input()
code2 = input()
k = 0
for i in range(0, n):
	c = abs(int(code1[i]) - int(code2[i]))
	if c <= 5:
		k += c
	else:
		k += 10 - c
print(k)


size = int(input())
sta_num = str(input())
cal_number = str(input())
cou = 0
for i in range(len(sta_num)):
	s = int(sta_num[i])
	c = int(cal_number[i])
	if s == c:
		pass
	elif s > c:
		tem = 10 + c
		n_tm = s - c
		if tem - s < n_tm:
			cou += tem - s
		else:
			cou += n_tm
	elif s < c:
		tem = s + 10
		n_tm = c - s
		if tem - c < n_tm:
			cou += tem - c
		else:
			cou += n_tm
print(cou)


import math
from fractions import Fraction as frac
MOD = 1000000000.0 + 7

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def solve(case_no):
	n = int(input())
	s1 = str(input())
	s2 = str(input())
	ans = 0
	for i in range(n):
		d = abs(ord(s1[i]) - ord(s2[i]))
		ans += min(d, 10 - d)
	print(ans)
t = 1
for i in range(1, t + 1):
	solve(i)


n = int(input())
f = list(map(int, list(input())))
t = list(map(int, list(input())))
r = 0
for i in range(len(f)):
	d = abs(f[i] - t[i])
	r += min(d, 10 - d)
print(r)


__author__ = 'catman'
n = int(input())
a = input()
b = input()
moves = 0
for i in range(n):
	x = int(a[i])
	y = int(b[i])
	if x > y:
		if x - y <= y + 10 - x:
			moves += x - y
		else:
			moves += y + 10 - x
	elif y - x <= x + 10 - y:
		moves += y - x
	else:
		moves += x + 10 - y
print(moves)


a = int(input())
b = str(input())
c = str(input())
cnt = 0
for i in range(a):
	x = int(b[i])
	y = int(c[i])
	cnt += min(abs(x - y), 10 - abs(x - y))
print(cnt)


n = int(input())
oriStatus = str(input())
lockPass = str(input())

def minDifference(a, b):
	a = int(a)
	b = int(b)
	(a, b) = (a, b) if a < b else (b, a)
	return b - a if b - a < a + 10 - b else a + 10 - b

def totalMoves(sum, index):
	return sum + index
sum = 0
k = len(oriStatus)
for i in range(0, k):
	sum = totalMoves(sum, minDifference(oriStatus[i], lockPass[i]))
print(sum)


n = int(input())
x = input()
y = input()
c = 0
for i in range(n):
	xx = int(x[i])
	yy = int(y[i])
	a = abs(xx - yy)
	b = 10 - a
	m = min(a, b)
	c = c + m
print(c)


n = input()
s1 = input()
s2 = input()
res = 0
for (idx, val) in enumerate(s1):
	i1 = int(val)
	i2 = int(s2[idx])
	res += min(abs(i1 - i2), abs(i1 - (10 + i2)), abs(10 + i1 - i2))
print(res)


input()
a = input()
b = input()
ret = 0
for i in range(len(a)):
	j = abs(ord(b[i]) - ord(a[i]))
	j = min(j, 10 - ord(a[i]) + ord(b[i]))
	j = min(j, 10 - ord(b[i]) + ord(a[i]))
	ret += j
print(ret)


x = int(input())
y = input()
z = input()
a = 0
output = 0
i = 0
while i < x:
	b = int(y[i])
	c = int(z[i])
	if b - c > 5:
		a = 10 + c - b
		output += a
	elif c - b > 5:
		a = 10 + b - c
		output += a
	elif b > c:
		a = b - c
		output += a
	elif b < c:
		a = c - b
		output += a
	i += 1
print(output)


n = int(input())
s = [int(i) for i in input()]
p = [int(i) for i in input()]
q = []
for i in range(n):
	small = min(max(s[i], p[i]) - min(s[i], p[i]), 10 + min(s[i], p[i]) - max(s[i], p[i]))
	q.append(small)
print(sum(q))


n = int(input())
s = [int(k) for k in input()]
s2 = [int(k) for k in input()]
t = 0
for i in range(n):
	t += min((s[i] - s2[i]) % 10, (10 - (s[i] - s2[i])) % 10)
print(t)


n = int(input())
L = list(input())
Need = list(input())
L = [int(i) for i in L]
Need = [int(i) for i in Need]
result = 0
for i in range(n):
	if L[i] != Need[i]:
		var1 = abs(L[i] - Need[i])
		var2 = min(L[i], Need[i]) + 1
		var2 += 9 - max(L[i], Need[i])
		result += min(var1, var2)
print(result)


def f(x, y):
	return min(x - y, 10 - x + y)
t = int(input())
s1 = input()
s2 = input()
count = 0
for i in range(t):
	n1 = int(s1[i])
	n2 = int(s2[i])
	if n1 > n2:
		count += f(n1, n2)
	else:
		count += f(n2, n1)
print(count)


a = int(input())
b = input()
c = input()
tm = 0

def move_calc(x, y):
	z = abs(x - y)
	if z > 5:
		return 10 - z
	else:
		return z
for i in range(a):
	l = move_calc(int(b[i]), int(c[i]))
	tm += l
print(tm)


def find_min_steps(a, b):
	(frm, to) = (min(a, b), max(a, b))
	order = list('01234567890123456789')
	frwrd_rotation = abs(order.index(frm) - order.index(to))
	order.remove(frm)
	bckwrd_rotation = abs(order.index(frm) - order.index(to))
	return min(frwrd_rotation, bckwrd_rotation)
n = int(input())
old_psswd = input()
new_psswd = input()
print(sum([find_min_steps(old_psswd[i], new_psswd[i]) for i in range(n)]))


input()
ans = 0
for (a, b) in zip(input(), input()):
	diff = abs(int(a) - int(b))
	ans += min(10 - diff, diff)
print(ans)


(n, org, open) = (int(input()), int(input()), int(input()))
moves = 0
for i in range(n):
	(dig1, dig2) = (org % 10, open % 10)
	diff = abs(dig1 - dig2)
	moves += min(diff, 10 - diff)
	(org, open) = (org // 10, open // 10)
print(moves)


n = int(input())
a = input()
b = input()
q = 0
d = 0
e = 0
f = 0
g = 0
for j in range(0, n):
	if int(a[j]) > int(b[j]):
		if int(a[j]) - int(b[j]) <= 4 and int(a[j]) - int(b[j]) > 0:
			g = int(a[j]) - int(b[j]) + g
		elif int(a[j]) - int(b[j]) > 4:
			d = 10 - int(a[j]) + int(b[j]) + d
	elif int(b[j]) - int(a[j]) <= 4 and int(b[j]) - int(a[j]) > 0:
		e = int(b[j]) - int(a[j]) + e
	elif int(b[j]) - int(a[j]) > 4:
		f = 10 - int(b[j]) + int(a[j]) + f
q = g + d + e + f
print(q)


__author__ = 'Jamey Sparreboom'
disks = eval(input())
orig_state = input()
combination = input()
res = 0
for disk in range(disks):
	if int(orig_state[disk]) < int(combination[disk]):
		res += min(abs(int(orig_state[disk]) - int(combination[disk])), abs(int(combination[disk]) - (int(orig_state[disk]) + 10)))
	elif int(orig_state[disk]) > int(combination[disk]):
		res += min(abs(int(combination[disk]) - int(orig_state[disk])), abs(int(orig_state[disk]) - (int(combination[disk]) + 10)))
print(res)


n = int(input(''))
x = input('')
y = input('')
xList = []
yList = []
for i in range(len(x)):
	xList.append(int(x[i]))
	yList.append(int(y[i]))
tot = 0
for i in range(len(xList)):
	if abs(xList[i] - yList[i]) < 10 - abs(xList[i] - yList[i]):
		tot += abs(xList[i] - yList[i])
	else:
		tot += 10 - abs(xList[i] - yList[i])
print(tot)


n = int(input())
a = list(input())
b = list(input())
sum = 0
for i in range(n):
	c = abs(int(a[i]) - int(b[i]))
	sum += min(c, 10 - c)
print(sum)


def answer():
	n = int(input())
	a = list(input())
	a = [int(x) for x in a]
	b = list(input())
	b = [int(x) for x in b]
	i = 0
	ans = 0
	while i < len(a):
		ans += min(abs(a[i] - b[i]), abs(10 - a[i] + b[i]), abs(-10 - a[i] + b[i]))
		i += 1
	return ans
print(answer())


class Solution(object):

	def getMinimumMoves(self, arr1, arr2, n):
		MAX_STEPS = 10
		count = 0
		for i in range(n):
			elem1 = int(arr1[i])
			elem2 = int(arr2[i])
			diff = abs(elem1 - elem2)
			diff = MAX_STEPS - diff if diff > MAX_STEPS / 2 else diff
			count += diff
		return count

def read_input():
	return [x for x in input().split()]
n = int(read_input()[0])
arr1 = read_input()[0]
arr2 = read_input()[0]
sol = Solution()
result = sol.getMinimumMoves(arr1, arr2, n)
print(result)


loc_len = int(input())
loc_state = input()
loc_key = input()
state = [int(i) for i in loc_state]
key = [int(i) for i in loc_key]
takes = 0
for i in range(loc_len):
	diff = abs(state[i] - key[i])
	if diff > 5:
		diff = 10 - diff
	takes += diff
print(takes)


n = int(input())
a = input()
a = [int(x) for x in a]
b = input()
b = [int(x) for x in b]
s = 0
for i in range(len(a)):
	if a[i] < b[i]:
		pass
	else:
		t = a[i]
		a[i] = b[i]
		b[i] = t
	if abs(a[i] + 10 - b[i]) < abs(a[i] - b[i]):
		s += abs(a[i] + 10 - b[i])
	else:
		s += abs(a[i] - b[i])
print(s)


import sys
import math

def main():
	n = int(sys.stdin.readline().strip())
	s1 = sys.stdin.readline().strip()
	s2 = sys.stdin.readline().strip()
	res = 0
	for i in range(n):
		k = abs(int(s1[i]) - int(s2[i]))
		if k > 5:
			k = 10 - k
		res += k
	print(res)
main()


n = int(input())
o = input()
c = input()
l = list(range(0, 10))
r = list(l)
r.reverse()
m = 0
for i in range(n):
	(a, b) = (int(o[i]), int(c[i]))
	p1 = abs(a - b)
	if a >= 0 and a < 5:
		p2 = a - l[0] + (r.index(b) + 1)
	else:
		p2 = abs(a - r[0]) + (l.index(b) + 1)
	m += min(p1, p2)
print(m)


n = int(input())
s1 = input()
s2 = input()
suma = 0
for i in range(n):
	x = int(s1[i])
	y = int(s2[i])
	suma += min(abs(x - y), min(abs(x - 9) + y + 1, x + 1 + abs(y - 9)))
print(suma)


(n, s, t) = (int(input()), input(), input())
ans = 0
for i in range(n):
	(x, y) = (max(int(s[i]), int(t[i])), min(int(s[i]), int(t[i])))
	ans += min(x - y, 10 + y - x)
print(ans)


n = int(input())
s1 = input()
s2 = input()
k = 0
for i in range(n):
	x1 = int(s1[i])
	x2 = int(s2[i])
	if x2 >= x1:
		c = x2 - x1
		if c <= 10 - c:
			k += c
		else:
			k += 10 - c
	else:
		c = x1 - x2
		if c <= 10 - c:
			k += c
		else:
			k += 10 - c
print(k)


_ = input()
source = list(map(int, input().strip()))
target = list(map(int, input().strip()))
sum_out = 0
for x in range(len(source)):
	sum_out += min(abs(source[x] - target[x]), 10 - abs(source[x] - target[x]))
print(sum_out)


x = int(input())
key1 = input()
key2 = input()
moves = 0
if len(key1) and len(key2) == x:
	lst_key1 = []
	lst_key2 = []
	for i in key1:
		lst_key1.append(int(i))
	for i in key2:
		lst_key2.append(int(i))
	for i in range(len(key1)):
		moves1 = 10 + lst_key1[i] - lst_key2[i]
		moves2 = lst_key2[i] - lst_key1[i]
		if moves1 > 10:
			moves1 = 10 + lst_key2[i] - lst_key1[i]
		if moves2 < 0:
			moves2 = lst_key1[i] - lst_key2[i]
		if moves1 >= moves2:
			moves += moves2
		elif moves1 < moves2:
			moves += moves1
print(moves)


digit = int(input())
originalState = input()
combination = input()
diffl = []
ol = [x for x in originalState]
cl = [y for y in combination]
for i in range(len(ol)):
	diff = abs(int(ol[i]) - int(cl[i]))
	if diff > 5:
		diff = 10 - diff
		diffl.append(diff)
	else:
		diffl.append(diff)
summ = 0
for l in diffl:
	summ += l
print(f'{summ}')


num = int(input())
init = input()
comb = input()
i = 0
xsum = 0
ii = int(init[i])
cc = int(comb[i])
while i < num:
	ii = int(init[i])
	cc = int(comb[i])
	xsum += min(abs(ii - cc), 10 - abs(ii - cc))
	i += 1
print(xsum)


n = int(input())
a = input()
b = input()
moves = 0
for i in range(n):
	temp = abs(int(a[i]) - int(b[i]))
	if temp > 5:
		moves += 10 - temp
	else:
		moves += temp
print(moves)


def lee(disk, n):
	a = input()
	for i in range(n):
		disk.append(int(a[i]))
n = int(input())
disk1 = list()
disk2 = list()
lee(disk1, n)
lee(disk2, n)
d = 0
for i in range(n):
	if disk1[i] > disk2[i]:
		d1 = disk1[i] - disk2[i]
		d2 = disk2[i] + 10 - disk1[i]
	elif disk1[i] < disk2[i]:
		d1 = disk1[i] + 10 - disk2[i]
		d2 = disk2[i] - disk1[i]
	elif disk1[i] == disk2[i]:
		d1 = d2 = 0
	if d1 < d2:
		d += d1
	else:
		d += d2
print(d)


j = 0
m = 0
n = int(input())
a = input()
b = input()
a = [int(i) for i in str(a)]
b = [int(i) for i in str(b)]
for j in range(n):
	m = m + min(abs(a[j] - b[j]), 10 - abs(a[j] - b[j]))
print(m)


n = int(input())
a1 = input()
a2 = input()
k = 0
for i in range(n):
	g1 = int(a1[i])
	g2 = int(a2[i])
	m = min(g1, g2)
	x = max(g1, g2)
	k += min(x - m, m + 10 - x)
print(k)


n = int(input())
s = [int(i) for i in input()]
d = [int(i) for i in input()]
c = 0
for i in range(n):
	if abs(s[i] - d[i]) <= 5:
		c += abs(s[i] - d[i])
	else:
		c += 10 - abs(s[i] - d[i])
print(c)


a = int(input())
b = input()
c = input()
j = 0
i = 0
while i < a:
	x = abs(int(b[i]) - int(c[i]))
	y = 10 - x
	j += min(x, y)
	i += 1
print(j)


n = int(input())
original_state = input()
required_state = input()
count = 0
for i in range(0, len(original_state)):
	backward_loop = 9 - int(required_state[i]) + int(original_state[i]) + 1
	forward_loop = 9 - int(original_state[i]) + int(required_state[i]) + 1
	forward = abs(int(original_state[i]) - int(required_state[i]))
	if forward <= backward_loop and forward <= forward_loop:
		count += forward
	elif backward_loop < forward_loop and backward_loop < forward:
		count += backward_loop
	else:
		count += forward_loop
print(count)


w = int(input())
y = input()
p = list(map(int, str(y)))
z = input()
q = list(map(int, str(z)))
s = 0
for i in range(w):
	t = abs(p[i] - q[i])
	if t > 5:
		s += 10 + min(p[i], q[i]) - max(p[i], q[i])
	else:
		s += t
print(s)


n = int(input())
current = str(input())
new = str(input())
ans = 0
j = 0
while j < len(current):
	temp = abs(int(current[j]) - int(new[j]))
	if temp > 5:
		temp = 10 - temp
	ans = ans + temp
	j = j + 1
print(ans)


o = int(input())
l1 = str(input())
l2 = str(input())
x = 0
for i in range(0, len(l1)):
	if abs(ord(l1[i]) - ord(l2[i])) <= 5:
		x += abs(ord(l1[i]) - ord(l2[i]))
	else:
		z = abs(ord(l1[i]) - ord(l2[i]))
		z = z - 5
		z = 5 - z
		x += z
print(x)


t = int(input())
a = input()
b = input()
sum = 0
for i in range(t):
	(m, n) = (float(a[i]), float(b[i]))
	if abs(m - n) >= (m + n) / 2:
		sum += min(abs(m - n), 9 - max(m, n) + min(m, n) + 1)
	else:
		sum += abs(m - n)
print(int(sum))


def main(no_of_disk, original_state, scrooge_pattern):
	moves = 0
	for i in range(no_of_disk):
		moves += min(abs(original_state[i] - scrooge_pattern[i]), 10 - abs(original_state[i] - scrooge_pattern[i]))
	print(moves)
no_of_disk = int(input())
original_state = list(map(int, input().replace('', ' ').split()))
scrooge_pattern = list(map(int, input().replace('', ' ').split()))
main(no_of_disk, original_state, scrooge_pattern)


s = int(input())
q = input()
ans = input()
sum = 0
for i in range(0, len(q)):
	c = int(ans[i])
	ch = int(q[i])
	backward = 10 - abs(ch - c)
	forward = abs(ch - c)
	n = min(backward, forward)
	c = ch
	sum += n
print(sum)


n = int(input())
k = list(map(int, input()))
pas = list(map(int, input()))
count = 0
for i in range(n):
	count = count + min(abs(k[i] - pas[i]), 10 - abs(k[i] - pas[i]))
print(count)


a = int(input())
st1 = input()
st2 = input()
s1 = []
s2 = []
for i in st1:
	s1.append(i)
for i in st2:
	s2.append(i)
res = 0
for i in range(a):
	s1[i] = int(s1[i])
	s2[i] = int(s2[i])
	k = abs(s2[i] - s1[i])
	if k >= 5:
		k = int(10 - k)
		res += k
	else:
		res += k
print(res)


n = int(input())
p = list(input())
q = list(input())
count = 0
for i in range(n):
	(y, m) = (int(p[i]), int(q[i]))
	t = abs(y - m)
	if t <= 5:
		count += t
	else:
		count += 10 - max(y, m) + min(y, m)
print(count)


def m(a, b):
	k = abs(a - b)
	return min(k, 10 - k)
input()
print(sum((m(int(d1), int(d2)) for (d1, d2) in zip(input(), input()))))


n = int(input())
a = input()
b = input()
moves = 0
for (i, j) in zip(a, b):
	x = int(i)
	y = int(j)
	curr = min(abs(x - y), abs(x) + abs(10 - y), 10 - x + y)
	moves += curr
print(moves)


n = int(input())
s = 0
a = list(str(input()))
b = list(str(input()))
for _ in range(n):
	s += min(abs(int(a[_]) - int(b[_])), 10 - int(a[_]) + int(b[_]), 10 - int(b[_]) + int(a[_]))
print(s)


test = int(input())
l0 = list(map(int, input()))
l1 = list(map(int, input()))
s = 0
for i in range(test):
	ma = max(l0[i], l1[i])
	mi = min(l0[i], l1[i])
	d0 = mi + 10 - ma
	d1 = abs(mi - ma)
	s += min(d0, d1)
print(s)


nStr = input()
originStr = input()
finalStr = input()
n = int(nStr)
origin = int(originStr)
final = int(finalStr)
total = 0
for i in range(n):
	bit_origin = origin % 10
	origin = origin // 10
	bit_final = final % 10
	final = final // 10
	distance = abs(bit_origin - bit_final)
	if distance > 5:
		distance = 10 - distance
	total = total + distance
print(total)


n = int(input())
s = input()
code = input()
res = 0
for i in range(n):
	k = abs(int(s[i]) - int(code[i]))
	res += min(k, 10 - k)
print(res)


def combLock(n, a, b):
	s = 0
	for i in range(n):
		x = abs(a[i] - b[i])
		if x > 5:
			s += 10 % x
		else:
			s += x
	return s
n = int(input())
a = list(map(int, list(input())))
b = list(map(int, list(input())))
print(combLock(n, a, b))


num = int(input())
digits = [int(x) for x in input()]
ans = [int(x) for x in input()]
out = 0
for (index, digit) in enumerate(digits):
	dif = abs(digit - ans[index])
	if dif > 5:
		out += 10 - dif
	else:
		out += dif
print(out)


__author__ = 'artyom'

def main():
	read(0)
	(a, c) = (map(sorted, zip(read(3), read(3))), 0)
	for (x, y) in a:
		c += min(y - x, 10 - y + x)
	return c

def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return int(inputs)
	if mode == 3:
		return map(int, list(inputs))

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')
write(main())


n = int(input())
e = input()
f = input()
c = []
d = []
for i in range(len(e)):
	c.append(int(e[i]))
for i in range(len(f)):
	d.append(int(f[i]))
result = 0
x = 0
y = 0
for i in range(len(c)):
	if c[i] < d[i]:
		x = 10 + c[i] - d[i]
	else:
		x = c[i] - d[i]
	if x < 0:
		x = -x
	if d[i] < c[i]:
		y = 10 + d[i] - c[i]
	else:
		y = d[i] - c[i]
	if y < 0:
		y = -y
	if x > y:
		result += y
	else:
		result += x
print(result)


n = int(input())
a = input()
b = input()
count = 0
for i in range(n):
	a1 = int(a[i])
	b1 = int(b[i])
	a2 = min(a1, b1)
	b2 = max(a1, b1)
	count = count + min(abs(a1 - b1), abs(a2 - b2 + 10))
print(count)


leng = int(input())
perv = input()
vtor = input()
sum = 0
for i in range(leng):
	iy = int(perv[i])
	jy = int(vtor[i])
	if abs(iy - jy) > 5:
		sum += 10 - abs(iy - jy)
	else:
		sum += abs(iy - jy)
print(sum)


input()
x = 0
for a in [[int(x), int(y)] for (x, y) in zip(input(), input())]:
	(i, j) = sorted(a)
	x += min(j - i, 10 - j + i)
print(x)


def m(x, y):
	x = int(x)
	y = int(y)
	p = max(x, y)
	q = min(x, y)
	x = p - q
	y = 9 - p + q + 1
	if x < y:
		return x
	else:
		return y
n = int(input(''))
a = list(input(''))
b = list(input(''))
s = 0
for i in range(0, n, 1):
	s = s + m(a[i], b[i])
print(s)


num_of_digits = int(input())
source = list(input())
dest = list(input())
minimum_moves = 0
for i in range(0, num_of_digits):
	f_moves = 0
	b_moves = 0
	if int(source[i]) > int(dest[i]):
		f_moves = int(source[i]) - int(dest[i])
		b_moves = 10 - f_moves
	else:
		f_moves = int(dest[i]) - int(source[i])
		b_moves = 10 - f_moves
	minimum_moves += b_moves if f_moves > b_moves else f_moves
print(minimum_moves)


n = int(input())
l1 = list(input())
l2 = list(input())

def distance(a, b):
	return min(abs(a - b), 10 - abs(a - b))
total = 0
for i in range(n):
	total += distance(int(l1[i]), int(l2[i]))
print(total)


n = int(input())
lock = input()
answer = input()
l = []
for _ in range(n):
	diff = abs(int(answer[_]) - int(lock[_]))
	if diff > 5:
		diff -= 10
	l.append(abs(diff))
print(sum(l))


n = int(input())
start = input()
combin = input()
k = 0
for i in range(0, n):
	if abs(int(start[i]) - int(combin[i])) >= 5:
		k = k + 1
		if abs(0 - int(start[i])) > abs(9 - int(start[i])):
			k = k + abs(9 - int(start[i]))
		if abs(0 - int(start[i])) < abs(9 - int(start[i])):
			k = k + abs(0 - int(start[i]))
		if abs(0 - int(combin[i])) > abs(9 - int(combin[i])):
			k = k + abs(9 - int(combin[i]))
		if abs(0 - int(combin[i])) < abs(9 - int(combin[i])):
			k = k + abs(0 - int(combin[i]))
	else:
		k = k + abs(int(start[i]) - int(combin[i]))
print(k)


n = int(input())
start_input = input()
start = [int(i) for i in start_input]
end_input = input()
end = [int(i) for i in end_input]
x = []
for i in range(n):
	if abs(start[i] - end[i]) < 6:
		x.append(abs(start[i] - end[i]))
	elif abs(start[i] - end[i]) >= 6:
		x.append(10 - abs(start[i] - end[i]))
print(sum(x))


n = int(input())
s1 = input()
s2 = input()
s = 0
for i in range(n):
	(a, b) = (max(int(s1[i]), int(s2[i])), min(int(s1[i]), int(s2[i])))
	s += min(a - b, b + 10 - a)
print(s)


n = int(input())
action = 0
a = [int(x) for x in list(input())]
b = [int(x) for x in list(input())]
for i in range(n):
	action += min(abs(b[i] - a[i]), 10 - abs(b[i] - a[i]))
print(action)


n = int(input())
s = [int(x) for x in input()]
d = [int(x) for x in input()]
c = 0
for i in range(n):
	m = min(s[i], d[i])
	M = max(s[i], d[i])
	c += min(M - m, m + 10 - M)
print(c)


n = int(input())
no1 = list(input())
no2 = list(input())
total = 0
for i in range(n):
	a = int(no1[i])
	b = int(no2[i])
	if a > b:
		total += min(a - b, b + 10 - a)
	else:
		total += min(b - a, a + 10 - b)
print(total)


n = int(input())
x1 = [int(i) for i in input()]
x2 = [int(i) for i in input()]
s = 0
for i in range(n):
	if max(x1[i], x2[i]) - min(x1[i], x2[i]) > 5:
		s = s + min(x1[i], x2[i]) + 10 - max(x1[i], x2[i])
	else:
		s = s + max(x1[i], x2[i]) - min(x1[i], x2[i])
print(s)


n = int(input())
x = str(input())
l = str(input())
sum = int(0)
for i in range(n):
	a = max(int(x[i]), int(l[i])) - min(int(x[i]), int(l[i]))
	b = 10 - a
	sum += min(a, b)
print(sum)


n = int(input())
ans = 0
s = input()
t = input()
for i in range(n):
	d = abs(int(s[i]) - int(t[i]))
	ans += min(d, 10 - d)
print(ans)


n = int(input())
pre = list(input())
lat = list(input())
step = 0

def con(i):
	num1 = int(pre[i])
	num2 = int(lat[i])
	l1 = abs(num1 - num2)
	l2 = abs(10 - abs(num1 - num2))
	if l1 < l2:
		return l1
	else:
		return l2
for i in range(n):
	step += con(i)
print(step)


n = int(input())
num1 = str(input())
num2 = str(input())
count = 0
for i in range(n):
	steps = abs(int(num1[i]) - int(num2[i]))
	if steps <= 5:
		count += steps
	else:
		count += 10 - steps
print(count)


n = int(input())
a = list(input())
b = list(input())
count = 0
for i in range(n):
	if int(a[i]) > int(b[i]):
		if int(a[i]) - int(b[i]) > 10 - int(a[i]) + int(b[i]):
			count += 10 - int(a[i]) + int(b[i])
		else:
			count += int(a[i]) - int(b[i])
	elif int(b[i]) - int(a[i]) > 10 - int(b[i]) + int(a[i]):
		count += 10 - int(b[i]) + int(a[i])
	else:
		count += int(b[i]) - int(a[i])
print(count)


n = int(input())
a = input()
b = input()
c = []
d = []
sum = 0
for i in a:
	c.append(int(i))
for i in b:
	d.append(int(i))
for i in range(n):
	ans = max(c[i], d[i]) - min(c[i], d[i])
	if ans > 5:
		ans = 10 - ans
	sum = ans + sum
print(sum)


n = int(input())
s1 = input()
s2 = input()
ans = 0
for i in range(n):
	a = int(s1[i])
	b = int(s2[i])
	zam = abs(a - b)
	if zam > 5:
		zam = 10 - zam
	ans += zam
print(ans)


n = int(input())
act = input()
cod = input()
s = 0
for i in range(len(act)):
	s += min(abs(int(act[i]) - int(cod[i])), abs(int(act[i]) + 10 - int(cod[i])), abs(-int(act[i]) + 10 + int(cod[i])))
print(s)


n = int(input())
a = int(input())
b = int(input())
ans = 0
while n > 0:
	x = a % 10
	y = b % 10
	if x > y:
		ans = ans + min(x - y, 10 - x + y)
	else:
		ans = ans + min(y - x, 10 - y + x)
	n -= 1
	a = a // 10
	b = b // 10
print(ans)


movement = 0
n = int(input())
a = input()
b = input()
for i in range(n):
	kmin = min(abs(10 + int(a[i]) - int(b[i])), abs(10 + int(b[i]) - int(a[i])))
	if abs(int(a[i]) - int(b[i])) < kmin:
		movement += abs(int(a[i]) - int(b[i]))
	else:
		movement += kmin
print(movement)


n = int(input())
s = input()
s1 = input()
result = 0
for i in range(0, n):
	result = result + min(abs(int(s[i:i + 1]) - int(s1[i:i + 1])), 10 - int(s[i:i + 1]) + int(s1[i:i + 1]), 10 - int(s1[i:i + 1]) + int(s[i:i + 1]))
print(result)


n = int(input())
x = input()
y = input()
count = 0
for i in range(n):
	if abs(int(x[i]) - int(y[i])) >= 5:
		count = count + 10 - abs(int(x[i]) - int(y[i]))
	else:
		count = count + abs(int(x[i]) - int(y[i]))
print(count)


n = int(input())
a = input()
b = input()
asn = 0
for i in range(n):
	p = int(a[i])
	q = int(b[i])
	c = abs(p - q)
	temp = min(p, q) + 10
	d = abs(temp - max(p, q))
	asn += min(c, d)
print(asn)


n = int(input())
a = list(input())
b = list(input())
c = 0
for i in range(n):
	x = int(a[i]) - int(b[i])
	y = int(b[i]) - int(a[i])
	if x >= 0 and x <= 5:
		c = c + x
	elif x >= 0 and x > 5:
		c = c + 10 - x
	elif y >= 0 and y <= 5:
		c = c + y
	elif y >= 0 and y > 5:
		c = c + 10 - y
print(c)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest, _heapify_max, _heapreplace_max
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = int(data())
(s, t) = (data(), data())
answer = 0
for i in range(n):
	answer += min(abs(int(s[i]) - int(t[i])), 10 - max(int(s[i]), int(t[i])) + min(int(s[i]), int(t[i])))
out(answer)


n = int(input())
num1 = input()
num2 = input()
num = 0
for i in range(n):
	if abs(int(num1[i]) - int(num2[i])) > 5:
		num += 10 - abs(int(num1[i]) - int(num2[i]))
	else:
		num += abs(int(num1[i]) - int(num2[i]))
print(num)


g = lambda : map(int, list(input()))
n = int(input())
a1 = g()
a2 = g()
print(sum([min(abs(a - b), 9 - max(a, b) + min(a, b) + 1) for (a, b) in zip(a1, a2)]))


n = int(input())
original_state = input()
combination = input()
actions = 0
for i in range(n):
	actions += min(abs(int(original_state[i]) - int(combination[i])), 10 - abs(int(original_state[i]) - int(combination[i])))
print(actions)


a = int(input())
b = list(input())
c = list(input())
n1 = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
d = 0
for i in range(a):
	i1 = n1.index(b[i])
	i2 = n1.index(c[i])
	si = abs(i2 - i1)
	if si < 10 - si:
		d += si
	elif si > 10 - si:
		d += 10 - si
	elif si == 10 - si:
		d += 5
print(d)


n = input()
old_mima = input()
new_mima = input()
number = 0
for i in range(int(n)):
	chazhi = abs(int(old_mima[i]) - int(new_mima[i]))
	if chazhi <= 5:
		number += chazhi
	else:
		number += 10 - chazhi
print(number)


x = int(input())
y = input()
z = input()
yy = int(y)
zz = int(z)
a = list(y)
b = list(z)
c = 0
for i in range(x):
	c += min(10 - abs(int(a[i]) - int(b[i])), abs(int(a[i]) - int(b[i])))
print(c)


def mod(a, b):
	if a >= b:
		return a - b
	else:
		return b - a

def ans(a, b):
	if a > b:
		m = a
		n = b
	else:
		m = b
		n = a
	k = 10 - m
	k += n - 0
	if mod(a, b) < k:
		return mod(a, b)
	else:
		return k
n = int(input())
x = input()
y = input()
moves = 0
for i in range(0, n):
	moves += ans(int(x[i]), int(y[i]))
print(moves)


n = int(input())
p = int(input())
q = int(input())
total = 0
for i in range(0, n):
	a = p % 10
	b = q % 10
	if a >= b:
		x = a - b
		y = b + 10 - a
	else:
		x = b - a
		y = a + 10 - b
	if x >= y:
		total = total + y
	else:
		total = total + x
	p = p // 10
	q = q // 10
print(total)


nb_disks = int(input())
original_state = input()
combination = input()
nb_moves = 0
for x in range(nb_disks):
	c = int(combination[x])
	o = int(original_state[x])
	nb_moves += min(abs(c - o), 10 - abs(c - o))
print(nb_moves)


n = int(input())
org = input()
com = input()
ans = 0
for i in range(n):
	d = abs(int(com[i]) - int(org[i]))
	if d > 5:
		d = 10 - d
	ans += d
print(ans)


a = int(input())
b = input()
c = input()
d = 0
for i in range(a):
	e = int(b[i])
	f = int(c[i])
	d += min(abs(e - f), 10 - abs(e - f))
print(d)


n = int(input())
s = input()
o = input()
f = '01234567890123456789'
ans = 0
for i in range(n):
	si = int(s[i])
	oi = int(o[i])
	ans = ans + min(abs(si - oi), abs(si - (10 + oi)), abs(si + 10 - oi))
print(ans)


n = int(input())
a = list(input())
b = list(input())
anse = 0
for i in range(n):
	anse += min(abs(int(a[i]) - int(b[i])), 10 - abs(int(a[i]) - int(b[i])))
print(anse)


a = int(input())
b = int(input())
c = int(input())
kol = 0
for i in range(a):
	v = b % 10
	g = c % 10
	if abs(v - g) > 5:
		kol += 10 - abs(v - g)
	else:
		kol += abs(v - g)
	b = b // 10
	c = c // 10
print(kol)


from sys import stdin, stdout, exit as sys_ret
(f_input, f_print, f_flush) = (stdin.readline, stdout.write, stdout.flush)
(numbers, actions) = (int(f_input()), 0)
(number1, number2) = (f_input().replace('\n', ''), f_input().replace('\n', ''))
for i in range(numbers):
	(plus, minus) = (0, 0)
	need = int(number2[i])
	plus_res = minus_res = int(number1[i])
	while plus_res != need and minus_res != need:
		plus_res += 1
		minus_res -= 1
		plus += 1
		minus += 1
		if minus_res == -1:
			minus_res = 9
		if plus_res == 10:
			plus_res = 0
	actions += min(plus, minus)
f_print(str(actions))


n = int(input())
p = input()
d = input()
k = 0
for i in range(n):
	a = int(p[i])
	b = int(d[i])
	k = k + min((10 + a - b) % 10, (10 + b - a) % 10)
print(k)


disks = int(input())
original = input()
correct = input()
if len(original) == disks and len(correct) == disks:
	moves = 0
	for d in range(disks):
		diff = abs(int(original[d]) - int(correct[d]))
		if diff > 5:
			diff = 10 - diff
		moves += diff
	print(moves)
else:
	print('wrong size input, check your input!')


n = int(input())
original = input()
key = input()
turns = 0
for i in range(n):
	dif = abs(int(original[i]) - int(key[i]))
	turns += min(dif, 10 - dif)
print(turns)


n = int(input())
a = input()
b = input()
i = 0
j = 0
while j < len(a):
	if abs(int(a[j]) - int(b[j])) > 5:
		i += 10 - abs(int(a[j]) - int(b[j]))
	else:
		i += abs(int(a[j]) - int(b[j]))
	j += 1
print(i)


n = input()
str1 = input()
str2 = input()
ans = 0
for i in range(int(n)):
	num = abs(int(str1[i]) - int(str2[i]))
	ans += min(num, 10 - num)
print(ans)


import sys

def Ints():
	return map(int, sys.stdin.readline().strip().split())

def Strs():
	return map(str, sys.stdin.readline().strip().split())

def Array():
	return list(map(int, sys.stdin.readline().strip().split()))

def Str():
	return sys.stdin.readline().strip()

def Int():
	return int(sys.stdin.readline().strip())

def MOD():
	return 1000000007
n = Int()
s1 = Str()
s2 = Str()
res = 0
for i in range(n):
	a = abs(int(s1[i]) - int(s2[i]))
	b = 10 - int(s1[i]) + int(s2[i])
	c = 10 - int(s2[i]) + int(s1[i])
	res += min(a, b, c)
print(res)


n = int(input())
s = input()
d = input()
c = 0
for i in range(n):
	f = (int(s[i]) - int(d[i])) % 10
	c += min(f, 10 - f)
print(c)


t = int(input())
n = input()
ar = [int(i) for i in n]
m = input()
ar1 = [int(j) for j in m]
count = 0
for i in range(len(n)):
	if ar[i] > ar1[i]:
		count += min(ar[i] - ar1[i], 10 + ar1[i] - ar[i])
	elif ar[i] < ar1[i]:
		count += min(ar1[i] - ar[i], 10 + ar[i] - ar1[i])
	elif ar[i] == ar1[i]:
		pass
print(count)


n = int(input())
s = input()
t = input()
ans = 0
for i in range(n):
	a = int(s[i])
	b = int(t[i])
	c = min(abs(a - b), 10 - abs(a - b))
	ans += c
print(ans)


n = int(input())
l = [int(i) for i in list(input())]
m = [int(i) for i in list(input())]
summ = 0
for i in range(0, n):
	summ += min(abs(l[i] - m[i]), 10 - abs(l[i] - m[i]))
print(summ)


a = int(input())
b = input()
c = input()
d = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
k = []
for i in range(0, a):
	m = int(b[i]) - int(c[i])
	if abs(int(b[i]) - int(c[i])) > 5:
		m = 10 - abs(int(b[i]) - int(c[i]))
	k.append(m)
f = 0
for i in k:
	f = f + abs(i)
print(f)


n = int(input())
s1 = input().strip()
s2 = input().strip()
ans = 0
for (a1, a2) in zip(s1, s2):
	d1 = int(a1)
	d2 = int(a2)
	if d1 > d2:
		ans += min(d1 - d2, 10 - (d1 - d2))
	else:
		ans += min(d2 - d1, 10 - (d2 - d1))
print(ans)


n = int(input())
v = input()
x = input()
a = 0
for i in range(n):
	if abs(int(x[i]) - int(v[i])) < 10 - abs(int(x[i]) - int(v[i])):
		a += abs(int(x[i]) - int(v[i]))
	elif abs(int(x[i]) - int(v[i])) == 10 - abs(int(x[i]) - int(v[i])):
		a += abs(int(x[i]) - int(v[i]))
	else:
		a += 10 - abs(int(x[i]) - int(v[i]))
print(a)


n = int(input())
ch1 = input()
ch2 = input()
s = 0
for i in range(n):
	d = abs(int(ch1[i]) - int(ch2[i]))
	if d > 5:
		s += 10 - d
	else:
		s += d
print(s)


x = int(input())
emon = input()
mishu = input()
a = 0
for i in range(x):
	m = int(emon[i]) - int(mishu[i])
	k = int(mishu[i])
	l = int(emon[i])
	if k < l:
		n = 0
		n = k - 0
		n = 1 + n + 9 - l
	else:
		n = 0
		n = l - 0
		n = 1 + n + 9 - k
	if n < 0:
		n = n - 2 * n
	if m < 0:
		m = m - 2 * m
	if m > n:
		a = a + n
	else:
		a = a + m
print(a)


k = int(input())
c1 = input()
c2 = input()
s = 0
for (i, j) in zip(c1, c2):
	k = int(i) - int(j) if i > j else int(j) - int(i)
	k = k if k < 10 - k else 10 - k
	s += k
print(s)


n = int(input())
a = list(input())
b = list(input())
q = 0
for i in range(1, n + 1):
	s = abs(int(a[i - 1]) - int(b[i - 1]))
	m = 10 - s
	if s >= m:
		q = q + m
	else:
		q = q + s
print(q)


n = int(input())
ipt1 = input()
ipt2 = input()
counter = 0
for (i, val) in enumerate(ipt1):
	val1 = int(val)
	val2 = int(ipt2[i])
	counter += min(10 - max(val1, val2) + min(val1, val2), abs(val1 - val2))
print(counter)


def main():
	n = int(input())
	b = input()
	a = input()
	ans = 0
	for i in range(n):
		ans += min(abs(int(b[i]) - int(a[i])), 10 - abs(int(b[i]) - int(a[i])))
	print(ans)

def __starting_point():
	main()
__starting_point()


n = int(input())
x = int(input())
y = int(input())
a = b = c = 0
while x > 0 or y > 0:
	a = x % 10
	b = y % 10
	if (a - b) ** 2 <= 25:
		if a > b:
			c += a - b
		else:
			c += b - a
	elif a > b:
		c += 10 - (a - b)
	else:
		c += 10 - (b - a)
	x = x // 10
	y = y // 10
print(c)


def getMin(a, b):
	t = abs(b - a)
	return min(t, 10 - t)
n = int(input())
num = map(int, input())
target = map(int, input())
res = sum(map(getMin, num, target))
print(res)


import sys
from math import *
n = int(input())
(a, b) = (input(), input())
ans = 0
for i in range(n):
	cur = int(a[i])
	ok = int(b[i])
	cnt1 = 0
	cnt2 = 0
	while cur != ok:
		cur = (cur + 1) % 10
		cnt1 += 1
	cur = int(a[i])
	while cur != ok:
		if cur == 0:
			cur = 9
		else:
			cur -= 1
		cnt2 += 1
	ans += min(cnt1, cnt2)
print(ans)


n = int(input())
s = input()
t = input()
ans = 0
for (i, j) in zip(s, t):
	a = abs(int(i) - int(j))
	ans += min(a, 10 - a)
print(ans)


n = int(input())
original_digits = [int(i) for i in input()]
desired_digits = [int(i) for i in input()]
num_moves = 0
for (i, original_digit) in enumerate(original_digits):
	diff = abs(desired_digits[i] - original_digit)
	num_moves += 10 - diff if diff > 5 else diff
print(num_moves)


n = int(input())
a = input()
b = input()

def dist(a, b):
	if b > a:
		(a, b) = (b, a)
	return min(a - b, b + 10 - a)
f = 0
for i in range(n):
	f += dist(int(a[i]), int(b[i]))
print(f)


def get_number(s, c):
	return min([abs(s - c), 10 - abs(s - c)])
length = int(input())
start = map(int, list(input()))
code = map(int, list(input()))
print(sum([get_number(s, c) for (s, c) in zip(start, code)]))


n = int(input())
state = input()
pswd = input()
moves = 0
for i in range(n):
	a = int(state[i])
	b = int(pswd[i])
	if a == b:
		continue
	else:
		mx = max(a, b)
		mn = min(a, b)
		d = min(abs(a - b), 10 - mx + mn)
		moves += d
print(moves)


n = int(input())
og = input()
lk = input()
ans = 0
for i in range(0, n):
	if abs(int(lk[i]) - int(og[i])) <= 5:
		ans += abs(int(lk[i]) - int(og[i]))
	else:
		ans += 10 - abs(int(lk[i]) - int(og[i]))
print(ans)


n = int(input())
init = input()
comb = input()
action = 0
for i in range(n):
	if init[i] == comb[i]:
		continue
	elif int(init[i]) - int(comb[i]) > 5:
		action += 10 - int(init[i]) + int(comb[i])
	elif int(init[i]) - int(comb[i]) < -5:
		action += int(init[i]) + (10 - int(comb[i]))
	else:
		action += abs(int(init[i]) - int(comb[i]))
print(action)


import sys
from functools import reduce
lines = iter(sys.stdin.read().split('\n'))
n = int(next(lines))
key1 = list(next(lines))
key2 = list(next(lines))

def distance(k1, k2):
	(k1, k2) = (int(k1), int(k2))
	v = k1 - k2 if k1 >= k2 else k2 - k1
	return min(v, 10 - v)
print(reduce(lambda x, y: x + distance(*y), zip(key1, key2), 0))


__author__ = 'huash06'
import sys
import os
import datetime
import functools
import itertools
import collections
digits = int(input())
start = input()
end = input()
res = 0
for i in range(digits):
	ei = int(end[i])
	si = int(start[i])
	res += min(abs(ei - si), ei + si, si + 10 - ei, 10 - si + ei)
print(res)


n = int(input())
n1 = input()
n2 = input()
counter = 0
for i in range(len(n1)):
	r1 = int(n1[i])
	r2 = int(n2[i])
	maxi = max(r1, r2)
	mini = min(r1, r2)
	r1 = maxi - mini
	r2 = 0
	while maxi != mini:
		if maxi == 10:
			maxi = 0
			continue
		r2 += 1
		maxi += 1
	counter += min(r1, r2)
print(counter)


import math
n = int(input())
n1 = input()
n2 = input()
result = 0
for (s1, s2) in zip(n1, n2):
	result += min(abs(int(s1) - int(s2)), abs(int(s1) + 10 - int(s2)), abs(int(s2) + 10 - int(s1)))
print(result)


n = int(input())
l = list(input())
m = list(input())
count = 0
for i in range(n):
	a = int(l[i])
	b = int(m[i])
	x = abs(b - a)
	f = max(a, b)
	g = min(a, b)
	j = 10 - f
	z = j + g
	c = min(z, x)
	count += c
print(count)


def saad(x, y):
	(x, y) = (int(x), int(y))
	if x > y:
		t = x
		x = y
		y = t
	return min(y - x, 10 - y + x)
s = int(input())
t = input()
d = input()
ans = 0
for i in range(s):
	ans += saad(t[i], d[i])
print(ans)


n = int(input())
ar = input()
ar1 = input()
arr = []
arr2 = []
for i in ar:
	arr.append(int(i))
for i in ar1:
	arr2.append(int(i))
count = 0
for i in range(n):
	mins = 0
	if arr[i] < arr2[i]:
		k = arr2[i] - arr[i]
		k3 = arr[i] + 10 - arr2[i]
		count += min(k, k3)
	elif arr[i] > arr2[i]:
		k = arr[i] - arr2[i]
		k3 = arr2[i] + 10 - arr[i]
		count += min(k, k3)
print(count)


n = int(input())
s1 = list(input())
s2 = list(input())
k = 0
for i in range(n):
	(s1[i], s2[i]) = (int(s1[i]), int(s2[i]))
	if s1[i] - s2[i] <= 4 and s1[i] - s2[i] >= 0:
		k += s1[i] - s2[i]
	elif abs(s1[i] - s2[i]) <= 4:
		k += abs(s1[i] - s2[i])
	elif s1[i] - s2[i] >= 5:
		k += 10 - s1[i] + s2[i]
	elif abs(s1[i] - s2[i]) >= 5:
		k += 10 - s2[i] + s1[i]
print(k)


from sys import stdin
_input = stdin.readline
(_max, _int, _str, _min, _range, _abs) = (max, int, str, min, range, abs)

def solution():
	n = _int(_input())
	current = _input().rstrip('\n')
	nead = _input().rstrip('\n')
	ans = 0
	for i in _range(n):
		a = _int(current[i])
		b = _int(nead[i])
		ans += _min(_abs(a - b), _abs(_min(a, b) + 10 - _max(a, b)))
	print(ans)
solution()


input()
print(sum((min(abs(ord(x) - ord(y)), 10 - abs(ord(x) - ord(y))) for (x, y) in zip(input(), input()))))


n = int(input())
a = input()
b = input()
s = 0
for i in range(n):
	k = min(abs(int(a[i]) - int(b[i])), abs(9 - int(a[i]) + int(b[i]) + 1), abs(9 - int(b[i]) + int(a[i]) + 1))
	s += k
print(s)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt, gcd

def ip():
	return int(sys.stdin.readline())

def sip():
	return sys.stdin.readline()

def mip():
	return map(int, sys.stdin.readline().split())

def mips():
	return map(str, sys.stdin.readline().split())

def lip():
	return list(map(int, sys.stdin.readline().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.insert(i, arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
n = ip()
cur = sip()
fin = sip()
p = 0
for i in range(n):
	x = min(int(cur[i]), int(fin[i]))
	y = max(int(cur[i]), int(fin[i]))
	p += min(abs(int(fin[i]) - int(cur[i])), abs(10 - y + x))
print(p)


n = int(input().strip())
n1 = str(input().strip())
n2 = str(input().strip())
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
r = 0
for i in range(n):
	s1 = abs(int(n1[i]) - int(n2[i]))
	s2 = abs(int(n1[i]) - 0) + abs(int(n2[i]) - 9) + 1
	s3 = abs(int(n2[i]) - 0) + abs(int(n1[i]) - 9) + 1
	r += min(s1, s2, s3)
print(r)


n = int(input())
original_state = input()
destination_state = input()
result = 0
for i in range(n):
	original_state_of_disk = int(original_state[i])
	destination_state_of_disk = int(destination_state[i])
	first_test = abs(original_state_of_disk - destination_state_of_disk)
	if original_state_of_disk > destination_state_of_disk:
		new_destination_state_of_disk = 10 + destination_state_of_disk
		second_test = new_destination_state_of_disk - original_state_of_disk
	else:
		new_original_state_of_disk = 10 + original_state_of_disk
		second_test = new_original_state_of_disk - destination_state_of_disk
	if first_test < second_test:
		result += first_test
	else:
		result += second_test
print(result)


from math import sqrt
(n, s1, s2) = (int(input()), input(), input())
r = 0
for i in range(n):
	if abs(int(s1[i]) - int(s2[i])) > 5:
		r += 10 - abs(int(s1[i]) - int(s2[i]))
	else:
		r += abs(int(s1[i]) - int(s2[i]))
print(r)


num_disk = int(input())
cur_disk = input()
dst_disk = input()
num_rot = 0
for i in range(num_disk):
	cur = int(cur_disk[i])
	dst = int(dst_disk[i])
	if cur < dst:
		cur = cur + 10
	if cur - dst > 5:
		num_rot = num_rot + (10 - (cur - dst))
	else:
		num_rot = num_rot + (cur - dst)
print(int(num_rot))


n = int(input())
l = list(map(int, input()))
s = list(map(int, input()))
c1 = 0
c2 = 0
c = 0
ll = 0
for i in range(n):
	c1 = 0
	c2 = 0
	if l[i] != s[i]:
		ll = l[i]
		while 1:
			ll += 1
			if ll == 10:
				ll = 0
			c1 += 1
			if ll == s[i]:
				break
		ll = l[i]
		while 1:
			ll -= 1
			if ll == -1:
				ll = 9
			c2 += 1
			if ll == s[i]:
				break
	c += min(c1, c2)
print(c)


n = input()
A = [int(x) for x in input()]
B = [int(x) for x in input()]
ans = 0
for i in range(len(A)):
	ans += min(abs(A[i] - B[i]), A[i] + 10 - B[i], abs(A[i] - 10 - B[i]))
print(ans)


n = input()
initial = input()
password = input()
res = 0
for (i, w) in enumerate(initial):
	df = abs(int(w) - int(password[i]))
	res += min(df, 10 - df)
print(res)


n = int(input())
begin = [int(x) for x in list(input())]
end = [int(x) for x in list(input())]
sum = 0
for i in range(n):
	(min_d, max_d) = sorted([begin[i], end[i]])
	sum += min(max_d - min_d, min_d + 10 - max_d)
print(sum)


def number_of_scrollings(x, y):
	x = int(x)
	y = int(y)
	if x > y:
		z = 5
		z = x
		x = y
		y = z
	return min(y - x, 10 - y + x)
n = int(input())
a = input()
b = input()
code = 0
for i in range(n):
	code += number_of_scrollings(a[i], b[i])
print(code)


input()
current = input()
target = input()
moves = 0
for i in range(len(current)):
	(val1, val2) = (int(current[i]), int(target[i]))
	moves += min([abs(val1 - val2), abs(val1 + 10 - val2), abs(val1 - (val2 + 10))])
print(moves)


n = int(input())
summation = 0
s = input()
x = input()
for i in range(n):
	diff = abs(int(s[i]) - int(x[i]))
	if diff <= 5:
		summation += diff
	else:
		summation += 10 - diff
print(summation)


_ = input()
source = input().strip()
target = input().strip()
print(sum(map(int, list(''.join(list((str(abs(int(source[x]) - int(target[x]))) if abs(int(source[x]) - int(target[x])) <= 5 else str(10 - abs(int(source[x]) - int(target[x]))) for x in range(len(source)))))))))


n = int(input())
num1 = [int(x) for x in str(input().strip())]
num2 = [int(x) for x in str(input().strip())]
print(sum([min(abs(num1[x] - num2[x]), min(num1[x], num2[x]) + 10 - max(num1[x], num2[x])) for x in range(n)]))


x = int(input())
a = list(map(int, list(input())))
b = list(map(int, list(input())))
print(sum([min(abs(a[i] - b[i]), abs(9 - max(a[i], b[i])) + 1 + min(a[i], b[i])) for i in range(x)]))


n = int(input())
a = input()
b = input()
cnt = 0
for i in range(n):
	if int(a[i]) == 0 and int(b[i]) > 5:
		cnt += 10 - int(b[i])
	elif int(a[i]) == 1 and int(b[i]) > 6:
		cnt += 11 - int(b[i])
	elif int(a[i]) == 2 and int(b[i]) > 7:
		cnt += 12 - int(b[i])
	elif int(a[i]) == 3 and int(b[i]) > 8:
		cnt += 13 - int(b[i])
	elif int(b[i]) == 0 and int(a[i]) > 5:
		cnt += 10 - int(a[i])
	elif int(b[i]) == 1 and int(a[i]) > 6:
		cnt += 11 - int(a[i])
	elif int(b[i]) == 2 and int(a[i]) > 7:
		cnt += 12 - int(a[i])
	elif int(b[i]) == 3 and int(a[i]) > 8:
		cnt += 13 - int(a[i])
	else:
		cnt += abs(int(a[i]) - int(b[i]))
print(cnt)


input()
a = [int(x) for x in input()]
b = [int(x) for x in input()]
print(sum((min(max(l) - min(l), 10 - max(l) + min(l)) for l in zip(a, b))))


def moves(n_target, n_lock):
	a = abs(n_target - n_lock)
	return min(a, 10 - a)
num = input()
n_lock = input()
n_target = input()
z = [moves(int(x1), int(x2)) for (x1, x2) in zip(n_target, n_lock)]
print(sum(z))


wheelsNum = int(input())
sourcePos = input()
targetPos = input()
minIter = 0
for i in range(wheelsNum):
	s = int(sourcePos[i])
	t = int(targetPos[i])
	if s != t:
		minIter += min(abs(s - t), 10 - abs(s - t))
print(minIter)


n = int(input())
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
l1 = list(map(int, input()))
l2 = list(map(int, input()))
c = 0
for i in range(n):
	c += min(abs(l.index(l1[i]) - l.index(l2[i])), abs(10 - l.index(l1[i]) + l2[i]), abs(10 - l.index(l2[i]) + l1[i]))
print(c)


n = int(input())
b = input()
c = input()
g = 0
for i in range(n):
	f = int(b[i])
	d = int(c[i])
	if d > f:
		if d - f < 10 - d + f:
			g += d - f
		else:
			g += 10 - d + f
	elif f > d:
		if f - d < 10 - f + d:
			g += f - d
		else:
			g += 10 - f + d
print(g)


n = int(input())
b = input()
a = input()
i = 0
sum = 0
while i < n:
	if abs(int(b[i]) - int(a[i])) <= 5:
		sum += abs(int(b[i]) - int(a[i]))
	else:
		sum += 10 - abs(int(b[i]) - int(a[i]))
	i += 1
print(sum)


n = int(input())
a = input()
b = input()
la = list(a)
lb = list(b)
cnt = 0
for i in range(n):
	cnt += min(abs(int(la[i]) - int(lb[i])), 10 - abs(int(la[i]) - int(lb[i])))
print(cnt)


ans = 0
input()
for (i, j) in zip(map(int, list(input())), map(int, list(input()))):
	ans += min(abs(i - j), 10 - abs(i - j))
print(ans)


def dani(x, y):
	(x, y) = (int(x), int(y))
	if x > y:
		t = x
		x = y
		y = t
	return min(y - x, 10 - y + x)
s = int(input())
r = input()
t = input()
ans = 0
for i in range(s):
	ans += dani(r[i], t[i])
print(ans)


n = int(input())
l = list(input())
l1 = list(input())
c = 0
for i in range(n):
	c += min(abs(int(l[i]) - int(l1[i])), abs(9 - abs(min(int(l[i]), int(l1[i])) - max(int(l[i]), int(l1[i])) + 1)))
print(c)


n = int(input())
original_state = input()
destination_state = input()
result = 0
for i in range(n):
	number_of_step = abs(int(original_state[i]) - int(destination_state[i]))
	result += min(number_of_step, 10 - number_of_step)
print(result)


cant = int(input())
intentos = 0
difer = 0
inicial = input()
fin = input()
Datos = range(cant)
for i in Datos:
	if int(inicial[i]) != int(fin[i]):
		difer = abs(int(inicial[i]) - int(fin[i]))
		if difer <= 5:
			intentos = intentos + difer
		else:
			intentos = intentos + (10 - difer)
print(intentos)


n = int(input())
orig = input()
code = input()
out = 0
for i in range(n):
	(a, b) = (int(orig[i]), int(code[i]))
	clws = abs(a - b)
	out += min(clws, 10 - clws)
print(out)


n = int(input())
current = list(map(int, input()))
code = list(map(int, input()))
result = 0
for i in range(0, n):
	result += min(abs(current[i] - code[i]), abs(max(current[i], code[i]) - (min(current[i], code[i]) + 10)))
print(result)


n = input()
n = int(n)
str1 = input()
str2 = input()
temp = 0
for i in range(0, n):
	t1 = int(str1[i])
	t2 = int(str2[i])
	a = min(abs(t1 - t2), abs(t1 + 10 - t2))
	m = min(a, abs(t2 + 10 - t1))
	temp += m
print(temp)


def s(x, y):
	sum1 = sum2 = 0
	if x > y:
		sum1 = x - y
		sum2 = y + (10 - x)
		if sum1 < sum2:
			return sum1
		else:
			return sum2
	else:
		sum1 = y - x
		sum2 = x + (10 - y)
		if sum1 < sum2:
			return sum1
		else:
			return sum2
final = 0
n = int(input())
org = list(input())
sol = list(input())
if len(org) == len(sol):
	for i in range(n):
		summ = s(int(org[i]), int(sol[i]))
		final = final + summ
print(final)


n = int(input())
c1 = str(input())
c2 = str(input())
start = [int(x) for x in c1]
finish = [int(x) for x in c2]
sum = 0
for i in range(n):
	t = abs(start[i] - finish[i])
	sum += min(t, 10 - t)
print(sum)


def distance(a, b):
	d = abs(int(b) - int(a))
	return min(d, 10 - d)
input()
print(sum([distance(x, y) for (x, y) in zip(input(), input())]))


def Q(n, string1, string2):
	count = 0
	for i in range(n):
		for j in range(1, 6):
			if string2[i] == string1[i]:
				continue
			if int(string1[i]) - j == int(string2[i]):
				count += j
				break
			if (int(string1[i]) + j) % 10 == int(string2[i]):
				count += j
				break
			if (int(string2[i]) + j) % 10 == int(string1[i]):
				count += j
				break
	return count
n = int(input())
line1 = input()
line2 = input()
print(Q(n, line1, line2))


n = int(input())
a = input()
b = input()
ch = 0
for x in range(0, n):
	if a[x] == b[x]:
		ch += 0
	else:
		l1 = int(a[x]) + 10
		l2 = int(b[x]) + 10
		if l1 - l2 > 5:
			l2 += 10
		if l2 - l1 > 5:
			l1 += 10
		aa1 = abs(l1 - l2)
		aa2 = abs(l2 - l1)
		ch += min(aa1, aa2)
print(ch)


a = int(input())
b = list(input())
c = list(input())
d = 0
e = 0
f = 0
s = 0
for i in range(a):
	b[i] = int(b[i])
	c[i] = int(c[i])
for i in range(a):
	if b[i] == 9:
		d = abs(c[i] + 1)
		e = abs(9 - c[i])
		f += min(d, e)
		e = 0
		d = 0
	else:
		d = abs(b[i] - c[i])
		e = 9 - b[i] + 1 + c[i]
		s = b[i] + 1 + (9 - c[i])
		f += min(d, e, s)
		e = 0
		d = 0
		s = 0
print(f)


n = int(input())
a = input()
b = input()
k = 0
for i in range(n):
	l = int(max(a[i], b[i])) - int(min(a[i], b[i]))
	s = int(min(a[i], b[i])) + 10 - int(max(a[i], b[i]))
	k = k + min(l, s)
print(k)


n = int(input())
a = input()
b = input()
sum = 0
for (x, y) in zip(a, b):
	d = abs(int(x) - int(y))
	if d > 5:
		d = 10 - d
	sum += d
print(sum)


a = int(input())
x = input()
y = input()
b = 0
n = 0

def xxx(a, b):
	x = int(a) - int(b)
	if x < 0:
		x *= -1
	return x
for i in range(a):
	z = xxx(x[i], y[i])
	if z > 5:
		z = 10 - z
	b += z
print(b)


digit = int(input())
current = list(input())
code = list(input())
ans = 0
for i in range(digit):
	ans += min(abs(int(current[i]) - int(code[i])), abs(int(current[i]) - int(code[i]) - 10), abs(int(current[i]) + 10 - int(code[i])))
print(ans)


import sys

def codes(inp, out, n):
	r = 0
	a = [int(i) for i in inp]
	b = [int(i) for i in out]
	for i in range(0, n):
		r += min(abs(a[i] - b[i]), 10 - abs(a[i] - b[i]))
	return r
n = int(input())
a = input()
b = input()
print(codes(a, b, n))


n = int(input())
sn = list(input())
sk = list(input())
k = 0
for i in range(n):
	sn[i] = int(sn[i])
	sk[i] = int(sk[i])
	k += min(10 - sn[i] + sk[i], max(sn[i], sk[i]) - min(sn[i], sk[i]), 10 - sk[i] + sn[i])
print(k)


n = int(input())
(s1, s2) = (input(), input())

def fn(s1, s2):
	ans = 0
	for i in range(len(s1)):
		a = abs(int(s1[i]) - int(s2[i]))
		b = 10 - a
		ans += min(a, b)
	return ans
print(fn(s1, s2))


n = int(input())
a = input()
b = input()
ans = 0
for i in range(n):
	d = abs(ord(a[i]) - ord(b[i]))
	ans += min(d, 10 - d)
print(ans)


n = int(input())
(a_str, b_str) = (input(), input())
ans = 0
for i in range(n):
	cnt = abs(int(a_str[i]) - int(b_str[i]))
	if cnt > 5:
		cnt = 10 - cnt
	ans += cnt
print(ans)


n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
s = sum([min(max(a[i], b[i]) - min(a[i], b[i]), min(a[i], b[i]) + 10 - max(a[i], b[i])) for i in range(n)])
print(s)


n = int(input())
s = [int(i) for i in input()]
j = [int(i) for i in input()]
count = 0
for i in range(n):
	count += min(abs(s[i] - j[i]), 10 - s[i] + j[i], 10 - abs(s[i] - j[i]))
print(count)


a = int(input())
b = list(input())
c = list(input())
s = 0
for i in range(len(c)):
	s += min(abs(int(b[i]) - int(c[i])), 10 - abs(int(b[i]) - int(c[i])))
print(s)


import math
n = int(input())
a = list(input())
b = list(input())
sumi = 0
for i in range(n):
	(c, d) = (int(a[i]), int(b[i]))
	sumi += min(10 - (max(c, d) - min(c, d)), max(c, d) - min(c, d))
print(sumi)


t = int(input())
s = input()
s1 = input()
move = 0
for i in range(t):
	move += min(10 - abs(int(s[i]) - int(s1[i])), abs(int(s[i]) - int(s1[i])))
print(move)


long_of_code = int(input())
start_result = input()
finish_result = input()
num = 0
for i in range(long_of_code):
	if abs(int(start_result[i]) - int(finish_result[i])) <= 5:
		num += abs(int(start_result[i]) - int(finish_result[i]))
	else:
		if 0 <= int(start_result[i]) <= 3:
			num += int(start_result[i]) + 10 - int(finish_result[i])
		if 6 <= int(start_result[i]) <= 9:
			num += int(finish_result[i]) + 10 - int(start_result[i])
print(num)


n = int(input())
original_state = input()
present_state = input()
sum = 0
for i in range(0, n):
	diff = abs(int(original_state[i]) - int(present_state[i]))
	if diff > 5:
		diff = 10 - diff
	sum = sum + abs(diff)
print(sum)


from collections import deque

def girar_derecha(num_ini, num_fin):
	numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
	num_moves = 0
	while numbers[0] != num_ini:
		numbers = deque(numbers)
		numbers.rotate(1)
		numbers = list(numbers)
	while numbers[0] != num_fin:
		numbers = deque(numbers)
		numbers.rotate(1)
		numbers = list(numbers)
		num_moves = num_moves + 1
	return num_moves

def girar_izquierda(num_ini, num_fin):
	numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
	num_moves = 0
	while numbers[0] != num_ini:
		numbers = deque(numbers)
		numbers.rotate(-1)
		numbers = list(numbers)
	while numbers[0] != num_fin:
		numbers = deque(numbers)
		numbers.rotate(-1)
		numbers = list(numbers)
		num_moves = num_moves + 1
	return num_moves

def init():
	disks = int(input())
	original_pos = input()
	password = input()
	numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
	total_moves = 0
	for i in range(0, disks):
		num1 = int(original_pos[i])
		num2 = int(password[i])
		moves1 = girar_izquierda(num1, num2)
		moves2 = girar_derecha(num1, num2)
		if moves1 < moves2:
			total_moves = total_moves + moves1
		elif moves2 < moves1:
			total_moves = total_moves + moves2
		else:
			total_moves = total_moves + moves1
	print(total_moves)
init()


n = int(input())
l1 = str(input())
l2 = str(input())
count = 0
for i in range(n):
	a = abs(int(l1[i]) - int(l2[i]))
	b = abs(10 + min(int(l1[i]), int(l2[i])) - max(int(l1[i]), int(l2[i])))
	count += min(a, b)
print(count)


n = int(input())
orig = [int(i) for i in list(input())]
dest = [int(i) for i in list(input())]
move = lambda i: min(abs(orig[i] - dest[i]), 10 - abs(orig[i] - dest[i]))
change = [move(i) for i in range(n)]
print(sum(change))


def main():
	(_, start, end) = [input() for _ in range(3)]
	ans = 0
	for (s, e) in zip(start, end):
		(a, b) = (int(s), int(e))
		if b > a:
			(a, b) = (b, a)
		ans += min(a - b, 10 + b - a)
	print(ans)
main()


Move = 0
n = int(input())
l = input()
l1 = input()
for i in range(n):
	a = int(l[i])
	b = int(l1[i])
	if a < b:
		Move += min(b - a, 9 - b + a + 1)
	elif l[i] > l1[i]:
		Move += min(a - b, 9 - a + b + 1)
	else:
		pass
print(Move)


number = int(input())
a = 0
now = [int(x) for x in list(input())]
target = [int(x) for x in list(input())]
for i in range(number):
	a += min(abs(now[i] - target[i]), 10 - abs(now[i] - target[i]))
print(a)


n = int(input())
m1 = input()
m2 = input()
x = 0
for i in range(len(m1)):
	p = abs(int(m1[i]) - int(m2[i]))
	q = 10 - int(m1[i]) + int(m2[i])
	s = 10 - int(m2[i]) + int(m1[i])
	x = x + min(p, q, s)
print(x)


n = int(input())
current = input()
secret = input()
move = 0
for i in range(n):
	diff = abs(int(secret[i]) - int(current[i]))
	if diff > 5:
		diff = 10 - diff
	move += diff
print(move)


from math import *
n = int(input())
x = input()
y = input()
z = 0
for i in range(n):
	z = z + min(fabs(int(x[i]) - int(y[i])), fabs(fabs(int(x[i]) - int(y[i])) - 10))
print(int(z))


def main():
	n = int(input())
	(code1, code2) = (input(), input())
	answ = 0
	for i in range(n):
		answ += min((int(code1[i]) - int(code2[i]) + 10) % 10, (-int(code1[i]) + int(code2[i]) + 10) % 10)
	print(answ)
main()


def main():
	n = int(input())
	a = input()
	b = input()
	c = 0
	for i in range(0, n):
		move = abs(int(a[i]) % 10 - int(b[i]) % 10)
		if move != 9 and move < 5:
			c = c + move
		elif move != 9 and move >= 5:
			c = c + 10 - move
		if move == 9:
			c = c + 1
	print(c)
main()


n = int(input())
a = input()
b = input()
count = 0
for i in range(len(a)):
	if max(int(a[i]), int(b[i])) - min(int(a[i]), int(b[i])) > 5:
		count += min(int(a[i]), int(b[i])) + 10 - max(int(a[i]), int(b[i]))
	elif max(int(a[i]), int(b[i])) - min(int(a[i]), int(b[i])) <= 5:
		count += max(int(a[i]), int(b[i])) - min(int(a[i]), int(b[i]))
print(count)


n = int(input())
s_our = input()
s_code = input()
answ = 0
for i in range(n):
	x_our = int(s_our[i])
	x_code = int(s_code[i])
	answ += min(abs(x_our - x_code), min(x_our, x_code) + 10 - max(x_our, x_code))
print(answ)


n = int(input())
a = input()
kod = input()
k = 0
for i in range(n):
	r = abs(int(a[i]) - int(kod[i]))
	if r > 5:
		k += 10 - r
	else:
		k += r
print(k)


n = int(input())
a = list(str(input()))
a = [int(i) for i in a]
b = list(str(input()))
b = [int(i) for i in b]
c = 0
i = 0
while i < len(a):
	roll = min(abs(a[i] - b[i]), 10 - abs(a[i] - b[i]))
	c += roll
	i += 1
print(c)


def Mini(a, b):
	if a < b:
		min = a
	else:
		min = b
	return min

def Maxi(a, b):
	if a > b:
		max = a
	else:
		max = b
	return max
n = int(input())
begin = [int(i) for i in input()]
end = [int(i) for i in input()]
count = 0
otvet = 0
while count < len(begin):
	i = begin[count]
	y = end[count]
	min = Mini(i, y)
	max = Maxi(i, y)
	ans = max - min
	reverse_ans = 9 - max + min + 1
	step = Mini(ans, reverse_ans)
	count += 1
	otvet = otvet + step
print(otvet)


n = int(input())
original_list = [int(x) for x in input()]
final_list = [int(x) for x in input()]
result = 0
for i in range(n):
	result += min(abs(original_list[i] - final_list[i]), 10 - abs(original_list[i] - final_list[i]))
print(result)


n = int(input())
a = input()
b = input()
i = 0
summ = 0
while i < n:
	aa = int(a[i])
	bb = int(b[i])
	summ += min(abs(aa - bb), abs(aa + 10 - bb), abs(bb - aa + 10))
	i += 1
print(summ)


import math
input()
n = input()
m = input()
d = list(zip(map(int, n), map(int, m)))
print(sum((min(abs(x - y), 10 - abs(x - y)) for (x, y) in d)))


n = int(input())
farii = int(input())
asli = int(input())
m = 0
for i in range(n):
	y = farii % 10
	yy = asli % 10
	z = max(y, yy) - min(y, yy)
	zz = 10 - z
	m = m + min(z, zz)
	farii = farii // 10
	asli //= 10
print(m)


n = int(input())
s1 = str(input())
s2 = str(input())
s = 0
for i in range(n):
	a = int(s1[i])
	b = int(s2[i])
	if abs(a - b) < 10 - abs(a - b):
		s += abs(a - b)
	else:
		s += 10 - abs(a - b)
print(s)


def main():
	n = int(input())
	a = int(input())
	b = int(input())
	ans = 0
	while n > 0:
		n -= 1
		(x, y) = (a % 10, b % 10)
		a //= 10
		b //= 10
		ans += min(10 - abs(x - y), abs(x - y))
	print(ans)
main()


fu = int(input())
combinationNow = list(map(int, list(input())))
combinationFINISH = list(map(int, list(input())))
k = 0
for (i, j) in zip(combinationNow, combinationFINISH):
	if abs(i - j) > 5:
		k += 10 - abs(i - j)
	else:
		k += abs(i - j)
print(k)


import sys

def main():
	n = int(sys.stdin.readline())
	c1 = sys.stdin.readline()
	c2 = sys.stdin.readline()
	total = 0
	for i in range(0, n):
		d1 = int(c1[i])
		d2 = int(c2[i])
		tforw = max(d1, d2) - min(d1, d2)
		tback = min(d1, d2) - max(d1, d2) + 10
		total = total + min(tforw, tback)
	print(total)
main()


disk = int(input())
disk_position = input()
combination = input()
ten = 10
result = []
for i in range(0, disk):
	if int(combination[i]) < int(disk_position[i]):
		itog = int(disk_position[i]) - int(combination[i])
		if itog >= 5:
			res = ten - itog
			result.append(res)
		else:
			result.append(itog)
	elif int(combination[i]) > int(disk_position[i]):
		itog = int(combination[i]) - int(disk_position[i])
		if itog >= 5:
			res = ten - itog
			result.append(res)
		else:
			result.append(itog)
summa = 0
for i in range(0, len(result)):
	summa = summa + result[i]
print(summa)


__author__ = '(Lambdell)'

def solve():
	n = int(input())
	a = [int(x) for x in input()]
	b = [int(x) for x in input()]
	return sum((min(abs(x - y), 10 - abs(x - y)) for (x, y) in zip(a, b)))
print(solve())


import pdb
n = int(input())
x = list(input())
y = list(input())
c = 0
for i in range(n):
	s = abs(int(x[i]) - int(y[i]))
	c += min(s, 10 - s)
print(c)


n = int(input())
p = list(input())
p = list(map(int, p))
q = list(input())
q = list(map(int, q))
sum = 0
for i in range(n):
	if abs(p[i] - q[i]) > 5:
		sum = sum + (10 - abs(p[i] - q[i]))
	else:
		sum = sum + abs(p[i] - q[i])
print(sum)


x = int(input())
y = input()
z = input()
a = 0
output = 0
i = 0
lst = []
lst2 = []
while i < x:
	lst.append(int(y[i]))
	lst2.append(int(z[i]))
	if lst[i] - lst2[i] > 5:
		a = 10 + lst2[i] - lst[i]
		output += a
	elif lst2[i] - lst[i] > 5:
		a = 10 + lst[i] - lst2[i]
		output += a
	elif lst[i] > lst2[i]:
		a = lst[i] - lst2[i]
		output += a
	elif lst[i] < lst2[i]:
		a = lst2[i] - lst[i]
		output += a
	i += 1
print(output)


d = int(input())
o = int(input())
f = int(input())
i = d
c = 0
while i >= 1:
	a = o % 10
	b = f % 10
	M = max(a, b)
	m = min(a, b)
	diff = M - m
	c = c + min(diff, 10 - diff)
	o = o // 10
	f = f // 10
	i -= 1
print(c)


l = int(input())
cur = input()
pas = input()
i = 0
sum = 0
while i < l:
	if abs(int(cur[i]) - int(pas[i])) <= 5:
		sum = sum + abs(int(cur[i]) - int(pas[i]))
	else:
		m = min(int(cur[i]), int(pas[i])) + 10
		sum = sum + (m - max(int(cur[i]), int(pas[i])))
	i += 1
print(sum)


input()
c = 0
for (x, y) in zip([int(i) for i in input()], [int(i) for i in input()]):
	c += min([abs(x - y), abs(10 - abs(x - y))])
print(c)


def F(n, m):
	p = abs(n - m)
	l = min(n, m) + 10 - max(n, m)
	return min(p, l)
n = int(input())
N1 = str(input())
N2 = str(input())
sh = 0
for i in range(n):
	k1 = N1[i]
	k2 = N2[i]
	sh += F(int(k1), int(k2))
print(sh)


n = int(input())
i1 = [int(x) for x in input()]
i2 = [int(x) for x in input()]
ans = 0
for i in range(n):
	x = i1[i]
	y = i2[i]
	z = abs(x - y)
	if z > 5:
		z = 10 - z
	ans += z
print(ans)


n = int(input())
s = input()
p = input()
a = 0
for i in range(n):
	(x, y) = (int(s[i]), int(p[i]))
	a += min(abs(x - y), x + 10 - y, y + 10 - x)
print(a)


n = int(input())
s = map(ord, input())
t = map(ord, input())
r = 0
for (c, d) in zip(s, t):
	r += min(abs(d - (c - 10)), abs(d - c), abs(d - (c + 10)))
print(r)


n = int(input())
str1 = input()
str2 = input()
move = 0
for i in range(n):
	a = str1[i]
	b = str2[i]
	q = abs(int(a) - int(b))
	move += min(q, 10 - q)
print(move)


n = int(input())
c1 = input()
c2 = input()
sum = 0
for i in range(n):
	s = int(c1[i])
	e = int(c2[i])
	d = abs(s - e)
	if d > 5:
		sum = sum + (10 - d)
	else:
		sum += d
print(sum)


ans = 0
n = int(input())
(a, b) = (list(map(int, list(input()))), list(map(int, list(input()))))
for i in range(n):
	if abs(a[i] - b[i]) < 5:
		ans += abs(a[i] - b[i])
	else:
		ans += abs(10 - abs(a[i] - b[i]))
print(ans)


n = int(input())
num1 = list(map(int, input()))
num2 = list(map(int, input()))
count = 0
for i in range(n):
	count += min(abs(num1[i] - num2[i]), 9 - max(num1[i], num2[i]) + min(num1[i], num2[i]) + 1)
print(count)


n = int(input())
o = list(map(int, input()))
l = list(map(int, input()))
c = 0
for i in range(n):
	if abs(o[i] - l[i]) > 5:
		c += 10 - abs(o[i] - l[i])
	else:
		c += abs(o[i] - l[i])
print(c)


n = int(input())
oriState = list(input())
finState = list(input())
moves = 0
for i in range(n):
	dif = abs(int(oriState[i]) - int(finState[i]))
	if dif > 5:
		moves += 10 - dif
	else:
		moves += dif
print(moves)


n = int(input())
p = input()
q = input()
c = 0
for i in range(n):
	a = int(p[i])
	b = int(q[i])
	c += min(abs(a - b), abs(a + 10 - b), abs(a - b - 10))
print(c)


n = int(input())
text = list(map(int, list(input())))
text2 = list(map(int, list(input())))
rez = 0
for i in range(n):
	rez += min(10 - abs(text[i] - text2[i]), abs(text[i] - text2[i]))
print(rez)


cifier = int(input())
zamok1 = input()
zamok2 = input()
otacok = 0
for i in range(cifier):
	cifry = sorted(map(int, [zamok1[i], zamok2[i]]))
	otacok1 = cifry[1] - cifry[0]
	otacok2 = 10 - cifry[1] + cifry[0]
	otacok += min(otacok1, otacok2)
print(otacok)


n = int(input())
s = input()
q = input()
cnt = 0
for i in range(len(s)):
	if abs(int(s[i]) - int(q[i])) <= 5:
		cnt = cnt + abs(int(s[i]) - int(q[i]))
	else:
		cnt = cnt + abs(abs(int(s[i]) - int(q[i])) - 10)
print(cnt)


n = int(input())
a = input()
b = input()
c = 0
for i in range(n):
	m = abs(int(a[i]) - int(b[i]))
	if m > 5:
		m = 10 - m
	c += m
print(c)


def dist(a, b):
	if a > b:
		return min(abs(a - b), b - a + 10)
	else:
		return min(abs(b - a), a - b + 10)
a = int(input())
x = input()
y = input()
tt = 0
for i in range(a):
	tt += dist(int(x[i]), int(y[i]))
print(tt)


n = int(input())
x = str(input())
y = str(input())
a = []
x = [int(i) for i in str(x)]
y = [int(i) for i in str(y)]
for i in range(0, len(x)):
	if abs(x[i] - y[i]) <= 5:
		a.append(abs(x[i] - y[i]))
	elif abs(x[i] - y[i]) == 6:
		a.append(4)
	elif abs(x[i] - y[i]) == 7:
		a.append(3)
	elif abs(x[i] - y[i]) == 8:
		a.append(2)
	elif abs(x[i] - y[i]) == 9:
		a.append(1)
print(sum(a))


n = int(input())
o = int(input())
p = int(input())
res = 0
while o > 0 or p > 0:
	l1 = o % 10
	l2 = p % 10
	res += min(abs(l2 - l1), min(abs(10 - l1 + l2), abs(10 - l2 + l1)))
	o = o // 10
	p = p // 10
print(res)


n = int(input())
s1 = input()
s2 = input()
diff = total = 0
while n:
	n = n - 1
	diff = abs(ord(s1[n]) - ord(s2[n]))
	if diff < 6:
		total = total + diff
	else:
		total = total + 10 - diff
print(total)


n = int(input())
s = input()
t = input()
k = 0
for i in range(n):
	d = int(s[i])
	e = int(t[i])
	l = abs(d - e)
	if l > 5:
		k += 10 - l
	else:
		k += l
print(k)


a = int(input())
b = str(input())
c = str(input())
i = 0
w = 0
while i in range(a):
	d = int(b[i]) - int(c[i])
	o = abs(d)
	e = min(o, 10 - o)
	w += e
	i += 1
print(w)


num = int(input())
current = int(input())
unlock = int(input())
moves = 0
i = 0
while i < num:
	cdgt = current % 10
	current = current // 10
	udgt = unlock % 10
	unlock = unlock // 10
	moves += min(abs(udgt - cdgt), 10 - abs(udgt - cdgt))
	i += 1
print(moves)


n = int(input())
a = input()
b = input()
i = 0
m = 0
count = 0
while i < n:
	if a[i] != b[m]:
		if abs(int(a[i]) - int(b[m])) < 10 - int(max(a[i], b[m])) + int(min(a[i], b[m])):
			count += abs(int(a[i]) - int(b[m]))
			i += 1
			m += 1
		else:
			count += 10 - int(max(a[i], b[m])) + int(min(a[i], b[m]))
			i += 1
			m += 1
	else:
		i += 1
		m += 1
print(count)


n = int(input())
start = list(input())
end = list(input())
i = 0
res = 0
while start != end:
	k = int(start[i])
	l1 = 0
	l2 = 0
	while k != int(end[i]):
		k += 1
		if k > 9:
			k = 0
		l1 += 1
	k = int(start[i])
	while k != int(end[i]):
		k -= 1
		if k < 0:
			k = 9
		l2 += 1
	start[i] = end[i]
	i += 1
	res += min(l1, l2)
print(res)


n = int(input())
orig = [int(x) for x in list(input())]
sec = [int(x) for x in list(input())]
cnt = 0
for i in range(n):
	if abs(orig[i] - sec[i]) > 5:
		cnt += 10 - abs(orig[i] - sec[i])
	else:
		cnt += abs(orig[i] - sec[i])
print(cnt)


n = int(input())
start = str(input())
need = str(input())
actions = 0
for a in range(n):
	f = int(start[a])
	s = int(need[a])
	if max(f, s) - min(f, s) < min(f, s) + 10 - max(f, s):
		actions += max(f, s) - min(f, s)
	else:
		actions += min(f, s) + 10 - max(f, s)
print(actions)


n = int(input())
start_pos = input()
end_pos = input()
count_sum = 0

def check_up():
	y = int(end_pos[i])
	x = int(start_pos[i])
	count = 0
	while x != y:
		if x == 9:
			x = 0
			count += 1
		else:
			x += 1
			count += 1
	return count

def check_down():
	y = int(end_pos[i])
	x = int(start_pos[i])
	count = 0
	while x != y:
		if x == 0:
			x = 9
			count += 1
		else:
			x -= 1
			count += 1
	return count
for i in range(n):
	count_sum += min(check_up(), check_down())
print(count_sum)


def f(a, b):
	ma = max(a, b)
	mi = min(a, b)
	p = ma - mi
	q = 10 - ma + mi
	return min(p, q)
n = int(input())
number1 = [int(i) for i in input()]
number2 = [int(i) for i in input()]
steps = 0
for i in range(n):
	steps += f(number1[i], number2[i])
print(steps)


n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
c = 0
k = 0
for i in range(len(a)):
	k = abs(a[i] - b[i])
	if k > 5:
		c += 10 - k
	else:
		c += k
print(c)


n = int(input())
r = 0
start = [int(i) for i in list(input())]
finish = [int(i) for i in list(input())]
for i in range(len(start)):
	u = abs(start[i] - finish[i])
	if u > 5:
		r += 10 - u
	else:
		r += u
print(r)


def main():
	disk = int(input())
	lock_state = input()
	unlock_state = input()
	count = 0
	for i in range(disk):
		if abs(int(unlock_state[i]) - int(lock_state[i])) <= 5:
			count += abs(int(unlock_state[i]) - int(lock_state[i]))
		else:
			count += 10 - abs(int(unlock_state[i]) - int(lock_state[i]))
	print(count)
main()


n = int(input())
o = input()
w = input()
p = 0
for i in range(0, n):
	v = int(o[i]) - int(w[i])
	if v < 0:
		v = -v
	if v > 5:
		v = 10 - v
	p = p + v
print(p)


n = int(input())
orig = input()
open = input()
move = 0
for i in range(n):
	a = orig[i]
	b = open[i]
	if a != b:
		a = int(a)
		b = int(b)
		move += min(abs(a - b), abs(a - b + 10), abs(b - a + 10))
print(move)


disk = int(input())
state = input()
combi = input()
count = 0
for num in range(disk):
	p = abs(int(state[num]) - int(combi[num]))
	if p <= 5:
		count += p
	else:
		count += 10 - p
print(count)


n = int(input())
s1 = input()
s2 = input()
res = 0
for i in range(n):
	x = abs(int(s1[i]) - int(s2[i]))
	y = 10 - x
	res += min(x, y)
print(res)


n = int(input())
sum = 0
l1 = list(input())
l2 = list(input())
for i in range(n):
	diff = abs(int(l1[i]) - int(l2[i]))
	if diff <= 5:
		sum = sum + diff
	else:
		sum = sum + (10 - diff)
print(sum)


x = int(input())
x_1 = list(input())
x_2 = list(input())
s = 0
for i in range(len(x_1)):
	d = abs(int(x_1[i]) - int(x_2[i]))
	s += min(d, 10 - d)
print(s)


n = int(input())
oComb = [int(x) for x in str(input())]
fComb = [int(x) for x in str(input())]
resp = 0
for i in range(n):
	a = abs(oComb[i] - fComb[i])
	if a > 5:
		resp += 10 - a
	else:
		resp += a
print(resp)


def solve(L):
	for i in range(n):
		L[i] = ord(L[i]) - ord('0')
	return L
n = int(input())
L1 = list(input())
L2 = list(input())
L1 = solve(L1)
L2 = solve(L2)
ans = 0
for i in range(n):
	temp = min(abs(L1[i] - L2[i]), min(10 - L1[i] + L2[i], 10 - L2[i] + L1[i]))
	ans += temp
print(ans)


n = int(input())
xs = [int(a) for a in input()]
ys = [int(a) for a in input()]
counter = 0
for (x, y) in zip(xs, ys):
	counter += min(abs(x - y), min(x, y) + 10 - max(x, y))
print(counter)


n = int(input())
s0 = input()
s1 = input()
ctr = 0
for i in range(n):
	t = int(s0[i]) - int(s1[i])
	ctr += min(abs(t), abs(t + 10), abs(t - 10))
print(ctr)


n = int(input())
x = input()
y = input()
a = list(x)
b = list(y)
l = []
for i in a:
	l.append(int(i))
m = []
for i in b:
	m.append(int(i))
total = 0
for i in range(n):
	d = l[i] - m[i]
	if d >= 6:
		total += 10 + m[i] - l[i]
	elif d <= -6:
		total += 10 + l[i] - m[i]
	elif l[i] > m[i]:
		total += l[i] - m[i]
	else:
		total += m[i] - l[i]
print(total)


n = int(input())
num1 = int(input())
num2 = int(input())
moves = 0
for i in range(n):
	temp1 = num1 % 10
	temp2 = num2 % 10
	if temp1 < temp2:
		if temp2 - temp1 >= 10 + temp1 - temp2:
			moves += 10 + temp1 - temp2
		else:
			moves += temp2 - temp1
	elif temp1 - temp2 >= 10 + temp2 - temp1:
		moves += 10 + temp2 - temp1
	else:
		moves += temp1 - temp2
	num1 = num1 // 10
	num2 = num2 // 10
print(moves)


n = int(input())
s = input()
l = input()
res = 0
for i in range(n):
	x = abs(int(s[i]) - int(l[i]))
	y = 10 - x
	res += min(x, y)
print(res)


n = int(input())
(a, b) = (input(), input())
s = 0
for i in range(n):
	tmp = ord(a[i]) - ord(b[i])
	tmp %= 10
	if tmp > 5:
		s += 10 - tmp
	else:
		s += tmp
print(s)


n = int(input())
s1 = input()
s2 = input()
s = 0
for i in range(n):
	d1 = int(s1[i])
	d2 = int(s2[i])
	s += min(abs(d2 - d1), d1 + 10 - d2, d2 + 10 - d1)
print(s)


n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
c = 0
for i in range(len(a)):
	k = abs(int(a[i]) - int(b[i]))
	l = 10 - abs(int(a[i] - b[i]))
	p = min(l, k)
	c = c + p
	p = 0
print(c)


n = int(input())
a = input()
b = input()
rotation = 0
for i in range(len(a)):
	if abs(int(a[i]) - int(b[i])) <= 5:
		rotation = rotation + abs(int(a[i]) - int(b[i]))
	else:
		rotation = rotation + (9 - max(int(a[i]), int(b[i])) + 1 + min(int(a[i]), int(b[i])))
print(rotation)


n = int(input())
d = list(map(int, input()))
p = list(map(int, input()))
count = 0
for i in range(n):
	count += min(abs(p[i] - d[i]), 10 - abs(p[i] - d[i]))
print(count)


n = int(input())
a = int(input())
b = int(input())
i = 1
x = 0
while i <= n:
	y = a % 10
	z = b % 10
	if abs(y - z) >= 6:
		x = x + 10 - abs(y - z)
	else:
		x = x + abs(y - z)
	a = a // 10
	b = b // 10
	i = i + 1
print(x)


numofdisks = int(input())
begstate = str(input())
endstate = str(input())
begstatelst = []
endstatelst = []
mvnmb = 0
for i in begstate:
	begstatelst.append(i)
for i in endstate:
	endstatelst.append(i)
for i in range(numofdisks):
	diff = abs(int(begstatelst[i]) - int(endstatelst[i]))
	if diff <= 5:
		mvnmb += diff
	elif diff > 5:
		mvnmb += 10 - diff
print(mvnmb)


n = int(input())
a = input()
b = input()
c = 0
for i in range(n):
	if a[i] > b[i]:
		if int(a[i]) - int(b[i]) <= 5:
			c += int(a[i]) - int(b[i])
		else:
			c += 9 - int(a[i]) + (int(b[i]) + 1)
	elif b[i] > a[i]:
		if int(b[i]) - int(a[i]) <= 5:
			c += int(b[i]) - int(a[i])
		else:
			c += 9 - int(b[i]) + (int(a[i]) + 1)
print(c)


n = int(input())
a = input()
b = input()
t = 0
for i in range(n):
	k = int(a[i])
	s = int(b[i])
	if k >= 5 and s >= 5 or (k <= 5 and s <= 5):
		t += abs(k - s)
	if k < 5 and s > 5:
		p = abs(10 + k - s)
		q = abs(k - s)
		t += min(p, q)
	if k > 5 and s < 5:
		p = abs(k - (10 + s))
		q = abs(k - s)
		t += min(p, q)
print(t)


n = int(input())
s1 = input()
s2 = input()
c = 0
import math
for i in range(len(s1)):
	o = math.fabs(int(s1[i]) - int(s2[i]))
	if o < 10 - o:
		c += o
	elif o > 10 - o:
		c += 10 - o
	else:
		c += o
print(int(c))


n = int(input())
x = str(input())
y = str(input())
turn = 0
for i in range(n):
	mx = max(int(x[i]), int(y[i]))
	mn = min(int(x[i]), int(y[i]))
	dif = mx - mn
	if dif > 5:
		turn = turn + (10 - dif)
	else:
		turn = turn + dif
print(turn)


p = int(input())
a = input()
b = input()
count = 0
for i in range(len(a)):
	k = abs(int(a[i]) - int(b[i]))
	if k > 5:
		k = 10 - k
	count = count + k
print(count)


n = int(input())
s1 = input()
s2 = input()
i = 0
count = 0
while i < n:
	diff = abs(int(s1[i]) - int(s2[i]))
	count += diff if diff <= 5 else 10 - diff
	i += 1
print(count)


n = int(input())
a = input()
b = input()
count = 0
for i in range(n):
	razn = abs(int(a[i]) - int(b[i]))
	if razn <= 5:
		count += razn
	else:
		count += 10 - razn
print(count)


n = int(input())
m = input()
d = input()
mylist1 = []
mylist = []
count = 0
for j in m:
	mylist.append(int(j))
for k in d:
	mylist1.append(int(k))
for i in range(n):
	if abs(mylist[i] - mylist1[i]) < 6:
		count += abs(mylist[i] - mylist1[i])
	elif abs(mylist[i] - mylist1[i]) >= 6:
		g = 10 - abs(mylist[i] - mylist1[i])
		count += g
	else:
		count += abs(mylist[i] - mylist1[i])
print(count)


n = int(input())
s = input()
m = input()
ans = 0
for i in range(n):
	ans += min(abs(int(s[i]) - int(m[i])), 10 - abs(int(s[i]) - int(m[i])))
print(ans)


n = int(input())
s = input()
t = input()
l = 0
for i in range(n):
	a = int(s[i])
	b = int(t[i])
	l += min(10 - abs(-a + b), abs(b - a))
print(l)


n = int(input())
s1 = input()
s2 = input()
ans = 0

def min_dif(x, y):
	rez = 0
	x = int(x)
	y = int(y)
	while x != y:
		if x == 0:
			x = 9
			rez += 1
		if x == y:
			return rez
		x -= 1
		rez += 1
		if x == 0 and x != y:
			x = 9
			rez += 1
	return rez

def min_sum(x, y):
	rez = 0
	x = int(x)
	y = int(y)
	while x != y:
		if x == 9:
			x = 0
			rez += 1
		if x == y:
			return rez
		x += 1
		rez += 1
		if x == 9 and x != y:
			x = 0
			rez += 1
	return rez
for i in range(n):
	ans += min(min_sum(s1[i], s2[i]), min_dif(s1[i], s2[i]))
print(ans)


N = int(input())
S1 = input()
S2 = input()

def move(a, b):
	return min(max(a, b) - min(a, b), min(a, b) + 10 - max(a, b))
ans = 0
for i in range(N):
	ans += move(int(S1[i]), int(S2[i]))
print(ans)


e = int(input())
a = input()
b = input()
res = 0
i = 0
while i != e:
	res += min(abs(max(int(a[i]), int(b[i])) - min(int(a[i]), int(b[i]))), abs(10 - max(int(a[i]), int(b[i])) + min(int(a[i]), int(b[i]))))
	i += 1
print(res)


n = int(input())
n1 = input()
n2 = input()
ans = 0
for i in range(n):
	result = abs(int(n1[i]) - int(n2[i]))
	if result > 5:
		result = 10 - result
	ans += result
print(ans)


wheels = int(input())
wheel = '01234567890123456789'
originalPos = input()
combination = input()
moves = 0
for index in range(wheels):
	if int(originalPos[index]) < int(combination[index]):
		moves += min(abs(wheel.find(originalPos[index]) - wheel.find(combination[index])), abs(wheel.rfind(originalPos[index]) - wheel.find(combination[index])))
	else:
		moves += min(abs(wheel.find(combination[index]) - wheel.find(originalPos[index])), abs(wheel.rfind(combination[index]) - wheel.find(originalPos[index])))
print(moves)


n = int(input())
string = '0123456789'
moves = 0
moves2 = 0
total = 0
str1 = input()
str2 = input()
for i in range(n):
	c = int(str1[i])
	d = int(str2[i])
	e = int(str1[i])
	f = int(str2[i])
	while c != d:
		c -= 1
		if c < 0:
			c = 9
		moves += 1
	while e != f:
		e += 1
		moves2 += 1
		if e > len(string) - 1:
			e = 0
	total += min(moves, moves2)
	moves = 0
	moves2 = 0
print(total)


from sys import stdin
n = int(stdin.readline().rstrip())
init_state = [int(x) for x in stdin.readline().rstrip()]
result_state = [int(x) for x in stdin.readline().rstrip()]
result = 0
for i in range(n):
	first_key = min(init_state[i], result_state[i])
	second_key = max(init_state[i], result_state[i])
	result1 = second_key - first_key
	result2 = 10 - second_key + first_key
	result += min(result1, result2)
print('{}\n'.format(result))


n = int(input())
a = input()
b = input()

def absolute(n):
	if n >= 0:
		return n
	else:
		return -1 * n

def minimum(a, b):
	if a <= b:
		return a
	else:
		return b

def value(n1, n2):
	return minimum(10 - n1, n1) + minimum(10 - n2, n2)
ans = 0
for i in range(len(a)):
	if absolute(int(a[i]) - int(b[i])) <= value(int(a[i]), int(b[i])):
		ans += absolute(int(a[i]) - int(b[i]))
	else:
		ans += value(int(a[i]), int(b[i]))
print(ans)


input()
i = input()
c = input()
m = 0
for r in range(len(i)):
	t = abs(int(c[r]) - int(i[r]))
	m += min(t, 10 - t)
print(m)


n = input()
n = int(n)
ori = list(input())
com = list(input())
for i in range(len(ori)):
	ori[i] = int(ori[i])
for i in range(len(com)):
	com[i] = int(com[i])
move = 0
for i in range(len(ori)):
	move = move + min(abs(ori[i] - com[i]), abs(ori[i] + 10 - com[i]), abs(ori[i] - com[i] - 10))
print(move)


def main(n, a, b):
	res = 0
	for i in range(n):
		x = min(a[i], b[i])
		y = max(a[i], b[i])
		diff = min(y - x, x + 10 - y)
		res += diff
	return res
n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
print(main(n, a, b))


import sys
T = int(input())
curr = input()
final = input()
total = 0
for i in range(T):
	diff_1 = int(curr[i]) - int(final[i])
	if diff_1 < 0:
		diff_1 += 10
	diff_2 = int(final[i]) - int(curr[i])
	if diff_2 < 0:
		diff_2 += 10
	if diff_1 < diff_2:
		total += diff_1
	else:
		total += diff_2
print(total)
exit(0)


disk = int(input())
lock1 = input()
lock2 = input()
count = 0
for i in range(0, disk):
	if int(lock1[i]) > int(lock2[i]):
		b = int(lock1[i]) - int(lock2[i])
		c = int(lock2[i]) + 10 - int(lock1[i])
		if c < b:
			b = c
		count += b
	elif int(lock1[i]) < int(lock2[i]):
		b = int(lock1[i]) + 10 - int(lock2[i])
		c = abs(int(lock2[i]) - int(lock1[i]))
		if c < b:
			b = c
		count += b
print(count)


disk = int(input())
original = input()
comb = input()
clk = list(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
steps = []
for x in range(0, disk):
	s = original[x]
	d = comb[x]
	start = clk.index(s)
	end = clk.index(d)
	stepinc = 0
	stepdec = 0
	while start != end:
		start += 1
		start = start % 10
		stepinc += 1
	start = clk.index(s)
	end = clk.index(d)
	while start != end:
		start -= 1
		start = start % 10
		stepdec += 1
	steps.append(min(stepdec, stepinc))
print(sum(steps))


n = int(input())
start = input()
kod = input()
a = '0123456789'
b = '5678901234'
qty = 0
for i in range(n):
	if start[i] >= kod[i] and int(start[i]) - int(kod[i]) <= 4:
		qty = qty + int(start[i]) - int(kod[i])
	elif start[i] <= kod[i] and int(kod[i]) - int(start[i]) <= 4:
		qty = qty + int(kod[i]) - int(start[i])
	elif start[i] > kod[i]:
		qty = qty - b.find(start[i]) + b.find(kod[i])
	else:
		qty = qty + b.find(start[i]) - b.find(kod[i])
print(qty)


n = int(input())
a = input()
b = input()
turns = 0
for i in range(n):
	if int(a[i]) - int(b[i]) > 0:
		turns = turns + min(int(a[i]) - int(b[i]), 10 - (int(a[i]) - int(b[i])))
	else:
		turns = turns + min(int(b[i]) - int(a[i]), 10 + int(a[i]) - int(b[i]))
print(turns)


n = int(input())
start = input()
goal = input()
count = 0
for (s, g) in zip(start, goal):
	s = int(s)
	g = int(g)
	count += min(abs(s - g), abs(10 + s - g), abs(10 + g - s))
print(count)


n = int(input())
a = list(input())
b = list(input())
count = 0
for i in range(n):
	z = abs(int(a[i]) - int(b[i]))
	z = min(z, 10 - z)
	count += z
print(count)


n = 0
initial_config = []
goal_config = []

def read_input():
	global n, initial_config, goal_config
	n = int(input())
	initial_config = [int(i) for i in input()]
	goal_config = [int(i) for i in input()]

def solve():
	total_moves = 0
	for i in range(n):
		smaller_digit = min(initial_config[i], goal_config[i])
		bigger_digit = max(initial_config[i], goal_config[i])
		a = smaller_digit + 9 - bigger_digit + 1
		b = bigger_digit - smaller_digit
		total_moves = total_moves + min(a, b)
	return total_moves
read_input()
print(solve())


N = int(input())
A = list(map(int, list(input())))
B = list(map(int, list(input())))
C = 0
for (a, b) in list(zip(A, B)):
	D = abs(a - b)
	C += min(D, (10 - D) % 10)
print(C)


n = int(input())
code = input()
answer = input()
kol = 0
for i in range(n):
	if code[i] > answer[i]:
		kol += min(int(code[i]) - int(answer[i]), 10 - (int(code[i]) - int(answer[i])))
	else:
		kol += min(int(answer[i]) - int(code[i]), 10 - (int(answer[i]) - int(code[i])))
print(kol)


disks = int(input())
a = input()
b = input()
moves = 0
for z in range(disks):
	x = int(a[z])
	y = int(b[z])
	move = []
	if x > y:
		move.append(x - y)
	else:
		move.append(y - x)
	d1 = x + 10 - y
	d2 = y + 10 - x
	if d1 > d2:
		move.append(d2)
	else:
		move.append(d1)
	moves += min(move)
print(moves)


n = int(input())
that = str(input())
code = str(input())

def abos(number):
	if number < 0:
		number = -1 * number
	return number

def uncode(numb, ret):
	a = abos(ret - numb)
	if a > 5:
		a = 10 - a
	return a
hod = 0
for i in range(n):
	(a, b) = (int(that[i]), int(code[i]))
	hod += uncode(a, b)
print(hod)


n = int(input())
a = input()
b = input()
x = 0
for i in range(n):
	p = int(a[i]) - int(b[i])
	if p < 0:
		p = p * -1
	if p > 5:
		p = 10 - p
	x += p
print(x)


n = int(input())
s = [int(ss) for ss in input()]
res = [int(ss) for ss in input()]
sum = 0
for i in range(n):
	sum += min(abs(s[i] - res[i]), 10 - abs(s[i] - res[i]))
print(sum)


def possTurns(poss0, poss1):
	pos0 = poss0
	turns0 = 0
	pos1 = poss0
	turns1 = 0
	while pos0 != poss1:
		turns0 += 1
		pos0 += 1
		if pos0 == 10:
			pos0 = 0
	while pos1 != poss1:
		turns1 += 1
		pos1 -= 1
		if pos1 == -1:
			pos1 = 9
	return min(turns0, turns1)
turns = 0
for i in range(int(input())):
	if i == 0:
		lock = [int(x) for x in input()]
		lock0 = [int(x) for x in input()]
	turns += possTurns(lock[i], lock0[i])
print(turns)


n = int(input())
x = list(input())
y = list(input())
count = 0
for i in range(0, n):
	p = int(max(x[i], y[i]))
	q = int(min(x[i], y[i]))
	if p - q > 5:
		count = count + (q + (10 - p))
	else:
		count = count + (p - q)
print(count)


import math
n = int(input())
s1 = input()
s2 = input()
l = len(s1)
svar = 0
for i in range(0, l):
	x = abs(int(s1[i]) - int(s2[i]))
	y = abs(10 - int(s1[i]) + int(s2[i]))
	z = abs(int(s1[i]) + 10 - int(s2[i]))
	svar += min(x, y, z)
print(svar)


n1 = int(input())
n = input()
m = input()
(l, sum) = ([], 0)
for i in range(n1):
	if n[i] > m[i]:
		l.append(int(n[i]) - int(m[i]))
	else:
		l.append(int(m[i]) - int(n[i]))
for i in range(len(l)):
	if l[i] > 5:
		sum += 10 - l[i]
	else:
		sum += l[i]
print(sum)


n = int(input())
A = input()
B = input()
x = []
y = []
Sum = 0
for i in A:
	x.append(int(i))
for j in B:
	y.append(int(j))
for l in range(0, n):
	a = abs(x[l] - y[l])
	if a <= 5:
		Sum = Sum + a
	else:
		Sum = Sum + (10 - a)
print(Sum)


n = int(input())
a = list(input())
b = list(input())
c = 0
for i in range(n):
	c1 = 0
	c2 = 0
	a1 = a[i]
	b1 = b[i]
	a2 = a[i]
	b2 = b[i]
	while a1 != b1:
		if a1 == '9':
			a1 = int(a1)
			a1 = a1 - 9
			a1 = str(a1)
		else:
			a1 = int(a1)
			a1 = a1 + 1
			a1 = str(a1)
		c1 = c1 + 1
	while a2 != b2:
		if a2 == '0':
			a2 = int(a2)
			a2 = a2 + 9
			a2 = str(a2)
		else:
			a2 = int(a2)
			a2 = a2 - 1
			a2 = str(a2)
		c2 = c2 + 1
	c = c + min(c1, c2)
print(c)


n = 10
x = int(input())
s = input()
s1 = input()
total_ = 0
for i in range(0, x):
	temp = int(s[i]) - int(s1[i])
	if temp < 0:
		temp = -temp
	if temp > n // 2:
		temp = n - temp
	total_ += temp
print(total_)


def function(x, y):
	(x, y) = (int(x), int(y))
	if x > y:
		t = x
		x = y
		y = t
	return min(y - x, 10 - y + x)
k = int(input())
b = input()
t = input()
an = 0
for i in range(k):
	an += function(b[i], t[i])
print(an)


t = int(input())
a = input()
b = input()
a = list(a)
b = list(b)
c = 0
for i in range(t):
	a[i] = int(a[i])
	b[i] = int(b[i])
for i in range(len(a)):
	if abs(a[i] - b[i]) > 0 and abs(a[i] - b[i]) < 5:
		c += abs(a[i] - b[i])
	elif abs(a[i] - b[i]) > 0 and abs(a[i] - b[i]) >= 5:
		c += 10 - abs(a[i] - b[i])
print(c)


from sys import stdin
import math
n = int(stdin.readline())
a = stdin.readline()
b = stdin.readline()
res = 0
for i in range(0, n):
	k = math.fabs(int(a[i]) - int(b[i]))
	if k <= 5:
		res += k
	else:
		res += 10 - k
print(int(res))


def diff(a, b):
	(a, b) = (int(a), int(b))
	(a, b) = (max(a, b), min(a, b))
	return min(a - b, 10 - a + b)
n = input()
(a, b) = (input(), input())
print(sum(map(diff, a, b)))


input()
password = input()
shuffle = input()
rotations = 0
bigNo = 11
for i in range(len(password)):
	passInt = int(password[i])
	shuffleInt = int(shuffle[i])
	if passInt != shuffleInt:
		if abs(passInt - shuffleInt) > 5:
			bigNo = passInt if passInt > shuffleInt else shuffleInt
			smallNo = passInt if passInt < shuffleInt else shuffleInt
			cRotations = 10 - bigNo + smallNo
		else:
			cRotations = abs(passInt - shuffleInt)
	else:
		cRotations = 0
	rotations += cRotations
print(rotations)


n = int(input())
s1 = input()
s2 = input()
s1 = list(s1)
s2 = list(s2)
r = 0
for i in range(n):
	d1 = abs(int(s1[i]) - int(s2[i]))
	d2 = 10 - max(int(s1[i]), int(s2[i])) + min(int(s1[i]), int(s2[i]))
	d = min(d1, d2)
	r += d
print(r)


a = int(input())
b = input()
c = input()
count = 0
for i in range(a):
	a1 = int(b[i])
	a2 = int(c[i])
	ans = abs(a2 - a1)
	if ans > 5:
		ans = 10 - ans
	else:
		pass
	count += ans
print(count)


input()
ans = 0
for (x, y) in zip(input(), input()):
	ans += min((ord(x) - ord(y) + 10) % 10, (ord(y) - ord(x) + 10) % 10)
print(ans)


n = int(input())
t = list(map(int, input()))
k = list(map(int, input()))
sum = 0
for i in range(n):
	if abs(t[i] - k[i]) > 5:
		sum += 10 - abs(t[i] - k[i])
	else:
		sum += abs(t[i] - k[i])
print(sum)


n = int(input())
s1 = input()
s2 = input()
qtd = 0
for (n1, n2) in zip(s1, s2):
	n1 = int(n1)
	n2 = int(n2)
	qtd += min(abs(n1 - n2), 10 - abs(n1 - n2))
print(qtd)


n = int(input())
l = list(input())
r = list(input())
z = 0
t = []
for i in l:
	if abs(int(i) - int(r[z])) >= 6:
		if int(i) >= 6:
			d = 10 - int(i)
			w = d + int(r[z])
			t.append(w)
		else:
			d = int(i) - 0
			w = d + 10 - int(r[z])
			t.append(w)
	else:
		w = abs(int(i) - int(r[z]))
		t.append(w)
	z += 1
print(sum(t))


n = int(input())
a = input()
a = list(a)
b = input()
b = list(b)
c = 0
for i in range(len(a)):
	if abs(int(a[i]) - int(b[i])) < abs(min(int(a[i]), int(b[i])) + 10 - int(max(a[i], b[i]))):
		c = c + abs(int(a[i]) - int(b[i]))
	else:
		c = c + abs(min(int(a[i]), int(b[i])) + 10 - int(max(a[i], b[i])))
print(c)


n = int(input())
o = [int(i) for i in input()]
c = [int(i) for i in input()]
summ = 0
for i in range(n):
	diff = abs(o[i] - c[i])
	if diff > 5:
		ten = 10 - diff
		turn = ten
	else:
		turn = diff
	summ = summ + turn
print(summ)


n = int(input())
myState = list(map(int, input()))
ogState = list(map(int, input()))
forward = 0
backward = 0
cnt = 0
for i in range(len(myState)):
	if myState[i] == ogState[i]:
		continue
	elif myState[i] < ogState[i] or myState[i] > ogState[i]:
		forward = abs(ogState[i] - myState[i])
		backward = 10 - forward
	cnt += min(forward, backward)
print(cnt)


n = int(input())
start_combination = input()
combination_lock = input()
count = 0
for i in range(n):
	differ = abs(int(start_combination[i]) - int(combination_lock[i]))
	if differ <= 5:
		count += differ
	else:
		count += 10 - differ
print(count)


s = '0123456789' * 2
input()
a = input()
b = input()
print(sum([min((10 + s.rfind(a[i]) - s.find(b[i])) % 10, (10 + s.rfind(b[i]) - s.find(a[i])) % 10) for i in range(len(a))]))


import math
input()
n = input()
m = input()
s = 0
for i in range(len(n)):
	if math.fabs(int(n[i]) - int(m[i])) < 5:
		s = s + math.fabs(int(n[i]) - int(m[i]))
	else:
		s = s + 10 - math.fabs(int(n[i]) - int(m[i]))
print(int(s))


I = lambda : map(int, list(input()))
I()
s = 0
for (a, b) in zip(I(), I()):
	d = abs(b - a)
	s += min(d, 10 - d)
print(s)


(n, counter) = (int(input()), 0)
(start, code) = (input(), input())
for i in range(n):
	counter += min(abs(int(code[i]) - int(start[i])), abs(10 + int(code[i]) - int(start[i])), abs(-10 + int(code[i]) - int(start[i])))
print(counter)


n = int(input())
tmp = list(map(int, input()))
org = list(map(int, input()))
counter = 0
for _ in range(n):
	counter += min(abs(tmp[_] - org[_]), min(org[_] + 10 - tmp[_], tmp[_] + (10 - org[_])))
print(counter)


n = int(input())
original = input()
final = input()
resp = 0
for (cont, i) in enumerate(original):
	bla = int(i)
	(cont1, cont2, resp1, resp2) = (bla, bla, 0, 0)
	while cont1 != int(final[cont]):
		if cont1 == 9:
			cont1 = 0
			if cont1 == int(final[cont]):
				resp1 = resp1 + 1
				break
			resp1 = resp1 + 1
		cont1 = cont1 + 1
		resp1 = resp1 + 1
	while cont2 != int(final[cont]):
		if cont2 == 0:
			cont2 = 9
			if cont2 == int(final[cont]):
				resp2 = resp2 + 1
				break
			resp2 = resp2 + 1
		cont2 = cont2 - 1
		resp2 = resp2 + 1
	if resp1 <= resp2:
		resp = resp + resp1
	else:
		resp = resp + resp2
print(resp)


n = int(input())
a = input()
b = input()
ans = 0
for i in range(n):
	k = abs(int(a[i]) - int(b[i]))
	ans += min(k, 10 - k)
print(ans)


n = int(input())
c = input()
d = input()
e = []
f = []
for i in range(n):
	e.append(int(c[i]))
for i in range(n):
	f.append(int(d[i]))
ans = 0
for i in range(n):
	ans += min(abs(e[i] - f[i]), 10 - abs(e[i] - f[i]))
print(ans)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
n = get_int()
target = get_intList_from_str()
actual = get_intList_from_str()
moves = [0] * n
for i in range(n):
	moves[i] = min(abs(actual[i] - target[i]), 10 - abs(actual[i] - target[i]))
print(sum(moves))


n = int(input())
s1 = input()
st = input()
sum = 0
for i in range(n):
	sum += min(abs(int(st[i]) - int(s1[i])), 10 - int(s1[i]) + int(st[i]), 10 - int(st[i]) + int(s1[i]))
print(sum)


t = int(input())
init = list(map(int, list(list(input()))))
pw = list(map(int, list(list(input()))))
ans = 0
for r in range(0, t):
	p = [abs(init[r] - pw[r]), abs(10 - init[r] + pw[r]), abs(10 - pw[r] + init[r])]
	ans += min(p)
print(ans)


(n, s, f, t) = (int(input()), input(), input(), 0)
for i in range(0, n):
	q = min(int(s[i]) + 10 - int(f[i]), abs(int(s[i]) - 10) + int(f[i]))
	if abs(int(s[i]) - int(f[i])) < q:
		t += abs(int(s[i]) - int(f[i]))
	else:
		t += q
print(t)


dont_need = input()
locked = input()
opened = str(input())
moves = 0
for (i, e) in enumerate(locked):
	lock = opened[i]
	if abs(int(e) - int(lock)) > 5:
		if e > lock:
			(e, lock) = (lock, e)
		moves += 9 - int(lock) + 1 + int(e)
	else:
		moves += abs(int(e) - int(lock))
print(moves)


def solve(n, m):
	return min(abs(n - m), abs(10 + n - m), abs(10 + m - n))
n = int(input())
S = input()
T = input()
ans = 0
for (s, t) in zip(S, T):
	ans += solve(int(s), int(t))
print(ans)


import math
x = int(input())
str1 = input()
str2 = input()
i = 0
count = 0
while i < x:
	sum1 = 0
	sum1 = abs(int(str1[i]) - int(str2[i]))
	if sum1 > 5:
		sum1 = 10 - sum1
	count += sum1
	i += 1
print(count)


number = int(input())
code_start = input()
code_combination = input()
min_steps = 0
for i in range(number):
	min = abs(int(code_start[i]) - int(code_combination[i]))
	alternative_operation = abs(10 - int(code_start[i]) + int(code_combination[i]))
	if alternative_operation < min:
		min = alternative_operation
	alternative_operation = abs(int(code_start[i]) + 10 - int(code_combination[i]))
	if alternative_operation < min:
		min = alternative_operation
	min_steps += min
print(min_steps)


def main():
	n = int(input())
	initial = input()
	final = input()
	data = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
	sum = 0
	for i in range(n):
		a = int(initial[i])
		b = int(final[i])
		diff_front = 0
		diff_back = 0
		mylocation = 10 + a
		while 1:
			if data[mylocation] == str(final[i]):
				break
			diff_front += 1
			mylocation += 1
		mylocation = 10 + a
		while 1:
			if data[mylocation] == str(final[i]):
				break
			diff_back += 1
			mylocation -= 1
		if diff_front > diff_back:
			sum += diff_back
		else:
			sum += diff_front
	print(sum)
	return 0
main()


n = int(input())
s = input()
p = input()
ans = 0
for (x, y) in zip(s, p):
	(x, y) = (int(x), int(y))
	ans += min([abs(x - y), 10 - y + x, 10 - x + y])
print(ans)


def rotationClock(x, i):
	sum = 0
	while x != i:
		x = (x + 1) % 10
		sum += 1
	return sum

def rotationCounterClock(x, i):
	sum = 0
	while x != i:
		x = (x - 1) % 10
		sum += 1
	return sum
n = int(input())
start = int(input())
end = int(input())
total = 0
for i in range(n):
	total += min(rotationClock(start % 10, end % 10), rotationCounterClock(start % 10, end % 10))
	end //= 10
	start //= 10
print(total)


n = int(input())
a = list(input())
b = list(input())
ans = 0
for (i, j) in zip(a, b):
	ans += min(abs(int(i) - int(j)), 10 - abs(int(i) - int(j)))
print(ans)


n = int(input())
str1 = list(input())
str2 = list(input())
moves = 0
for i in range(0, n):
	tmp = abs(int(str1[i]) - int(str2[i]))
	if tmp > 10 - tmp:
		moves += 10 - tmp
	else:
		moves += tmp
print(moves)


n = int(input())
o = [int(x) for x in input()]
c = [int(x) for x in input()]
i = 0
ans = 0
while i < n:
	diff = abs(o[i] - c[i])
	diff2 = 10 - diff
	ans += diff if diff < diff2 else diff2
	i += 1
print(ans)


def diff(num1, num2):
	result = 0
	if num1 > num2:
		result = num1 - num2
	else:
		result = num2 - num1
	if result > 5:
		return 10 - result
	else:
		return result
n = int(input())
a = input()
b = input()
sum = 0
for x in range(n):
	sum += diff(int(a[x]), int(b[x]))
print(sum)


n = int(input())
ds = (abs(ord(v1) - ord(v2)) for (v1, v2) in zip(input(), input()))
print(sum(map(lambda v: min(v, 10 - v), ds)))


n = int(input())
s = str(input())
count = 0
m = str(input())
e = 0
for i in range(0, len(s)):
	a = abs(int(s[i]) - int(m[i]))
	b = abs(10 - int(a))
	if a > b:
		mins = b
	elif a < b:
		mins = a
	else:
		mins = a
	count = count + mins
print(count)


_ = input()
lock_keys = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
current_lock_state = [int(num) for num in input()]
unlock_combination = [int(num) for num in input()]
minimum_combination = 0
current_one = 0
for i in unlock_combination:
	forward_step = 0
	backward_step = 0
	if current_lock_state[current_one] == i:
		pass
	else:
		index_current_lock_f = lock_keys.index(current_lock_state[current_one])
		while True:
			index_current_lock_f += 1
			if index_current_lock_f == 10:
				index_current_lock_f = 0
			forward_step += 1
			test_f = lock_keys[index_current_lock_f]
			if test_f == i:
				break
			else:
				continue
		index_current_lock_b = lock_keys.index(current_lock_state[current_one])
		while True:
			index_current_lock_b -= 1
			backward_step += 1
			test_b = lock_keys[index_current_lock_b]
			if test_b == i:
				break
			else:
				continue
	current_one += 1
	if forward_step > backward_step:
		minimum_combination = minimum_combination + backward_step
	else:
		minimum_combination = minimum_combination + forward_step
print(minimum_combination)


n = int(input())
t = 0
s1 = input()
s2 = input()
for i in range(n):
	if abs(int(s1[i]) - int(s2[i])) < 10 - abs(int(s1[i]) - int(s2[i])):
		t += abs(int(s1[i]) - int(s2[i]))
	else:
		t += 10 - abs(int(s1[i]) - int(s2[i]))
print(t)


n = int(input())
a = input()
b = input()
sum = 0
for x in range(n):
	p = int(a[x])
	q = int(b[x])
	k = abs(p - q)
	if k < 6:
		sum += k
	else:
		sum += 10 - k
print(sum)


(n, m, o) = (int(input()), input(), input())
ans = 0
for i in range(n):
	(a, b) = (int(m[i]), int(o[i]))
	if a > b:
		ans += min(a - b, b + 10 - a)
	else:
		ans += min(b - a, a + 10 - b)
print(ans)


import sys

def func(x, y):
	(x, y) = (int(x), int(y))
	if x > y:
		t = x
		x = y
		y = t
	return min(y - x, 10 - y + x)
n = int(input())
s = input()
t = input()
ans = 0
for i in range(n):
	ans += func(s[i], t[i])
print(ans)


n = int(input())
combo_i = input().strip()
combo_f = input().strip()
moves = 0
for i in range(n):
	(initial, final) = (int(combo_i[i]), int(combo_f[i]))
	if initial != final:
		down = initial + (10 - final)
		up = 10 - initial + final
		moves += min(abs(final - initial), 10 - abs(final - initial))
print(moves)


ans = 0
n = int(input())
x = input()
y = input()
for i in range(n):
	digito = int(x[i])
	digitoy = int(y[i])
	ansAux = min(abs(digito + 10 - digitoy), min(abs(digito - (digitoy + 10)), abs(digito - digitoy)))
	ans += ansAux
print(ans)


n = int(input())
s1 = input()
s2 = input()
m = 0
for i in range(n):
	x = abs(int(s1[i]) - int(s2[i]))
	if x > 5:
		x = 10 - x
	m = m + x
print(m)


t = int(input())
z = 0
p = input()
q = input()
for i in range(t):
	x = abs(int(p[i]) - int(q[i]))
	if p[i] < q[i]:
		x2 = 10 - int(q[i]) + int(p[i])
	else:
		x2 = 10 - int(p[i]) + int(q[i])
	z += min(x, x2)
print(z)


n = int(input())
str1 = input()
str2 = input()

def calculate(a, b):
	max_num = max(int(a), int(b))
	min_num = min(int(a), int(b))
	c = max_num - min_num
	d = 9 - max_num + min_num - 0 + 1
	count = min(c, d)
	return count
length = len(str1)
count = 0
for i in range(length):
	count += calculate(str1[i], str2[i])
print(count)


n = int(input())
s = input()
s = list(s)
s1 = input()
s1 = list(s1)
c = 0
for i in range(n):
	if abs(int(s[i]) - int(s1[i])) > 5:
		c += 10 - abs(int(s[i]) - int(s1[i]))
	else:
		c += abs(int(s[i]) - int(s1[i]))
print(c)


n = int(input())
num1 = list(map(int, input()))
num2 = list(map(int, input()))
ans = 0
for (n1, n2) in zip(num1, num2):
	diff = abs(n1 - n2)
	ans += min(diff, 10 - diff)
print(ans)


n = int(input())
m = list(map(int, input()))
b = list(map(int, input()))
ans = 0
for i in range(n):
	ans += min(abs(m[i] - b[i]), min(m[i], b[i]) + 10 - max(m[i], b[i]))
print(ans)


n = int(input())
t = input()
g = input()
x = 0
y = 0
m = 0
while n > 0:
	x = abs(int(t[y]) - int(g[y]))
	if x > 5:
		m = m + (10 - x)
	else:
		m = m + x
	y = y + 1
	n = n - 1
print(m)


n = int(input())
ori = input()
tar = input()
s = 0
for i in range(n):
	x = abs(int(ori[i]) - int(tar[i]))
	y = 10 - x
	if x < y:
		s += x
	else:
		s += y
print(s)


code_size = int(input())
before = input()
after = input()
actions = 0
for x in range(0, code_size):
	a = int(before[x])
	b = int(after[x])
	flips = min(abs(a - b), abs(min(a, b) + 10 - max(a, b)))
	actions += flips
print(actions)


n = int(input())
c1 = input()
c2 = input()
t = 0
for i in range(n):
	t += min(abs(int(c1[i]) - int(c2[i])), -abs(int(c1[i]) - int(c2[i])) + 10)
print(t)


n = int(input())
cipher = input()
plain = input()
k = 0
for i in range(n):
	diff = abs(int(cipher[i]) - int(plain[i]))
	k = k + min(diff, 10 - diff)
print(k)


n = int(input())
ini = input()
fin = input()
count = 0
for i in range(n):
	dif = abs(int(ini[i]) - int(fin[i]))
	if dif > 5:
		dif = 10 - dif
	count = count + dif
print(count)


def driver(n, f, g):
	ans = 0
	f = [int(z) for z in f]
	g = [int(z) for z in g]
	for (x, y) in zip(f, g):
		ans += min(abs(x + 1 - (y + 1)), 10 - abs(x + 1 - (y + 1)))
	print(ans)

def main():
	n = int(input())
	f = input()
	g = input()
	f = list(f)
	g = list(g)
	driver(n, f, g)
main()


a = int(input())
b = input('')
c = input('')
d = 0
for (i, j) in zip(b, c):
	e = int(i)
	f = int(j)
	g = abs(e - f)
	if g < 10 - g:
		d = d + g
	else:
		d = d + (10 - g)
print(d)


n = int(input())
x = list(map(int, input()))
y = list(map(int, input()))
s = 0
for i in range(n):
	s += min(abs(x[i] - y[i]), 10 - abs(x[i] - y[i]))
print(s)


count = int(input())
source = input()
target = input()
num = 0
for i in range(0, count):
	disk = int(target[i]) - int(source[i])
	if abs(disk) <= 5:
		num += abs(disk)
	else:
		num += 10 - abs(disk)
print(num)


n = int(input())
dst = input()
src = input()
step = 0
for i in range(n):
	mov = abs(ord(dst[i]) - ord(src[i]))
	if mov > 5:
		mov = 10 - mov
	step += mov
print(step)


n = int(input())
a = input()
b = input()
a = list(a)
b = list(b)
sum = 0
for i in range(n):
	x = abs(int(a[i]) - int(b[i]))
	y = min(x, 10 - x)
	sum = sum + y
print(sum)


n = int(input())
a = list(input())
b = list(input())
ncount = 0
for i in range(n):
	c = max(int(a[i]), int(b[i]))
	d = min(int(a[i]), int(b[i]))
	e = c - d
	f = 10 - c + d
	ncount += min(e, f)
print(ncount)


n = int(input())
ish = input()
kod = input()
k = 0
for i in range(n):
	if ish[i] == kod[i]:
		k = k + 0
	else:
		k = k + min([abs(int(ish[i]) - int(kod[i])), int(min([ish[i], kod[i]])) + 10 - int(max([ish[i], kod[i]]))])
print(k)


n = int(input())
s = input()
r = input()
si = list(s)
ri = list(r)
for i in range(0, n):
	si[i] = int(si[i])
	ri[i] = int(ri[i])
sum = 0
for i in range(0, n):
	trnp = si[i] - ri[i]
	trn = abs(trnp)
	if trn > 5:
		trn = 10 - trn
	sum = sum + trn
print(sum)


n = int(input())
a1 = input()
a2 = input()
sm = 0
for i in range(n):
	q = int(a1[i])
	w = int(a2[i])
	sm += min(abs(q - w), min(q, w) + 10 - max(q, w))
print(sm)


n = int(input())
isx = str(input())
cod = str(input())
c = []
if 1 <= n <= 1000 and len(isx) == len(cod) == n:
	for i in range(len(isx)):
		if isx[i] == cod[i]:
			c.append(0)
		elif isx[i] != cod[i]:
			a = abs(int(isx[i]) - int(cod[i]))
			b = 10 - a
			if a <= b:
				c.append(a)
			else:
				c.append(b)
	k = sum(c)
	print(k)


n = int(input())
p = input()
k = input()
k1 = 0
c = 0
for i in range(n):
	k1 = abs(int(p[i]) - int(k[i]))
	if k1 >= 5:
		c = c + 10 - k1
	else:
		c = c + k1
print(c)


n = int(input())
aux = list(input())
aux2 = list(input())
init = list()
goal = list()
for i in range(n):
	init.append(int(aux[i]))
	goal.append(int(aux2[i]))
answer = 0
for i in range(n):
	answer += min(10 - abs(init[i] - goal[i]), abs(init[i] - goal[i]))
print(answer)


length = int(input())
number1 = input()
number2 = input()
counter = 0
for i in range(length):
	diff = abs(int(number1[i]) - int(number2[i]))
	if diff > 5:
		counter += 10 - diff
	else:
		counter += diff
print(counter)


n = int(input())
s = input()
p = input()
count = 0
for i in range(n):
	if abs(int(s[i]) - int(p[i])) <= 5:
		count += abs(int(s[i]) - int(p[i]))
	else:
		count += 10 - abs(int(s[i]) - int(p[i]))
print(count)


def u(x, y):
	(x, y) = (int(x), int(y))
	if x > y:
		r = x
		x = y
		y = r
	return min(y - x, 10 - y + x)
g = int(input())
w = input()
r = input()
ans = 0
for i in range(g):
	ans += u(w[i], r[i])
print(ans)


def min_move(ia, ib):
	dn = abs(ia - ib)
	if ia >= 5:
		dm = 9 - ia
		dm += ib
	else:
		dm = ia
		dm += 9 - ib + 1
	if dn < dm:
		ret = dn
	else:
		ret = dm
	return ret
input()
a = [str(i) for i in str(input())]
b = [str(i) for i in str(input())]
cf_sum = 0
for i in range(0, len(a)):
	if int(a[i]) < int(b[i]):
		cf_sum += min_move(int(a[i]), int(b[i]))
	else:
		cf_sum += min_move(int(b[i]), int(a[i]))
print(cf_sum)


n = int(input())
s = input()
p = input()
count = 0
for i in range(n):
	if int(s[i]) > int(p[i]):
		mini = min(int(s[i]) - int(p[i]), 10 - int(s[i]) + int(p[i]))
		count += mini
	elif int(p[i]) > int(s[i]):
		mini = min(int(p[i]) - int(s[i]), 10 - int(p[i]) + int(s[i]))
		count += mini
print(count)


from math import fabs as f
n = int(input())
k1 = input()
k2 = input()
c = 0
for i in range(n):
	c += min(f(int(k1[i]) - int(k2[i])), 10 - f(int(k1[i]) - int(k2[i])))
print(int(c))


n = int(input())
s = input().strip()
r = input().strip()
result = 0
for i in range(len(s)):
	x = abs(int(s[i]) - int(r[i]))
	result += min(x, 10 - x)
print(result)


import math
n = int(input())
x = [int(k) for k in list(input())]
l = [int(k) for k in list(input())]
sum = 0
for i in range(n):
	sum += min(int(math.fabs(x[i] - l[i])), 10 - int(math.fabs(x[i] - l[i])))
print(sum)


def codeforces():
	n = int(input())
	st1 = input()
	st2 = input()
	count = 0
	for i in range(n):
		count_up = 0
		count_down = 0
		while (int(st1[i]) + count_up) % 10 != int(st2[i]):
			count_up += 1
		while (int(st1[i]) - count_down) % 10 != int(st2[i]):
			count_down += 1
		count += min(count_down, count_up)
	return count
print(codeforces())


x = int(input())
y = input()
z = input()
d = 0
for i in range(x):
	if abs(int(z[i]) - int(y[i])) < 3:
		d += min(10 - abs(int(z[i]) - int(y[i])), abs(int(z[i]) - int(y[i])))
	else:
		d += min(10 - abs(int(z[i]) - int(y[i])), abs(int(z[i]) - int(y[i])))
print(d)


def main():
	n = int(input())
	lock = input()
	desired = input()
	ans = 0
	for (src, dest) in zip(lock, desired):
		x = min(abs(int(src) - int(dest)), abs(10 + int(dest) - int(src)), abs(10 + int(src) - int(dest)))
		ans += x
	print(ans)
main()


x = int(input())
y = input()
z = input()
s = [int(n) + 1 for n in y]
t = [int(n) + 1 for n in z]
m = 0
for n in range(x):
	m += 5 - abs(5 - abs(s[n] - t[n]))
print(m)


disks = int(input())
x = str(input())
y = str(input())
move = 0

def unlock(x, y, move):
	for i in range(len(x)):
		if x[i] > y[i]:
			if int(x[i]) - int(y[i]) > 5:
				move += 10 - (int(x[i]) - int(y[i]))
			else:
				move += int(x[i]) - int(y[i])
		elif int(y[i]) - int(x[i]) > 5:
			move += 10 - (int(y[i]) - int(x[i]))
		else:
			move += int(y[i]) - int(x[i])
	print(move)
unlock(x, y, move)


a = int(input())
x = str(input())
y = str(input())
sum = 0
for i in range(a):
	if x[i] > y[i]:
		sum = sum + min(int(x[i]) - int(y[i]), 10 - (int(x[i]) - int(y[i])))
	elif x[i] < y[i]:
		sum = sum + min(int(y[i]) - int(x[i]), 10 - (int(y[i]) - int(x[i])))
print(sum)


n = int(input())
s1 = input()
s2 = input()
count = 0
for i in range(len(s1)):
	forward = abs(int(s1[i]) - int(s2[i]))
	backward = 10 - abs(int(s1[i]) - int(s2[i]))
	count += min(forward, backward)
print(count)


n = int(input())
s = input()
s1 = input()
su = 0
for i in range(n):
	su += min(abs(int(s1[i]) - int(s[i])), 10 - abs(int(s1[i]) - int(s[i])))
print(su)


n = int(input())
start = input()
end = input()
list1 = [int(i) for i in start]
list2 = [int(i) for i in end]
time = 0
for i in range(n):
	if abs(list1[i] - list2[i]) <= 5:
		time += abs(list1[i] - list2[i])
	elif list1[i] - list2[i] > 5:
		time += list2[i] + 2 * 5 - list1[i]
	else:
		time += list1[i] + 2 * 5 - list2[i]
print(time)


n = int(input())
ori = [int(i) for i in list(input())]
key = [int(i) for i in list(input())]
move = 0
for i in range(n):
	if ori[i] <= key[i]:
		move += min(key[i] - ori[i], ori[i] + 10 - key[i])
	else:
		move += min(ori[i] - key[i], key[i] + 10 - ori[i])
print(move)


n = int(input())
nach = input()
cod = input()
kv = 0
for i in range(n):
	if int(cod[i]) >= int(nach[i]):
		k = min(int(cod[i]) - int(nach[i]), 10 + int(nach[i]) - int(cod[i]))
	else:
		k = min(int(nach[i]) - int(cod[i]), 10 + int(cod[i]) - int(nach[i]))
	kv = kv + k
print(kv)


n = int(input())
palsu = input()
asli = str(input())
count = 0
for i in range(n):
	if abs(int(asli[i]) - int(palsu[i])) < 6:
		count += abs(int(asli[i]) - int(palsu[i]))
	else:
		count += abs(10 - abs(int(asli[i]) - int(palsu[i])))
print(count)


n = int(input())
origin = input()
target = input()
Result = 0
for i in range(n):
	sub = abs(int(origin[i]) - int(target[i]))
	if sub > 5:
		sub = 10 - sub
	Result += sub
print(Result)


__author__ = 'Andrey'
n = int(input())
n_1 = input()
n_2 = input()
s = 0
for i in range(n):
	c_1 = int(n_1[i])
	c_2 = int(n_2[i])
	s += min(abs(c_1 - c_2), abs(10 - abs(c_1 - c_2)))
print(s)


def main():
	from sys import stdin, stdout
	n = int(stdin.readline())
	a = stdin.readline().strip()
	b = stdin.readline().strip()
	counter = 0
	for i in range(n):
		x = int(a[i])
		y = int(b[i])
		counter += min(abs(x - y), min(x, y) + 10 - max(x, y))
	stdout.write(str(counter))
main()


a = int(input())
b = input()
c = input()
count = 0
for i in range(a):
	if int(b[i]) - int(c[i]) <= 5 and int(b[i]) - int(c[i]) >= -5:
		if int(b[i]) - int(c[i]) > 0:
			count += int(b[i]) - int(c[i])
		else:
			count += -(int(b[i]) - int(c[i]))
	elif int(b[i]) - int(c[i]) >= 5:
		count += 10 - (int(b[i]) - int(c[i]))
	else:
		count += 10 + (int(b[i]) - int(c[i]))
print(count)


num = int(input())
a = '0123456789'
key1 = input()
key2 = input()
min = 0
dis = 0
for i in range(0, num):
	clock = abs(a.index(key1[i]) - a.index(key2[i]))
	antiClock = 0
	if a.index(key1[i]) < a.index(key2[i]):
		antiClock = a.index(key1[i]) + (10 - a.index(key2[i]))
	elif a.index(key1[i]) > a.index(key2[i]):
		antiClock = a.index(key2[i]) + (10 - a.index(key1[i]))
	dis = clock
	if clock > antiClock:
		dis = antiClock
	min = min + dis
print(min)


import math, string, itertools, fractions, heapq, collections, re, array, bisect
from sys import stdin, stdout
n = int(stdin.readline())
sd = str(stdin.readline()).strip()
ed = str(stdin.readline()).strip()
sd = str(sd)
ed = str(ed)
s = 0
for (i, y) in zip(sd, ed):
	i = int(i)
	y = int(y)
	s = s + min(abs(i - y), 10 - abs(i - y))
stdout.write(str(s) + '\n')


n = int(input())
st = int(input())
st1 = int(input())
c = 0
for i in range(n):
	a = int(st // 10 ** i - st // 10 ** (i + 1) * 10)
	b = int(st1 // 10 ** i - st1 // 10 ** (i + 1) * 10)
	if abs(a - b) > 5:
		c += 10 - abs(a - b)
	else:
		c += abs(a - b)
print(c)


n = int(input())
a = input()
b = input()
res = 0
temp = 0
for i in range(n):
	x = int(a[i]) - int('0')
	y = int(b[i]) - int('0')
	if x > y:
		temp = x - y
	else:
		temp = y - x
	if temp < 5:
		res = res + temp
	else:
		res = res + 10 - temp
print(res)


import math
n = int(input())
c = input()
a = input()
steps = 0
for i in range(n):
	diff = abs(int(a[i]) - int(c[i]))
	steps = steps + min(diff, 10 - diff)
print(steps)


disks = int(input())
originalState = input()
secretNumber = input()
digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
totalMinMoves = 0

def minStepsFromXtoY(x, y):
	steps2 = 0
	if x == y:
		return 0
	else:
		if x > y:
			steps1 = x - y
		elif y > x:
			steps1 = y - x
		if x > y:
			for i in range(digits.index(x), 19, 1):
				if digits[i] == y:
					break
				else:
					steps2 += 1
					continue
		elif y > x:
			for i in range(digits.index(y), 19, 1):
				if digits[i] == x:
					break
				else:
					steps2 += 1
					continue
		if steps1 > steps2 or steps1 == steps2:
			return steps2
		else:
			return steps1
for i in range(0, len(originalState)):
	totalMinMoves += minStepsFromXtoY(int(originalState[i]), int(secretNumber[i]))
print(totalMinMoves)


def combination_lock(a, b, n):
	a = [int(i) for i in a]
	b = [int(i) for i in b]
	count = 0
	for i in range(n):
		k1 = abs(a[i] - b[i])
		k2 = 10 - a[i] + b[i]
		k3 = 10 - b[i] + a[i]
		k_final = min(k1, k2, k3)
		count = count + k_final
	print(count)
n = int(input(''))
a = input('')
b = input('')
combination_lock(list(a), list(b), n)


def get(a, b):
	c = 9 - b + (a + 1)
	d = 9 - a + (b + 1)
	if a < b:
		(a, b) = (b, a)
	return min(a - b, c, d)
n = int(input())
a = input()
b = input()
s = 0
for i in range(n):
	s += get(int(a[i]), int(b[i]))
print(s)


a = int(input())
b = list(map(int, input()))
c = list(map(int, input()))
d = 0
for i in range(a):
	e = abs(b[i] - c[i])
	d += min(e, 10 - e)
print(d)


t = int(input())
s1 = str(input())
s2 = str(input())

def func(a, b):
	if b > a:
		d = a
		(a, b) = (b, d)
	c = a - b
	if c > 5:
		c = 10 - c
	return c
r = 0
for i in range(t):
	d = func(int(s1[i]), int(s2[i]))
	r += d
print(r)


def count_actions(initial, final, n):
	return sum((min((final[i] - initial[i]) % 10, (initial[i] - final[i]) % 10) for i in range(n)))

def main():
	n = int(input())
	initial = list(map(int, input()))
	final = list(map(int, input()))
	print(count_actions(initial, final, n))
main()


n = int(input())
orig = input()
combin = input()
word = 0
for i in range(n):
	num = abs(int(orig[i]) - int(combin[i]))
	par = (int(orig[i]), int(combin[i]))
	if num > 5:
		r = 10 - max(par) + min(par)
		word += r
	else:
		word += num
print(word)


n = int(input())
a = input()
b = input()
ar = []
ar2 = []
for i in range(n):
	ar.append(int(a[i]))
for j in range(n):
	ar2.append(int(b[j]))
ans = 0
for i in range(n):
	ans += min(abs(ar[i] - ar2[i]), 10 - abs(ar[i] - ar2[i]))
print(ans)


n = int(input())
now = [int(i) for i in list(input())]
key = [int(i) for i in list(input())]
t = 0
for i in range(n):
	t += min(abs(now[i] - key[i]), 10 - abs(now[i] - key[i]))
print(t)


inputs = []
for i in range(3):
	inpt = input()
	inputs.append(inpt)
res = 0
for i in zip(inputs[1], inputs[2]):
	if int(i[0]) == int(i[1]):
		pass
	elif abs(int(i[0]) - int(i[1])) >= 6:
		if int(i[0]) < int(i[1]):
			res += int(i[0]) + (10 - int(i[1]))
		else:
			res += int(i[1]) + (10 - int(i[0]))
	elif int(i[0]) > int(i[1]):
		res += int(i[0]) - int(i[1])
	else:
		res += int(i[1]) - int(i[0])
print(res)


n = int(input())
ori_state = [int(i) for i in list(input())]
sec_combination = [int(i) for i in list(input())]
min_num = 0
for i in range(n):
	tmp1 = abs(ori_state[i] - sec_combination[i])
	tmp2 = min(ori_state[i], sec_combination[i]) + 10 - max(ori_state[i], sec_combination[i])
	tmp3 = min(tmp1, tmp2)
	min_num += tmp3
print(min_num)


n = int(input())
a = [0] * n
for b in range(2):
	c = 0
	for i in input():
		a[c] = abs(a[c] - int(i))
		c += 1
print(sum([5 - abs(5 - d) for d in a]))


input()
l = []
for tmp in input().strip('\n\r\t '):
	l.append(int(tmp))
c = 0
for (i, tmp) in enumerate(input().strip('\n\r\t ')):
	ss = int(tmp)
	c += min(abs(ss - l[i]), min(ss, l[i]) + 10 - max(ss, l[i]))
print(c)


import math

def f():
	x = int(input())
	t = 0
	str1 = input()
	str2 = input()
	for a in range(x):
		f = math.fabs(int(str1[a]) - int(str2[a]))
		if f >= 5:
			t += 10 - f
		else:
			t += f
	print(int(t))
f()


def find_dif(a, b):
	if a > b:
		aux = b
		b = a
		a = aux
	c = b - 10
	if b - a < a - c:
		return b - a
	else:
		return a - c
n = int(input())
initial_code = list(map(int, list(input())))
final_code = list(map(int, list(input())))
count = 0
for (x, y) in zip(initial_code, final_code):
	count += find_dif(x, y)
print(count)


from math import fabs
n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
k = 0
for (i, j) in zip(a, b):
	if fabs(i - j) > 5:
		if i > j:
			k += j + 10 - i
		else:
			k += i + 10 - j
	else:
		k += int(fabs(i - j))
print(k)


n = int(input())
l1 = list(input())
l2 = list(input())
ans = 0
for i in range(n):
	(a, b) = (int(l1[i]), int(l2[i]))
	if a > b:
		(a, b) = (b, a)
	if b > a:
		c1 = b - a
		c2 = a + 1 + 9 - b
		ans += min(c1, c2)
print(ans)


num = int(input())
ini = input()
fin = input()
cant_mov = 0
for i in range(num):
	if abs(int(ini[i]) - int(fin[i])) < 5:
		cant_mov = cant_mov + abs(int(ini[i]) - int(fin[i]))
	else:
		cant_mov = cant_mov + 10 - abs(int(ini[i]) - int(fin[i]))
print(cant_mov)


n = int(input())
str1 = input()
str2 = input()
count = 0
for x in range(n):
	a = int(str1[x])
	b = int(str2[x])
	count += min(abs(b - a), 10 - max(a, b) + min(a, b))
print(count)


(l, p, q) = [input() for _ in [1, 2, 3]]
c = 0
for i in range(int(l)):
	c += min(abs(int(p[i]) - int(q[i])), 10 - abs(int(p[i]) - int(q[i])))
print(c)


n = int(input())
s1 = input()
s2 = input()
answ = 0
for i in range(n):
	n1 = int(s1[i])
	n2 = int(s2[i])
	n3 = 10 - max(n1, n2) + min(n1, n2)
	if abs(n1 - n2) < n3:
		answ += abs(n1 - n2)
	else:
		answ += n3
print(answ)


a = int(input())
b = input()
c = input()
sum = 0
for k in range(a):
	d = int(b[k])
	e = int(c[k])
	if e > d:
		sum += min(d - e + 10, e - d)
	else:
		sum += min(10 - d + e, d - e)
print(sum)


n = int(input())
a = [int(i) for i in input()]
b = [int(i) for i in input()]
res = 0
for i in range(n):
	l = min(a[i], b[i])
	r = max(a[i], b[i])
	res += min(r - l, 10 - r + l)
print(res)


n = int(input())
a = list(map(int, ' '.join(input()).split()))
b = list(map(int, ' '.join(input()).split()))
c = 0
for i in range(n):
	c += min((a[i] - b[i]) % 10, (b[i] - a[i]) % 10)
print(c)


n = int(input())
s1 = input()
s2 = input()
a1 = []
a2 = []
for i in range(n):
	a1.append(int(s1[i]))
	a2.append(int(s2[i]))
s = 0
for i in range(n):
	d1 = abs(a1[i] - a2[i])
	d2 = abs(10 - a1[i] + a2[i])
	d3 = abs(10 - a2[i] + a1[i])
	d = min(d1, d2, d3)
	s += d
print(s)


res = 0
o = input()
o1 = input()
o2 = input()
for i in range(int(o)):
	if abs(int(o1[i]) - int(o2[i])) > 5:
		res += 10 - abs(int(o1[i]) - int(o2[i]))
	else:
		res += abs(int(o1[i]) - int(o2[i]))
print(res)


n = int(input())
i = [int(x) for x in input().strip()]
t = [int(x) for x in input().strip()]
sum = 0
for x in range(len(i)):
	r = abs(i[x] - t[x])
	sum += min(r, 10 - r)
print(sum)


y = int(input())
x = input()
z = input()
i = 0
s = 0
while i < y:
	a = int(x[i])
	b = int(z[i])
	if a - b >= 5:
		b = b + 10
		s += b - a
	elif b - a >= 5:
		a += 10
		s += a - b
	elif a >= b:
		s += a - b
	elif b > a:
		s += b - a
	i += 1
print(s)


n = int(input())
s1 = input()
s2 = input()
sun = 0
for i in range(len(s1)):
	if s1[i] == '1' and s2[i] == '9' or (s2[i] == '1' and s1[i] == '9'):
		sun += 2
	elif s1[i] == '1' and s2[i] == '8' or (s2[i] == '1' and s1[i] == '8'):
		sun += 3
	elif s1[i] == '1' and s2[i] == '7' or (s2[i] == '1' and s1[i] == '7'):
		sun += 4
	elif s1[i] == '0' and s2[i] == '9' or (s2[i] == '0' and s1[i] == '9'):
		sun += 1
	elif s1[i] == '0' and s2[i] == '8' or (s2[i] == '0' and s1[i] == '8'):
		sun += 2
	elif s1[i] == '0' and s2[i] == '7' or (s2[i] == '0' and s1[i] == '7'):
		sun += 3
	elif s1[i] == '0' and s2[i] == '6' or (s2[i] == '0' and s1[i] == '6'):
		sun += 4
	elif s1[i] == '2' and s2[i] == '9' or (s2[i] == '2' and s1[i] == '9'):
		sun += 3
	elif s1[i] == '2' and s2[i] == '8' or (s2[i] == '2' and s1[i] == '8'):
		sun += 4
	elif s1[i] == '3' and s2[i] == '9' or (s2[i] == '3' and s1[i] == '9'):
		sun += 4
	else:
		sun += max(int(s1[i]), int(s2[i])) - min(int(s1[i]), int(s2[i]))
print(sun)


def Lock(n, a, b):
	count = 0
	for i in range(n):
		j = int(a[i])
		k = int(b[i])
		if abs(j - k) > abs(10 + k - j):
			count = count + abs(10 + k - j)
		elif abs(j - k) > abs(10 + j - k):
			count = count + abs(10 + j - k)
		else:
			count = count + abs(j - k)
	return count
x = int(input())
a = input()
b = input()
print(Lock(x, a, b))


n = int(input())
l = input()
m = input()
l = list(map(int, l))
m = list(map(int, m))
p = min
cnt = 0
for i in range(n):
	if l[i] < m[i]:
		sum1 = 10 + l[i] - m[i]
	elif l[i] > m[i]:
		sum1 = 10 + m[i] - l[i]
	else:
		sum1 = 0
	cnt += p(sum1, abs(l[i] - m[i]))
print(cnt)


def print_lst(lst):
	print(' '.join(lst))
input()
a = list(map(int, list(input())))
b = list(map(int, list(input())))
r = 0
for i in range(len(a)):
	if abs(a[i] - b[i]) > 5:
		r += 10 - abs(a[i] - b[i])
	else:
		r += abs(a[i] - b[i])
print(r)


n = input()
n = int(n)
original = input()
real = input()
original_list = [int(i) for i in list(original)]
real_list = [int(i) for i in list(real)]
moves = 0
for i in range(n):
	moves_down = original_list[i] - real_list[i]
	if moves_down < 0:
		moves_down = -moves_down
	moves_up = 10 + real_list[i] - original_list[i]
	moves_up_2 = 10 + original_list[i] - real_list[i]
	moves += min(moves_down, moves_up, moves_up_2)
print(moves)


n = int(input())
t = list(input())
k = list(input())
count = 0
for i in range(len(t)):
	a = abs(int(t[i]) - int(k[i]))
	b = abs(10 + min(int(t[i]), int(k[i])) - max(int(t[i]), int(k[i])))
	count += min(a, b)
print(count)


n = int(input())
x = input()
y = input()
ans = 0
for i in range(n):
	val = abs(int(x[i]) - int(y[i]))
	val = min(val, 10 - val)
	ans += val
print(ans)


n = int(input())
code1 = input()
code2 = input()
answ = 0
for i in range(len(code1)):
	if abs(int(code1[i]) - int(code2[i])) > 5:
		answ += 10 - abs(int(code1[i]) - int(code2[i]))
	else:
		answ += abs(int(code1[i]) - int(code2[i]))
print(answ)


def func(a, b):
	cnt = 0
	for i in range(n):
		x = ord(a[i]) - ord('0')
		y = ord(b[i]) - ord('0')
		cnt += min(abs(x - y), 10 - abs(x - y))
	return cnt
n = int(input())
a = input()
b = input()
print(func(a, b))


n = int(input())
a1 = input().strip()
a2 = input().strip()
res = 0
for i in range(n):
	symbA1 = int(a1[i])
	symbA2 = int(a2[i])
	res += min(abs(symbA2 - symbA1), abs(min(symbA2, symbA1) + 10 - max(symbA1, symbA2)))
print(res)


n = int(input())
l1 = [int(i) for i in input()]
l2 = [int(i) for i in input()]
k = 0
for i in range(n):
	(a, b) = (min(l1[i], l2[i]), max(l1[i], l2[i]))
	u = min(10 - b + a, b - a)
	k += u
print(k)


n = int(input())
n1 = input()
n2 = input()
(i, ans) = (0, 0)
while i < n:
	(a, b) = (ord(n1[i]) - 48, ord(n2[i]) - 48)
	if a > b:
		ans += min(10 - a + b, abs(a - b))
	elif a < b:
		ans += min(a + 10 - b, abs(a - b))
	i += 1
print(ans)


n = int(input())
ch1 = str(input())
ch2 = str(input())
r = 0
for k in range(n):
	a = int(ch1[k])
	b = int(ch2[k])
	r += min(abs(a - b), abs(a + 10 - b), abs(a - 10 - b))
print(r)


n = int(input())
line1 = [int(i) for i in input()]
line2 = [int(i) for i in input()]
op = 0
for i in range(n):
	op += min(abs(line1[i] - line2[i]), 10 - abs(line1[i] - line2[i]))
print(op)


n = int(input())
na = input()
a = []
for h in na:
	a.append(int(h))
nb = input()
b = []
for h in nb:
	b.append(int(h))
res = 0
for i in range(0, len(a)):
	ab = abs(a[i] - b[i])
	if ab <= 5:
		res += ab
	elif a[i] > b[i]:
		b[i] += 10
		ab = abs(a[i] - b[i])
		res += ab
	else:
		a[i] += 10
		ab = abs(a[i] - b[i])
		res += ab
print(res)


__author__ = 'runekri3'
n = int(input())
first_l = list(map(int, input()))
second_l = list(map(int, input()))
total_moves = 0
for (first, second) in zip(first_l, second_l):
	difference = abs(first - second)
	if difference > 5:
		difference = 10 - difference
	total_moves += difference
print(total_moves)


n = int(input())
oc = list(map(int, list(input())))
ac = list(map(int, list(input())))
c = 0
for i in range(n):
	c += min(abs(oc[i] - ac[i]), abs(9 - oc[i]) + ac[i] + 1, abs(9 - ac[i]) + oc[i] + 1)
print(c)


n = int(input())
ori = list(map(int, input()))
com = list(map(int, input()))
inc = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
dec = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]
sum1 = 0
for (i, j) in zip(ori, com):
	incx = abs(inc.index(i) - inc.index(j))
	count = 0
	ind = dec.index(min(i, j))
	for k in range(20):
		if dec[(ind + k) % 10] != max(j, i):
			count += 1
		else:
			break
	sum1 += min(count, incx)
print(sum1)


n = input()
n = int(n)
s1 = input()
s2 = input()
c = 0
for i in range(n):
	p = abs(int(s1[i]) - int(s2[i]))
	f = abs(9 - int(s1[i]) + int(s2[i])) + 1
	l = abs(int(s1[i]) + 9 - int(s2[i]) + 1)
	c = c + min(p, min(f, l))
print(c)


n1 = input()
code_random = str(input())
code_ok = str(input())
oborot = 0
for i in range(len(code_ok)):
	delta = abs(int(code_random[i]) - int(code_ok[i]))
	if delta < 5:
		oborot += delta
	else:
		oborot += 10 - delta
print(oborot)


n = int(input())
s1 = input()
s2 = input()
x = 0
y = 0
ct = 0
for i in range(0, n):
	x = max(int(s1[i]), int(s2[i]))
	y = min(int(s1[i]), int(s2[i]))
	if x - y <= 5:
		ct += x - y
	else:
		ct += 56 - x + y - 47 + 1
print(ct)


n = input()
s = input()
s1 = input()
count = 0
l = list(map(int, s))
l1 = list(map(int, s1))
for i in range(len(l)):
	count = count + min(abs(l[i] - l1[i]), 10 - abs(l1[i] - l[i]))
print(count)


n = int(input())
state0 = [int(x) for x in input().rstrip()]
state1 = [int(x) for x in input().rstrip()]
print(sum((min((state0[i] - state1[i]) % 10, (state1[i] - state0[i]) % 10) for i in range(n))))


n = int(input())
a = input()
b = input()
c = 0
for (i, j) in zip(a, b):
	c = c + min(10 - abs(int(i) - int(j)), abs(int(i) - int(j)))
print(c)


n = int(input())
a = input()
b = input()
s = 0
for i in range(0, n):
	ai = ord(a[i])
	bi = ord(b[i])
	s += min(abs(ai - bi), abs(10 + ai - bi), abs(ai - (bi + 10)))
print(s)


n = int(input())
s1 = input().strip()
s2 = input().strip()
ans = 0
for i in range(n):
	(a, b) = (int(s1[i]), int(s2[i]))
	if a > b:
		(a, b) = (b, a)
	ans += min(b - a, 9 - b + a + 1)
print(ans)


n = int(input())
k = input()
l = input()
ans = 0
for i in range(0, n):
	x = int(k[i])
	y = int(l[i])
	a = abs(x - y)
	if a > 5:
		a = 10 - a
	ans += a
print(ans)


n = int(input())
s = input()
s1 = input()
ans = 0
for i in range(n):
	ans += min(abs(ord(s[i]) - ord(s1[i])), 10 + ord(s[i]) - ord(s1[i]), 10 + ord(s1[i]) - ord(s[i]))
print(ans)


n = int(input())
original = list((int(i) for i in input()))
unlock = list((int(i) for i in input()))
step = 0
for i in range(n):
	dif = max(original[i], unlock[i]) - min(original[i], unlock[i])
	if dif > 5:
		step = step + 10 - dif
	else:
		step = step + dif
print(step)


n = int(input())
s1 = input()
s2 = input()
res = 0
for i in range(n):
	x = int(s1[i])
	y = int(s2[i])
	if abs(x - y) > 5:
		res += 10 - abs(x - y)
	else:
		res += abs(x - y)
print(res)


n = int(input())
isx = input()
komb = input()
p = 0
for i in range(n):
	if int(isx[i]) > int(komb[i]):
		if int(isx[i]) - int(komb[i]) < int(komb[i]) + 9 - int(isx[i]) + 1:
			p += int(isx[i]) - int(komb[i])
		else:
			p += int(komb[i]) + 9 - int(isx[i]) + 1
	elif int(komb[i]) - int(isx[i]) < 9 - int(komb[i]) + 1 + int(isx[i]):
		p += int(komb[i]) - int(isx[i])
	else:
		p += 9 - int(komb[i]) + 1 + int(isx[i])
print(p)


n = int(input())
a1 = [int(x) for x in list(input())]
a2 = [int(x) for x in list(input())]
e = 0
for i in range(n):
	e += min(10 - abs(a1[i] - a2[i]), abs(a1[i] - a2[i]))
print(e)


n = int(input())
list1 = [int(x) for x in input()]
list2 = [int(x) for x in input()]
x = 0
for i in range(n):
	x += min(abs(list1[i] - list2[i]), 10 - abs(list1[i] - list2[i]))
print(x)


nb = input()
total = 0
val = input()
compare = input()
for i in range(int(nb)):
	calc = abs(int(val[i]) - int(compare[i]))
	total += calc if calc < 6 else 10 - calc
print(total)


int(input())
o = input()
r = input()
sl = [int(n) for n in o]
el = [int(n) for n in r]
reckoning = list(zip(sl, el))
retribution = []
for (x, y) in reckoning:
	if abs(x - y) <= 5:
		retribution.append(abs(x - y))
	elif x > y:
		retribution.append(10 - x + y)
	elif x < y:
		retribution.append(10 - y + x)
result = sum(retribution)
print(result)


n = int(input())
start = input()
stop = input()
moves = 0
for i in range(n):
	if abs(int(start[i]) - int(stop[i])) > 5:
		moves += 5 - abs(int(start[i]) - int(stop[i])) % 5
	else:
		moves += abs(int(start[i]) - int(stop[i]))
print(moves)


D = int(input())
R = input()
G = input()
m = 0
for (u, y) in zip(R, G):
	m += min(abs(int(y) - int(u)), 10 - abs(int(y) - int(u)))
print(m)


(a, b, c) = [int(input()) for _ in '.' * 3]
l = []
for _ in '.' * a:
	x = abs(b % 10 - c % 10)
	b //= 10
	c //= 10
	l += [min(x, 10 - x)]
print(sum(l))


t = int(input())
l = input()
l2 = input()
cou = 0
for i in range(t):
	a = abs(int(l2[i]) - int(l[i]))
	if a > 5:
		cou += 10 - a
	else:
		cou += a
print(cou)


x = int(input())
l = input()
m = input()
l = list(l)
m = list(m)
c = 0
for i in range(0, x):
	u = int(l[i])
	v = int(m[i])
	c += min(abs(u - v), 10 - u + v, 10 - v + u)
print(c)


n = int(input())
a = input()
b = input()
x = 0
a = list(a)
b = list(b)
for i in range(n):
	if int(a[i]) > int(b[i]) and abs(int(a[i]) - int(b[i])) <= 5:
		a1 = int(a[i])
		b1 = int(b[i])
		while a1 != b1:
			a1 = a1 - 1
			x += 1
	elif int(a[i]) < int(b[i]) and abs(int(a[i]) - int(b[i])) <= 5:
		a1 = int(a[i])
		b1 = int(b[i])
		while a1 != b1:
			a1 = a1 + 1
			x += 1
	elif int(a[i]) > int(b[i]) and abs(int(a[i]) - int(b[i])) > 5:
		a1 = int(a[i])
		b1 = int(b[i])
		while a1 != b1:
			a1 = a1 + 1
			x += 1
			if a1 == 10:
				a1 = 0
	elif int(a[i]) < int(b[i]) and abs(int(a[i]) - int(b[i])) > 5:
		a1 = int(a[i])
		b1 = int(b[i])
		while a1 != b1:
			a1 = a1 - 1
			x += 1
			if a1 == -1:
				a1 = 9
print(x)


n = int(input(''))
a = int(input(''))
b = int(input(''))
now = 0
for i in range(n):
	c = int(a // 10 ** i - a // 10 ** (i + 1) * 10)
	d = int(b // 10 ** i - b // 10 ** (i + 1) * 10)
	if abs(c - d) > 5:
		now = now + 10 - abs(c - d)
	else:
		now = now + abs(c - d)
print(now)


input()
c = [int(i) for i in list(input())]
cc = [int(i) for i in list(input())]
result = 0
for i in range(len(c)):
	if abs(c[i] - cc[i]) == 9:
		result += 1
	elif c[i] > cc[i] and 10 - c[i] + cc[i] < abs(c[i] - cc[i]):
		result += 10 - c[i] + cc[i]
	elif c[i] < cc[i] and 10 + c[i] - cc[i] < abs(c[i] - cc[i]):
		result += 10 + c[i] - cc[i]
	else:
		result += abs(c[i] - cc[i])
print(result)


import sys
from random import choice, randint
inp = sys.stdin.readline
out = sys.stdout.write
flsh = sys.stdout.flush
sys.setrecursionlimit(10 ** 9)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def MI():
	return map(int, inp().strip().split())

def LI():
	return list(map(int, inp().strip().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

def LI_():
	return [int(x) - 1 for x in inp().strip().split()]

def LF():
	return [float(x) for x in inp().strip().split()]

def LS():
	return inp().strip().split()

def I():
	return int(inp().strip())

def F():
	return float(inp().strip())

def S():
	return inp().strip()

def pf(s):
	return out(s + '\n')

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	n = I()
	s1 = S()
	s2 = S()
	c = 0
	for i in range(n):
		ans = min(abs(int(s1[i]) - int(s2[i])), 9 - max(int(s1[i]), int(s2[i])) + min(int(s1[i]), int(s2[i])) + 1)
		c += ans
	pf(str(c))
main()


n = int(input())
now = input()
desired = input()
counter = 0
for _ in range(n):
	i = int(now[_])
	j = int(desired[_])
	if abs(j - i) > 5 and i > j:
		(i, j) = (j, i)
	if i + (10 - j) < abs(i - j):
		counter += i + (10 - j)
	else:
		counter += abs(i - j)
print(counter)


(n, a, b) = (input(), map(int, list(input())), map(int, list(input())))
print(sum((min(10 - abs(c - d), abs(c - d)) for (c, d) in zip(a, b))))


n1 = int(input())
n2 = input()
n3 = input()
n22 = []
n33 = []
moves = 0
for i in n2:
	n22.append(int(i))
for i in n3:
	n33.append(int(i))
for i in range(0, len(n22)):
	dif = abs(n22[i] - n33[i])
	if dif > 5:
		moves += 10 - dif
	else:
		moves += dif
print(moves)


def main():
	disks = int(input())
	original = input()
	combination = input()
	total = 0
	for i in range(disks):
		option1 = abs(int(original[i]) - int(combination[i]))
		option2 = abs(min(int(original[i]), int(combination[i])) + 10 - max(int(original[i]), int(combination[i])))
		total += min(option1, option2)
	print(total)
main()


n = int(input())
m = input()
mm = input()
sum = 0
for i in range(0, n):
	if abs(ord(mm[i]) - ord(m[i])) > 5:
		sum = sum + 10 - abs(ord(mm[i]) - ord(m[i]))
	else:
		sum = sum + abs(ord(mm[i]) - ord(m[i]))
print(sum)


n = int(input())
current_state = input()
real_state = input()
total_steps = 0
for i in range(0, n):
	n = abs(int(current_state[i]) - int(real_state[i]))
	if n < 10 - n:
		total_steps += n
	else:
		total_steps += 10 - n
print(total_steps)


t = int(input())
a = str(input())
b = str(input())
s = 0
for k in range(t):
	s += min(abs(int(a[k]) - int(b[k])), min(int(a[k]), int(b[k])) - max(int(a[k]), int(b[k])) + 10)
print(s)


I = lambda : map(int, input())
(n, start, goal) = (input(), I(), I())
print(sum((min(abs(x - y), 10 - abs(x - y)) for (x, y) in zip(start, goal))))


n = int(input())
s = str(input())
s1 = str(input())
res = 0
for i in range(n):
	x = int(s[i])
	y = int(s1[i])
	res += min(abs(x - y), 10 - abs(x - y))
print(res)


import sys

def get_d(d1, d2):
	if d1 > d2:
		(d1, d2) = (d2, d1)
	return min(d2 - d1, 10 - d2 + d1)
fin = sys.stdin
n = int(fin.readline())
s1 = fin.readline().strip()
s2 = fin.readline().strip()
ans = 0
for i in range(n):
	ans += get_d(int(s1[i]), int(s2[i]))
print(ans)


a = int(input())
b = input()
c = input()
e = []
f = []
for i in b:
	e.append(int(i))
for i in c:
	f.append(int(i))
count = 0
for i in range(a):
	count += min(abs(e[i] - f[i]), 10 - abs(e[i] - f[i]))
print(count)


n = int(input())
l1 = list(map(int, input()))
l2 = list(map(int, input()))
num = 0
for i in range(n):
	num += min(abs(l1[i] - l2[i]), 10 - abs(l1[i] - l2[i]))
print(num)


a = input()
b = input()
c = input()
res1 = [int(x) for x in str(b)]
res2 = [int(x) for x in str(c)]
s = 0
for i in range(len(res1)):
	x = abs(res1[i] - res2[i])
	s = s + min(x, 10 - x)
print(s)


n = int(input())
src = input()
tgt = input()
cnt = 0
for i in range(n):
	d = abs(int(tgt[i]) - int(src[i]))
	if d > 5:
		d = 10 - d
	cnt += d
print(cnt)


n = int(input())
o = input()
c = input()
lo = list(o)
lo = list(map(int, lo))
lc = list(c)
lc = list(map(int, lc))
total = 0
for i in range(n):
	d1 = abs(lo[i] - lc[i])
	if lo[i] > lc[i]:
		d2 = abs(9 - lo[i] + lc[i]) + 1
	else:
		d2 = abs(9 + lo[i] - lc[i]) + 1
	total += min(d1, d2)
print(total)


(actions, n, reset, code) = (0, int(input()), input(), input())
for i in range(n):
	diff = abs(int(reset[i]) - int(code[i]))
	actions += min(diff, 10 - diff)
print(actions)


from math import fabs
a = int(input())
b = input()
c = input()
b_l = []
c_l = []
for every in list(b):
	b_l.append(every)
for every in list(c):
	c_l.append(every)
count = 0
for every in range(0, a):
	fir = fabs(int(b_l[every]) - int(c_l[every]))
	sec = 10 - int(b_l[every]) + int(c_l[every])
	if sec > 10:
		sec = 20 - sec
	if fir < sec:
		count += fir
	else:
		count += sec
print(int(count))


input()
x = 0
l1 = list(map(int, input()))
l2 = list(map(int, input()))
for i in range(len(l1)):
	a = max(l1[i], l2[i])
	b = min(l1[i], l2[i])
	if abs(l1[i] - l2[i]) > 5:
		x += 10 - a + b
	else:
		x += abs(l1[i] - l2[i])
print(x)


n = int(input())
a = input()
b = input()
x = 0
for i in range(0, n):
	e = abs(10 - int(a[i]) + int(b[i]))
	f = abs(10 - int(b[i]) + int(a[i]))
	c = min(e, f)
	d = abs(int(b[i]) - int(a[i]))
	if c >= d:
		x += d
	else:
		x += c
print(x)


n = int(input())
S1 = input()
S2 = input()
k = 0
for i in range(n):
	a = int(S1[i])
	b = int(S2[i])
	k = k + min((10 + a - b) % 10, (10 + b - a) % 10)
print(k)


n = 0
z = int(input())
x = list(map(int, input()))
c = list(map(int, input()))
for v in range(z):
	b = abs(x[v] - c[v])
	if b <= 5:
		n += b
	else:
		n += 10 - b
print(n)


n = int(input())
current_set = [int(x) for x in input()]
goal_set = [int(x) for x in input()]
roll = '01234567890123456789'
count = 0
for i in range(len(current_set)):
	current_num = str(current_set[i])
	desired_num = str(goal_set[i])
	lc = roll.index(current_num)
	rc = roll.rindex(current_num)
	ld = roll.index(desired_num)
	rd = roll.rindex(desired_num)
	count += min(abs(lc - ld), min(abs(rc - rd), min(abs(lc - rd), abs(rc - ld))))
print(count)


n = int(input())
list1 = list(map(int, input()))
list2 = list(map(int, input()))
count = 0
for i in range(n):
	if abs(list1[i] - list2[i]) > 5:
		count += 10 - abs(list1[i] - list2[i])
	else:
		count += abs(list1[i] - list2[i])
print(count)


n = int(input())
c = list(input())
p = list(input())
cnt = 0
for i in range(len(c)):
	if c[i] != p[i]:
		m1 = abs(int(c[i]) - int(p[i]))
		if int(c[i]) < int(p[i]):
			m2 = abs(int(c[i]) + 10 - int(p[i]))
		else:
			m2 = abs(int(p[i]) + 10 - int(c[i]))
		cnt += min(m1, m2)
print(cnt)


n = int(input())
current = input()
final = input()
count = 0
for i in range(n):
	a = abs(int(current[i]) - int(final[i]))
	b = abs(10 - int(final[i]) + int(current[i]))
	c = abs(10 - int(current[i]) + int(final[i]))
	count += min(a, b, c)
print(count)


moves = 0
n = int(input())
x = input()
passw = input()
for (i, j) in zip(range(len(x)), range(len(passw))):
	z = abs(int(passw[j]) - int(x[i]))
	if z <= 5:
		moves += z
	if z > 5:
		if int(x[i]) > int(passw[j]):
			z = int(passw[j]) + 10 - int(x[i])
			moves += z
		else:
			z = int(x[i]) + 10 - int(passw[j])
			moves += z
print(moves)


input()
(n, m) = (input(), input())
c = 0
for i in range(len(n)):
	a = max(int(n[i]), int(m[i]))
	b = min(int(n[i]), int(m[i]))
	c += min(a - b, 10 - a + b)
print(c)


n = int(input())
original = [int(i) for i in input()]
code = [int(i) for i in input()]
cnt = 0
for i in range(n):
	cnt += min(abs(original[i] - code[i]), abs(original[i] + 10 - code[i]), abs(original[i] - code[i] - 10))
print(cnt)


def rotate(m, n):
	(m, n) = (min(m, n), max(m, n))
	return min([abs(m - n), 10 - n + m])
n = int(input())
s1 = input()
s2 = input()
count = 0
for i in range(n):
	count += rotate(int(s1[i]), int(s2[i]))
print(count)


n = int(input())
l = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
s = input()
s1 = input()
sm = 0
for i in range(len(s)):
	a = l.index(s[i])
	l1 = l[a:] + l[:a]
	l2 = l[a + 1:] + l[:a + 1]
	x = abs(l1.index(s[i]) - l1.index(s1[i]))
	y = abs(l2.index(s[i]) - l2.index(s1[i]))
	sm += min(x, y)
print(sm)


times = 0
a = int(input())
b = list(map(int, input()))
c = list(map(int, input()))
for i in range(a):
	m = abs(b[i] - c[i])
	x = b[i] + (9 - c[i]) + 1
	n = c[i] + (9 - b[i]) + 1
	if m < n and m < x:
		times += m
	elif n < x and n < m:
		times += n
	elif x < n and x < m:
		times += x
	elif m == n and m < x:
		times += m
	elif m == x and m < n:
		times += m
	elif n == x and n < m:
		times += n
print(times)


n = int(input())
s = list(input())
e = list(input())
a = 0
for i in range(n):
	m = abs(int(s[i]) - int(e[i]))
	a += min(m, 10 - m)
print(a)


n = int(input())
l1 = list(map(int, list(input())))
l2 = list(map(int, list(input())))
total = 0
for i in range(n):
	if abs(l1[i] - l2[i]) > 5:
		total += 10 - abs(l1[i] - l2[i])
	else:
		total += abs(l1[i] - l2[i])
print(total)


n = int(input())
a = input()
b = input()
now = [int(x) for x in a]
password = [int(x) for x in b]
count = 0
for i in range(n):
	if now[i] == 0 and password[i] == 9 or (password[i] == 0 and now[i] == 9):
		count += 1
	elif now[i] < password[i]:
		if abs(now[i] + 10 - password[i]) < abs(now[i] - password[i]):
			count += abs(now[i] + 10 - password[i])
		else:
			count += abs(now[i] - password[i])
	elif abs(10 - now[i] + password[i]) < abs(now[i] - password[i]):
		count += abs(10 - now[i] + password[i])
	else:
		count += abs(now[i] - password[i])
print(count)


disks = int(input())
original = input()
opens = input()
moves = 0
for idx in range(disks):
	ori = int(original[idx])
	ope = int(opens[idx])
	differ = abs(ori - ope)
	if differ > 5:
		if ori > ope:
			differ = ope + 10 - ori
		else:
			differ = ori + 10 - ope
	moves += differ
print(moves)


n = int(input())
s = input()
key = input()
res = 0
for i in range(len(s)):
	if abs(int(key[i]) - int(s[i])) < 5:
		res += abs(int(key[i]) - int(s[i]))
	elif int(key[i]) > int(s[i]):
		res += int(s[i]) + (9 - int(key[i])) + 1
	else:
		res += int(key[i]) + (9 - int(s[i])) + 1
print(res)


(n, r, f) = (int(input()), input(), input())
move = 0
for i in range(n):
	d = abs(int(r[i]) - int(f[i]))
	if d > 5:
		d = 10 - d
	move += d
print(move)


n = input()
current_state = input()
required_state = input()
no_moves = 0
for i in range(int(n)):
	current_digit = current_state[i]
	required_digit = required_state[i]
	digit = list(map(int, [current_digit, required_digit]))
	minimum = min(digit)
	maximum = max(digit)
	no_moves += min(abs(minimum - maximum), abs(10 + minimum - maximum))
print(no_moves)


def main():
	input()
	res = 0
	for (a, b) in zip(input(), input()):
		x = (int(a) - int(b)) % 10
		res += min(x, 10 - x)
	print(res)
main()


a = int(input(''))
b = input('')
c = input('')
z = 0
p = 0
for i in range(a):
	if b[p] < c[p]:
		d = int(b[p]) - int(c[p])
		if d < 0:
			d = -d
		k = int(b[p])
		l = 9 - int(c[p]) + k + 1
		if l < 0:
			l = -l
		if d > l:
			z = z + l
		else:
			z = z + d
	elif b[p] > c[p]:
		d = int(c[p]) - int(b[p])
		if d < 0:
			d = -d
		k = int(c[p])
		l = 9 - int(b[p]) + k + 1
		if l < 0:
			l = -l
		if d > l:
			z = z + l
		else:
			z = z + d
	p = p + 1
print(z)


n = int(input())
x = list(map(int, ' '.join(input()).split()))
y = list(map(int, ' '.join(input()).split()))
count = 0
for i in range(len(x)):
	a = max(x[i], y[i])
	b = min(x[i], y[i])
	count += a - b if a - b < 5 else b + 10 - a
print(count)


a = int(input())
b = list(input())
c = list(input())
s = 0
for i in range(a):
	k = abs(int(b[i]) - int(c[i]))
	m = 10 - k
	if k > m:
		s = s + m
	else:
		s = s + k
print(s)


n = int(input())
s4 = int(input())
s3 = int(input())
nbr_moves = 0
s1 = []
s2 = []
for x in range(n):
	s1.append(s4 % 10)
	s4 = s4 // 10
for x in range(n):
	s2.append(s3 % 10)
	s3 = s3 // 10
for x in range(n):
	if s1[x] == s2[x]:
		continue
	elif s1[x] > s2[x]:
		if s1[x] - s2[x] <= 10 + s2[x] - s1[x]:
			nbr_moves += s1[x] - s2[x]
		else:
			nbr_moves += 10 + s2[x] - s1[x]
	elif s2[x] - s1[x] <= 10 + s1[x] - s2[x]:
		nbr_moves += s2[x] - s1[x]
	else:
		nbr_moves += 10 + s1[x] - s2[x]
print(nbr_moves)


n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
col = 0
for i in range(n):
	f = abs(a[i] - b[i])
	g = 10 - a[i] + b[i]
	e = a[i] + 10 - b[i]
	col += min(f, g, e)
print(col)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	s = S()
	t = S()
	r = 0
	for i in range(n):
		a = int(s[i])
		b = int(t[i])
		(a, b) = (min(a, b), max(a, b))
		r += min(b - a, a + 10 - b)
	return r
print(main())