#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 distance(int, int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, int *, int *, int *, int *);
int main(void) {
  int num, a, b, c, d, i, min = 200, temp;
  scanf("%d %d %d %d %d", &num, &a, &b, &c, &d);
  for (i = 1; i <= num; i++) {
    temp = distance(a - 1, b - 1, i) + distance(c - 1, d - 1, i);
    if (temp < min)
      min = temp;
  }
  printf("%d\n", min);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xc8,-0x20(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
lea    -0x18(%rbp),%r9
call   1040 <scanf@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11d3 <main+0xa3>
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
mov    -0x1c(%rbp),%edx
call   1050 <distance@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
sub    $0x1,%edi
mov    -0x18(%rbp),%esi
sub    $0x1,%esi
mov    -0x1c(%rbp),%edx
call   1050 <distance@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11c0 <main+0x90>
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11c5 <main+0x95>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116d <main+0x3d>
mov    -0x20(%rbp),%esi
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x14(%rsp),%r8
lea    0x10(%rsp),%r9
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11b0 <main+0x80>
mov    $0xc8,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    0x1c(%rsp),%edi
add    $0xffffffff,%edi
mov    0x18(%rsp),%esi
add    $0xffffffff,%esi
mov    %ebp,%edx
call   1050 <distance@plt>
mov    %eax,%r14d
mov    0x14(%rsp),%edi
add    $0xffffffff,%edi
mov    0x10(%rsp),%esi
add    $0xffffffff,%esi
mov    %ebp,%edx
call   1050 <distance@plt>
add    %r14d,%eax
cmp    %ebx,%eax
cmovl  %eax,%ebx
cmp    0xc(%rsp),%ebp
jl     1170 <main+0x40>
jmp    11b5 <main+0x85>
mov    $0xc8,%ebx
lea    0xe53(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"%d %d %d %d %d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 200, i32* %8
%10 = call i32 @scanf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %5, i32* %6)
store i32 1, i32* %7
br label %11
11: ; preds = %35, %0
%12 = load i32, i32* %7
%13 = load i32, i32* %2
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %38
15: ; preds = %11
%16 = load i32, i32* %3
%17 = sub nsw i32 %16, 1
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 1
%20 = load i32, i32* %7
%21 = call i32 @distance(i32 %17, i32 %19, i32 %20)
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 1
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, 1
%26 = load i32, i32* %7
%27 = call i32 @distance(i32 %23, i32 %25, i32 %26)
%28 = add nsw i32 %21, %27
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = load i32, i32* %8
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %15
%33 = load i32, i32* %9
store i32 %33, i32* %8
br label %34
34: ; preds = %32, %15
br label %35
35: ; preds = %34
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %11
38: ; preds = %11
%39 = load i32, i32* %8
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %39)
ret i32 0
}

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