#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 */
scalar_t__ EOF;
int /*<<< orphan*/ printf(char *, int);
scalar_t__ scanf(char *, int *);
int main() {
  int a, b;
  int count, time;
  while (scanf("%d", &count) != EOF && count != 0) {
    a = 0;
    time = 0;
    while (count--) {
      scanf("%d", &b);
      if (a > b) {
        time += 4 * (a - b) + 5;
      } else {
        time += 6 * (b - a) + 5;
      }
      a = b;
    }
    printf("%d\n", time);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2e9d(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x15(%rbp)
je     1161 <main+0x41>
cmpl   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1171 <main+0x51>
jmp    11f7 <main+0xd7>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cmp    $0x0,%eax
je     11e3 <main+0xc3>
lea    0xe66(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11c6 <main+0xa6>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
shl    $0x2,%eax
add    $0x5,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11d8 <main+0xb8>
mov    -0xc(%rbp),%eax
sub    -0x8(%rbp),%eax
imul   $0x6,%eax,%eax
add    $0x5,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    117f <main+0x5f>
mov    -0x14(%rbp),%esi
lea    0xe16(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xece(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    0x2ea7(%rip),%rcx
cmp    (%rcx),%rax
je     11d9 <main+0xb9>
mov    (%rsp),%eax
test   %eax,%eax
je     11d9 <main+0xb9>
lea    0xea4(%rip),%r13
lea    0x4(%rsp),%r14
lea    0xe9b(%rip),%r15
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%eax
mov    %eax,(%rsp)
xor    %ebx,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
mov    %ebp,%ecx
sub    %eax,%ecx
mov    %ecx,%edx
neg    %edx
shl    $0x2,%ecx
add    %edx,%edx
cmp    %eax,%ebp
lea    (%rdx,%rdx,2),%edx
cmovg  %ecx,%edx
add    %edx,%ebx
add    $0x5,%ebx
subl   $0x1,(%rsp)
mov    %eax,%ebp
jae    1180 <main+0x60>
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%rax
je     11d9 <main+0xb9>
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"
@EOF = global i64 0
@.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
store i32 0, i32* %1
br label %6
6: ; preds = %43, %0
%7 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%8 = load i64, i64* @EOF
%9 = icmp ne i64 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br label %13
13: ; preds = %10, %6
%14 = phi i1 [ false, %6 ], [ %12, %10 ]
br i1 %14, label %15, label %46
15: ; preds = %13
store i32 0, i32* %2
store i32 0, i32* %5
br label %16
16: ; preds = %41, %15
%17 = load i32, i32* %4
%18 = add nsw i32 %17, -1
store i32 %18, i32* %4
%19 = icmp ne i32 %17, 0
br i1 %19, label %20, label %43
20: ; preds = %16
%21 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = sub nsw i32 %26, %27
%29 = mul nsw i32 4, %28
%30 = add nsw i32 %29, 5
%31 = load i32, i32* %5
%32 = add nsw i32 %31, %30
store i32 %32, i32* %5
br label %41
33: ; preds = %20
%34 = load i32, i32* %3
%35 = load i32, i32* %2
%36 = sub nsw i32 %34, %35
%37 = mul nsw i32 6, %36
%38 = add nsw i32 %37, 5
%39 = load i32, i32* %5
%40 = add nsw i32 %39, %38
store i32 %40, i32* %5
br label %41
41: ; preds = %33, %25
%42 = load i32, i32* %3
store i32 %42, i32* %2
br label %16
43: ; preds = %16
%44 = load i32, i32* %5
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %44)
br label %6
46: ; preds = %13
ret i32 0
}

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