#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);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, last = 0, temp, sum = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &temp);
    temp -= last;
    last += temp;
    if (temp > 0)
      sum += temp * 6;
    else if (temp < 0)
      sum += (-1 * temp) * 4;
    sum += 5;
  }
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xebc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d3 <main+0xb3>
lea    0xe99(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    119d <main+0x7d>
imul   $0x6,-0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11bc <main+0x9c>
cmpl   $0x0,-0x10(%rbp)
jge    11b7 <main+0x97>
imul   $0xffffffff,-0x10(%rbp),%eax
shl    $0x2,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11bc <main+0x9c>
mov    -0x14(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1154 <main+0x34>
mov    -0x14(%rbp),%esi
lea    0xe26(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xecd(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1198 <main+0x78>
xor    %ebp,%ebp
lea    0xeb3(%rip),%r14
lea    0x8(%rsp),%r15
xor    %ebx,%ebx
xor    %eax,%eax
jmp    1172 <main+0x52>
nopl   0x0(%rax,%rax,1)
lea    (%rcx,%rcx,2),%ecx
lea    (%rbx,%rcx,2),%ebx
add    $0x5,%ebx
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jge    119a <main+0x7a>
mov    %eax,%r12d
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    0x8(%rsp),%eax
mov    %eax,%ecx
sub    %r12d,%ecx
mov    %ecx,0x8(%rsp)
jg     1160 <main+0x40>
jns    1166 <main+0x46>
shl    $0x2,%ecx
sub    %ecx,%ebx
jmp    1166 <main+0x46>
xor    %ebx,%ebx
lea    0xe62(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
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() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %5
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %6
br label %8
8: ; preds = %40, %0
%9 = load i32, i32* %6
%10 = load i32, i32* %2
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %43
12: ; preds = %8
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, %14
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = add nsw i32 %18, %17
store i32 %19, i32* %3
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %12
%23 = load i32, i32* %4
%24 = mul nsw i32 %23, 6
%25 = load i32, i32* %5
%26 = add nsw i32 %25, %24
store i32 %26, i32* %5
br label %37
27: ; preds = %12
%28 = load i32, i32* %4
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i32, i32* %4
%32 = mul nsw i32 -1, %31
%33 = mul nsw i32 %32, 4
%34 = load i32, i32* %5
%35 = add nsw i32 %34, %33
store i32 %35, i32* %5
br label %36
36: ; preds = %30, %27
br label %37
37: ; preds = %36, %22
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 5
store i32 %39, i32* %5
br label %40
40: ; preds = %37
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %8
43: ; preds = %8
%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)
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() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %27, %0
%9 = phi i32 [ 0, %0 ], [ %29, %27 ]
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %9)
ret i32 0
11: ; preds = %0, %27
%12 = phi i32 [ %30, %27 ], [ 0, %0 ]
%13 = phi i32 [ %29, %27 ], [ 0, %0 ]
%14 = phi i32 [ %16, %27 ], [ 0, %0 ]
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%16 = load i32, i32* %2
%17 = sub nsw i32 %16, %14
store i32 %17, i32* %2
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = mul nsw i32 %17, 6
%21 = add nsw i32 %20, %13
br label %27
22: ; preds = %11
%23 = icmp slt i32 %17, 0
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = mul i32 %17, -4
%26 = add nsw i32 %25, %13
br label %27
27: ; preds = %22, %24, %19
%28 = phi i32 [ %21, %19 ], [ %26, %24 ], [ %13, %22 ]
%29 = add nsw i32 %28, 5
%30 = add nuw nsw i32 %12, 1
%31 = load i32, i32* %1
%32 = icmp slt i32 %30, %31
br i1 %32, label %11, label %8
}