#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(void) {
  int N, i, min, profit, temp;
  scanf("%d", &N);
  scanf("%d", &temp);
  scanf("%d", &profit);
  min = temp;
  if (min > profit)
    min = profit;
  profit -= temp;
  for (i = 0; i < N - 2; i++) {
    scanf("%d", &temp);
    if (temp - min > profit)
      profit = temp - min;
    if (temp < min)
      min = temp;
  }
  printf("%d\n", profit);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeba(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeaa(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1177 <main+0x57>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    11e7 <main+0xc7>
lea    0xe5f(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x18(%rbp),%eax
sub    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11c2 <main+0xa2>
mov    -0x18(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11d4 <main+0xb4>
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11d9 <main+0xb9>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1189 <main+0x69>
mov    -0x14(%rbp),%esi
lea    0xe12(%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   %rbx
sub    $0x18,%rsp
lea    0xecf(%rip),%rbx
lea    0x14(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
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),%ebp
mov    0xc(%rsp),%eax
mov    %eax,%esi
sub    %ebp,%esi
mov    %esi,0xc(%rsp)
cmpl   $0x3,0x14(%rsp)
jl     11c6 <main+0xa6>
cmp    %ebp,%eax
cmovl  %eax,%ebp
xor    %ebx,%ebx
lea    0xe83(%rip),%r14
lea    0x10(%rsp),%r15
jmp    11a3 <main+0x83>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %ebp,%eax
cmovl  %eax,%ebp
add    $0x1,%ebx
mov    0x14(%rsp),%eax
add    $0xfffffffe,%eax
cmp    %eax,%ebx
jge    11c6 <main+0xa6>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    0x10(%rsp),%eax
mov    %eax,%ecx
sub    %ebp,%ecx
mov    0xc(%rsp),%esi
cmp    %esi,%ecx
jle    1190 <main+0x70>
mov    %ecx,0xc(%rsp)
mov    %ecx,%esi
jmp    1190 <main+0x70>
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
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
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%10 = load i32, i32* %6
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = icmp sgt i32 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = load i32, i32* %5
store i32 %15, i32* %4
br label %16
16: ; preds = %14, %0
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, %17
store i32 %19, i32* %5
store i32 0, i32* %3
br label %20
20: ; preds = %43, %16
%21 = load i32, i32* %3
%22 = load i32, i32* %2
%23 = sub nsw i32 %22, 2
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %46
25: ; preds = %20
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%27 = load i32, i32* %6
%28 = load i32, i32* %4
%29 = sub nsw i32 %27, %28
%30 = load i32, i32* %5
%31 = icmp sgt i32 %29, %30
br i1 %31, label %32, label %36
32: ; preds = %25
%33 = load i32, i32* %6
%34 = load i32, i32* %4
%35 = sub nsw i32 %33, %34
store i32 %35, i32* %5
br label %36
36: ; preds = %32, %25
%37 = load i32, i32* %6
%38 = load i32, i32* %4
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = load i32, i32* %6
store i32 %41, i32* %4
br label %42
42: ; preds = %40, %36
br label %43
43: ; preds = %42
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
br label %20
46: ; preds = %20
%47 = load i32, i32* %5
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %47)
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 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = sub nsw i32 %11, %10
store i32 %12, i32* %2
%13 = load i32, i32* %1
%14 = icmp sgt i32 %13, 2
br i1 %14, label %15, label %35
15: ; preds = %0
%16 = icmp slt i32 %11, %10
%17 = select i1 %16, i32 %11, i32 %10
br label %18
18: ; preds = %15, %27
%19 = phi i32 [ %30, %27 ], [ %17, %15 ]
%20 = phi i32 [ %31, %27 ], [ 0, %15 ]
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%22 = load i32, i32* %3
%23 = sub nsw i32 %22, %19
%24 = load i32, i32* %2
%25 = icmp sgt i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %18
store i32 %23, i32* %2
br label %27
27: ; preds = %26, %18
%28 = phi i32 [ %23, %26 ], [ %24, %18 ]
%29 = icmp slt i32 %22, %19
%30 = select i1 %29, i32 %22, i32 %19
%31 = add nuw nsw i32 %20, 1
%32 = load i32, i32* %1
%33 = add nsw i32 %32, -2
%34 = icmp slt i32 %31, %33
br i1 %34, label %18, label %35
35: ; preds = %27, %0
%36 = phi i32 [ %12, %0 ], [ %28, %27 ]
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
ret i32 0
}