integer mi,ma,md
integer N
integer cnt
integer,allocatable,dimension(:)::mins
integer A
read*,N
read*,A
allocate(mins(N))
cnt=1
mins(1)=A
do i=2,N
  read*,A
  if(A>mins(cnt))then
    mi=0
    ma=cnt 
    do while(mi+1<ma)
      md=(mi+ma-1)/2+1
      if(mins(md)<A)then
        ma=md
      else
        mi=md
      endif
    end do
    mins(ma)=A
  else
    cnt=cnt+1
    mins(cnt)=A
  end if
end do
print"(I0)",cnt
end
; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QFEmins.0 = internal unnamed_addr global ptr null
@_QQcl.9c3a6f538f14ce8ca3d205da77c1a132 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3754/source.f\00"
@_QQcl.28493029 = linkonce constant [4 x i8] c"(I0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9c3a6f538f14ce8ca3d205da77c1a132, i32 6)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9c3a6f538f14ce8ca3d205da77c1a132, i32 7)
  %7 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %1, i32 4)
  %8 = call i32 @_FortranAioEndIoStatement(ptr %6)
  %9 = load i32, ptr %2, align 4, !tbaa !3
  %10 = call i32 @llvm.smax.i32(i32 %9, i32 0)
  %11 = zext i32 %10 to i64
  %12 = shl nuw nsw i64 %11, 2
  %13 = call ptr @malloc(i64 %12)
  store ptr %13, ptr @_QFEmins.0, align 8, !tbaa !7
  %14 = load i32, ptr %1, align 4, !tbaa !3
  store i32 %14, ptr %13, align 4, !tbaa !3
  %.0123174 = add i32 %9, -1
  %15 = icmp sgt i32 %.0123174, 0
  br i1 %15, label %.lr.ph178, label %._crit_edge179

.lr.ph178:                                        ; preds = %0, %._crit_edge
  %.0123176 = phi i32 [ %.0123, %._crit_edge ], [ %.0123174, %0 ]
  %.0126175 = phi i32 [ %.1, %._crit_edge ], [ 1, %0 ]
  %16 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9c3a6f538f14ce8ca3d205da77c1a132, i32 12)
  %17 = call i1 @_FortranAioInputInteger(ptr %16, ptr nonnull %1, i32 4)
  %18 = call i32 @_FortranAioEndIoStatement(ptr %16)
  %19 = load i32, ptr %1, align 4, !tbaa !3
  %.unpack = load ptr, ptr @_QFEmins.0, align 8, !tbaa !7
  %20 = sext i32 %.0126175 to i64
  %21 = add nsw i64 %20, -1
  %22 = getelementptr i32, ptr %.unpack, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !3
  %24 = icmp sgt i32 %19, %23
  br i1 %24, label %.preheader, label %36

.preheader:                                       ; preds = %.lr.ph178
  %25 = icmp sgt i32 %.0126175, 1
  br i1 %25, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.0173 = phi i32 [ %.0., %.lr.ph ], [ 0, %.preheader ]
  %.0124172 = phi i32 [ %..0124, %.lr.ph ], [ %.0126175, %.preheader ]
  %26 = add nsw i32 %.0124172, -1
  %27 = add i32 %26, %.0173
  %28 = sdiv i32 %27, 2
  %29 = add nsw i32 %28, 1
  %30 = sext i32 %28 to i64
  %31 = getelementptr i32, ptr %.unpack, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !3
  %33 = icmp slt i32 %32, %19
  %..0124 = select i1 %33, i32 %29, i32 %.0124172
  %.0. = select i1 %33, i32 %.0173, i32 %29
  %34 = add i32 %.0., 1
  %35 = icmp slt i32 %34, %..0124
  br i1 %35, label %.lr.ph, label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = sext i32 %..0124 to i64
  %.pre181 = add nsw i64 %.pre, -1
  br label %._crit_edge

36:                                               ; preds = %.lr.ph178
  %37 = add i32 %.0126175, 1
  %38 = sext i32 %37 to i64
  %39 = add nsw i64 %38, -1
  br label %._crit_edge

._crit_edge:                                      ; preds = %.preheader, %._crit_edge.loopexit, %36
  %.pre-phi182.sink = phi i64 [ %39, %36 ], [ %.pre181, %._crit_edge.loopexit ], [ %21, %.preheader ]
  %.1 = phi i32 [ %37, %36 ], [ %.0126175, %._crit_edge.loopexit ], [ %.0126175, %.preheader ]
  %40 = getelementptr i32, ptr %.unpack, i64 %.pre-phi182.sink
  store i32 %19, ptr %40, align 4, !tbaa !3
  %.0123 = add i32 %.0123176, -1
  %41 = icmp sgt i32 %.0123, 0
  br i1 %41, label %.lr.ph178, label %._crit_edge179

._crit_edge179:                                   ; preds = %._crit_edge, %0
  %.0126.lcssa = phi i32 [ 1, %0 ], [ %.1, %._crit_edge ]
  %42 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28493029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.9c3a6f538f14ce8ca3d205da77c1a132, i32 30)
  %43 = call i1 @_FortranAioOutputInteger32(ptr %42, i32 %.0126.lcssa)
  %44 = call i32 @_FortranAioEndIoStatement(ptr %42)
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
