#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 argc, char *argv[]) {
  int tallindex, tall, shortindex, shor, num, moves = 0, count, curr;
  scanf("%d", &num);
  scanf("%d", &tall);
  shor = tall;
  tallindex = shortindex = 0;
  for (count = 1; count < num; count++) {
    scanf("%d", &curr);
    if (curr > tall) {
      tall = curr;
      tallindex = count;
    } else if (curr <= shor) {
      shor = curr;
      shortindex = count;
    }
  }
  moves = tallindex + ((num - 1) - shortindex);
  if (tallindex > shortindex)
    moves--;
  printf("%d", moves);
  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   $0x0,-0x28(%rbp)
lea    0xebc(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeac(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11e1 <main+0xc1>
lea    0xe75(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11b1 <main+0x91>
mov    -0x30(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11ce <main+0xae>
mov    -0x30(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     11c9 <main+0xa9>
mov    -0x30(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11ce <main+0xae>
jmp    11d3 <main+0xb3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1178 <main+0x58>
mov    -0x14(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
sub    -0x1c(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    1207 <main+0xe7>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xdef(%rip),%rdi
call   1030 <printf@plt>
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
sub    $0x18,%rsp
lea    0xecb(%rip),%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
mov    0x10(%rsp),%eax
xor    %r12d,%r12d
mov    $0x0,%r13d
cmp    $0x2,%eax
jl     11b2 <main+0x92>
xor    %r13d,%r13d
mov    $0x1,%ebp
mov    0xc(%rsp),%ebx
lea    0xe8c(%rip),%r14
lea    0x14(%rsp),%r15
xor    %r12d,%r12d
jmp    1194 <main+0x74>
xchg   %ax,%ax
cmp    %ebx,%eax
cmovle %ebp,%r13d
cmovle %eax,%ebx
add    $0x1,%ebp
mov    0x10(%rsp),%eax
cmp    %eax,%ebp
jge    11b2 <main+0x92>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    0x14(%rsp),%eax
cmp    0xc(%rsp),%eax
jle    1180 <main+0x60>
mov    %eax,0xc(%rsp)
mov    %ebp,%r12d
jmp    1189 <main+0x69>
xor    %ecx,%ecx
cmp    %r13d,%r12d
not    %r13d
setg   %cl
add    %r12d,%r13d
sub    %ecx,%r13d
add    %eax,%r13d
lea    0xe33(%rip),%rdi
mov    %r13d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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