#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*/ free(unsigned int *);
unsigned int *malloc(int);
int /*<<< orphan*/ memset(unsigned int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ proc(unsigned int *, unsigned int, unsigned int);
int /*<<< orphan*/ scanf(char *, unsigned int *);
int main() {
  unsigned int n;
  scanf("%u", &n);
  unsigned int len = 0;
  unsigned int *d;
  d = malloc(sizeof(unsigned int) * n);
  memset(d, 0, sizeof(unsigned int) * n);
  for (int i = 0; i < n; i++) {
    unsigned int a;
    scanf("%u", &a);
    if (0 == i) {
      d[0] = a;
      len++;
    } else {
      if (a < d[0]) {
        d[0] = a;
      } else if (a > d[len - 1]) {
        d[len] = a;
        len++;
      } else {
        proc(d, a, len);
      }
    }
  }
  free(d);
  printf("%u\n", len);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    126d <main+0x10d>
lea    0xe3a(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <scanf@plt>
xor    %eax,%eax
cmp    -0x1c(%rbp),%eax
jne    11f1 <main+0x91>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    125a <main+0xfa>
mov    -0x20(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jae    120e <main+0xae>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1255 <main+0xf5>
mov    -0x20(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
mov    %edx,%edx
cmp    (%rcx,%rdx,4),%eax
jbe    1241 <main+0xe1>
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1250 <main+0xf0>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <proc@plt>
jmp    1255 <main+0xf5>
jmp    125a <main+0xfa>
jmp    125f <main+0xff>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b3 <main+0x53>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%esi
lea    0xd83(%rip),%rdi
call   1040 <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    0xe8d(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x8(%rsp),%ebp
shl    $0x2,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
xor    %r14d,%r14d
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1050 <memset@plt>
cmpl   $0x0,0x8(%rsp)
je     123d <main+0xdd>
lea    0xe51(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
mov    0xc(%rsp),%eax
mov    %eax,(%rbx)
mov    $0x1,%r14d
cmpl   $0x2,0x8(%rsp)
jb     123d <main+0xdd>
mov    $0x1,%ebp
lea    0xe28(%rip),%r15
lea    0xc(%rsp),%r12
mov    $0x1,%r14d
jmp    11fb <main+0x9b>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %esi,(%rbx)
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
jae    123d <main+0xdd>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
mov    0xc(%rsp),%esi
cmp    (%rbx),%esi
jb     11f0 <main+0x90>
lea    -0x1(%r14),%eax
cmp    (%rbx,%rax,4),%esi
jbe    1230 <main+0xd0>
mov    %r14d,%eax
mov    %esi,(%rbx,%rax,4)
add    $0x1,%r14d
jmp    11f2 <main+0x92>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14d,%edx
call   1060 <proc@plt>
jmp    11f2 <main+0x92>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xdb7(%rip),%rdi
mov    %r14d,%esi
call   1040 <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"%u\00"
@.str.1 = [4 x i8] c"%u\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)
store i32 0, i32* %3
%8 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = mul i64 4, %9
%11 = trunc i64 %10 to i32
%12 = call i32* @malloc(i32 %11)
store i32* %12, i32** %4
%13 = load i32*, i32** %4
%14 = load i32, i32* %2
%15 = zext i32 %14 to i64
%16 = mul i64 4, %15
%17 = trunc i64 %16 to i32
%18 = call i32 @memset(i32* %13, i32 0, i32 %17)
store i32 0, i32* %5
br label %19
19: ; preds = %68, %0
%20 = load i32, i32* %5
%21 = load i32, i32* %2
%22 = icmp ult i32 %20, %21
br i1 %22, label %23, label %71
23: ; preds = %19
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%25 = load i32, i32* %5
%26 = icmp eq i32 0, %25
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* %6
%29 = load i32*, i32** %4
%30 = getelementptr inbounds i32, i32* %29, i64 0
store i32 %28, i32* %30
%31 = load i32, i32* %3
%32 = add i32 %31, 1
store i32 %32, i32* %3
br label %67
33: ; preds = %23
%34 = load i32, i32* %6
%35 = load i32*, i32** %4
%36 = getelementptr inbounds i32, i32* %35, i64 0
%37 = load i32, i32* %36
%38 = icmp ult i32 %34, %37
br i1 %38, label %39, label %43
39: ; preds = %33
%40 = load i32, i32* %6
%41 = load i32*, i32** %4
%42 = getelementptr inbounds i32, i32* %41, i64 0
store i32 %40, i32* %42
br label %66
43: ; preds = %33
%44 = load i32, i32* %6
%45 = load i32*, i32** %4
%46 = load i32, i32* %3
%47 = sub i32 %46, 1
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %45, i64 %48
%50 = load i32, i32* %49
%51 = icmp ugt i32 %44, %50
br i1 %51, label %52, label %60
52: ; preds = %43
%53 = load i32, i32* %6
%54 = load i32*, i32** %4
%55 = load i32, i32* %3
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
store i32 %53, i32* %57
%58 = load i32, i32* %3
%59 = add i32 %58, 1
store i32 %59, i32* %3
br label %65
60: ; preds = %43
%61 = load i32*, i32** %4
%62 = load i32, i32* %6
%63 = load i32, i32* %3
%64 = call i32 @proc(i32* %61, i32 %62, i32 %63)
br label %65
65: ; preds = %60, %52
br label %66
66: ; preds = %65, %39
br label %67
67: ; preds = %66, %27
br label %68
68: ; preds = %67
%69 = load i32, i32* %5
%70 = add nsw i32 %69, 1
store i32 %70, i32* %5
br label %19
71: ; preds = %19
%72 = load i32*, i32** %4
%73 = call i32 @free(i32* %72)
%74 = load i32, i32* %3
%75 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %74)
ret i32 0
}

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