#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int abs(int);
int ctoi(char);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int n;
  int init, fin;
  int answer;
  scanf("%d\n", &n);
  char *initial = malloc(sizeof(char) * (n + 1));
  char *final = malloc(sizeof(char) * (n + 1));
  scanf("%1000s\n", initial);
  scanf("%1000s", final);
  for (int i = 0; i < n; i++) {
    init = ctoi(initial[i]);
    fin = ctoi(final[i]);
    answer += abs(init - fin) > 5 ? 10 - abs(init - fin) : abs(init - fin);
  }
  free(initial);
  free(final);
  printf("%d\n", answer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1080 <scanf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1263 <main+0x103>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <ctoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <ctoi@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
sub    -0x10(%rbp),%edi
call   1040 <abs@plt>
cmp    $0x5,%eax
jle    123e <main+0xde>
mov    -0xc(%rbp),%edi
sub    -0x10(%rbp),%edi
call   1040 <abs@plt>
mov    %eax,%ecx
mov    $0xa,%eax
sub    %ecx,%eax
mov    %eax,-0x30(%rbp)
jmp    124c <main+0xec>
mov    -0xc(%rbp),%edi
sub    -0x10(%rbp),%edi
call   1040 <abs@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11da <main+0x7a>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%esi
lea    0xd81(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9d(%rip),%rdi
xor    %ebp,%ebp
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0xc(%rsp),%ebx
add    $0x1,%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xe71(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
lea    0xe68(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
xchg   %ax,%ax
movsbl (%r14,%rbp,1),%edi
call   1040 <ctoi@plt>
mov    %eax,%ebx
movsbl (%r15,%rbp,1),%edi
call   1040 <ctoi@plt>
sub    %eax,%ebx
mov    %ebx,%eax
neg    %eax
cmovs  %ebx,%eax
mov    $0xa,%ecx
sub    %eax,%ecx
cmp    $0x6,%eax
cmovb  %eax,%ecx
add    %ecx,%r12d
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     11b0 <main+0x60>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xdfc(%rip),%rdi
mov    %r12d,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [8 x i8] c"%1000s\0A\00"
@.str.2 = [7 x i8] c"%1000s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = add nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = mul i64 1, %12
%14 = trunc i64 %13 to i32
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %6
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = mul i64 1, %18
%20 = trunc i64 %19 to i32
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %7
%22 = load i8*, i8** %6
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %7
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store i32 0, i32* %8
br label %26
26: ; preds = %63, %0
%27 = load i32, i32* %8
%28 = load i32, i32* %2
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %66
30: ; preds = %26
%31 = load i8*, i8** %6
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @ctoi(i8 signext %35)
store i32 %36, i32* %3
%37 = load i8*, i8** %7
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = call i32 @ctoi(i8 signext %41)
store i32 %42, i32* %4
%43 = load i32, i32* %3
%44 = load i32, i32* %4
%45 = sub nsw i32 %43, %44
%46 = call i32 @abs(i32 %45)
%47 = icmp sgt i32 %46, 5
br i1 %47, label %48, label %54
48: ; preds = %30
%49 = load i32, i32* %3
%50 = load i32, i32* %4
%51 = sub nsw i32 %49, %50
%52 = call i32 @abs(i32 %51)
%53 = sub nsw i32 10, %52
br label %59
54: ; preds = %30
%55 = load i32, i32* %3
%56 = load i32, i32* %4
%57 = sub nsw i32 %55, %56
%58 = call i32 @abs(i32 %57)
br label %59
59: ; preds = %54, %48
%60 = phi i32 [ %53, %48 ], [ %58, %54 ]
%61 = load i32, i32* %5
%62 = add nsw i32 %61, %60
store i32 %62, i32* %5
br label %63
63: ; preds = %59
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
br label %26
66: ; preds = %26
%67 = load i8*, i8** %6
%68 = call i32 @free(i8* %67)
%69 = load i8*, i8** %7
%70 = call i32 @free(i8* %69)
%71 = load i32, i32* %5
%72 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %71)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [8 x i8] c"%1000s\0A\00"
@.str.2 = [7 x i8] c"%1000s\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = add nsw i32 %4, 1
%6 = call i8* @malloc(i32 %5)
%7 = call i8* @malloc(i32 %5)
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br label %16
12: ; preds = %16
%13 = call i32 @free(i8* %6)
%14 = call i32 @free(i8* %7)
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %30)
ret i32 0
16: ; preds = %0, %16
%17 = phi i64 [ 0, %0 ], [ %31, %16 ]
%18 = phi i32 [ undef, %0 ], [ %30, %16 ]
%19 = getelementptr inbounds i8, i8* %6, i64 %17
%20 = load i8, i8* %19
%21 = call i32 @ctoi(i8 signext %20)
%22 = getelementptr inbounds i8, i8* %7, i64 %17
%23 = load i8, i8* %22
%24 = call i32 @ctoi(i8 signext %23)
%25 = sub nsw i32 %21, %24
%26 = call i32 @llvm.abs.i32(i32 %25, i1 true)
%27 = icmp ugt i32 %26, 5
%28 = sub nsw i32 10, %26
%29 = select i1 %27, i32 %28, i32 %26
%30 = add nsw i32 %29, %18
%31 = add nuw nsw i64 %17, 1
%32 = load i32, i32* %1
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %16, label %12
}