#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 /*<<< orphan*/ printf(char *, int);
scalar_t__ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int n = 1;
  int t = 0;
  int i;
  int start = 0, dest = 0;
  int distance;
  while (scanf("%d", &n) && n != 0) {
    i = 0;
    t = 5 * n;
    start = 0;
    while (i < n) {
      scanf("%d", &dest);
      distance = dest - start;
      if (distance > 0) {
        t += (6 * distance);
      } else {
        t -= (4 * distance);
      }
      start = dest;
      i++;
    }
    printf("%d\n", t);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xea7(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
je     117e <main+0x5e>
cmpl   $0x0,-0x14(%rbp)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    118e <main+0x6e>
jmp    1217 <main+0xf7>
movl   $0x0,-0x1c(%rbp)
imul   $0x5,-0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1203 <main+0xe3>
lea    0xe4a(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x24(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    11e1 <main+0xc1>
imul   $0x6,-0x28(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11ef <main+0xcf>
mov    -0x28(%rbp),%ecx
shl    $0x2,%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a3 <main+0x83>
mov    -0x18(%rbp),%esi
lea    0xdf6(%rip),%rdi
call   1030 <printf@plt>
jmp    1152 <main+0x32>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x1,(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xebf(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     11d6 <main+0xb6>
mov    (%rsp),%eax
test   %eax,%eax
je     11d6 <main+0xb6>
lea    0xe9c(%rip),%rbx
lea    0x4(%rsp),%r14
mov    $0x6,%r13d
nop
lea    (%rax,%rax,4),%ebp
test   %eax,%eax
jle    11b1 <main+0x91>
xor    %r12d,%r12d
xor    %r15d,%r15d
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
mov    %eax,%ecx
sub    %r12d,%ecx
test   %ecx,%ecx
mov    $0xfffffffc,%edx
cmovg  %r13d,%edx
imul   %ecx,%edx
add    %edx,%ebp
add    $0x1,%r15d
mov    %eax,%r12d
cmp    (%rsp),%r15d
jl     1180 <main+0x60>
lea    0xe4b(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     11d6 <main+0xb6>
mov    (%rsp),%eax
test   %eax,%eax
jne    1170 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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