#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 INT_MIN;
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int i, n, x, min, diff;
  int max_diff = INT_MIN;
  scanf("%d", &n);
  scanf("%d", &min);
  for (i = 1; i < n; i++) {
    scanf("%d", &x);
    diff = x - min;
    if (max_diff < diff) {
      max_diff = diff;
    }
    if (min > x) {
      min = x;
    }
  }
  printf("%d\n", max_diff);
  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)
mov    0x2eab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xea7(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11c5 <main+0xa5>
lea    0xe84(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x1c(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11a0 <main+0x80>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    11b2 <main+0x92>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11b7 <main+0x97>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1169 <main+0x49>
mov    -0x28(%rbp),%esi
lea    0xe34(%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   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2eb5(%rip),%rax
mov    (%rax),%ebx
lea    0xec4(%rip),%r14
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1040 <scanf@plt>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
call   1040 <scanf@plt>
cmpl   $0x2,0x8(%rsp)
jl     11a4 <main+0x84>
mov    $0x1,%ebp
lea    0xe97(%rip),%r14
lea    0xc(%rsp),%r15
jmp    1179 <main+0x59>
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
jge    11a4 <main+0x84>
mov    %ebx,%r12d
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
mov    0x4(%rsp),%ecx
mov    %eax,%ebx
sub    %ecx,%ebx
cmp    %ebx,%r12d
cmovge %r12d,%ebx
cmp    %ecx,%eax
jge    1170 <main+0x50>
mov    %eax,0x4(%rsp)
jmp    1170 <main+0x50>
lea    0xe58(%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):
@INT_MIN = global i32 0
@.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
%12 = load i32, i32* @INT_MIN
store i32 %12, i32* %11
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
store i32 1, i32* %6
br label %15
15: ; preds = %36, %2
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %39
19: ; preds = %15
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = sub nsw i32 %21, %22
store i32 %23, i32* %10
%24 = load i32, i32* %11
%25 = load i32, i32* %10
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = load i32, i32* %10
store i32 %28, i32* %11
br label %29
29: ; preds = %27, %19
%30 = load i32, i32* %9
%31 = load i32, i32* %8
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = load i32, i32* %8
store i32 %34, i32* %9
br label %35
35: ; preds = %33, %29
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %15
39: ; preds = %15
%40 = load i32, i32* %11
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
ret i32 0
}

LLVM IR (-O2):
@INT_MIN = global i32 0
@.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 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = load i32, i32* @INT_MIN
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %29
14: ; preds = %2, %25
%15 = phi i32 [ %22, %25 ], [ %9, %2 ]
%16 = phi i32 [ %26, %25 ], [ 1, %2 ]
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = sub nsw i32 %18, %19
%21 = icmp slt i32 %15, %20
%22 = select i1 %21, i32 %20, i32 %15
%23 = icmp slt i32 %18, %19
br i1 %23, label %24, label %25
24: ; preds = %14
store i32 %18, i32* %5
br label %25
25: ; preds = %14, %24
%26 = add nuw nsw i32 %16, 1
%27 = load i32, i32* %3
%28 = icmp slt i32 %26, %27
br i1 %28, label %14, label %29
29: ; preds = %25, %2
%30 = phi i32 [ %9, %2 ], [ %22, %25 ]
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
ret i32 0
}