      PROGRAM kagamiMochi
      IMPLICIT NONE
      INTEGER :: N
      INTEGER,ALLOCATABLE :: d(:)
      INTEGER :: a, buffer(2),ans
      LOGICAL :: flag
      
      READ*,N
      ALLOCATE( d(N) )
      DO a = 1,N
        READ*,d(a)
      END DO
      
      DO while(.TRUE.)
      flag = .TRUE.
        DO a = 1,N-1
          IF( d(a)<d(a+1) )THEN
            buffer(1:2) = d(a:a+1)
            d(a) = buffer(2); d(a+1) = buffer(1)
            flag = .FALSE.
          END IF
          
        END DO
        
        IF(flag) EXIT
      END DO
      
      
      ans = 1
      DO a = 1,N-1
        IF( d(a)>d(a+1) )THEN
          ans = ans + 1
        END IF
      END DO
      
      
      print'(I0)',ans
      
      
      
      END PROGRAM
; 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"

@_QFEd.0 = internal unnamed_addr global ptr null
@_QQcl.a8050c94371c73104ae5e306f7c80744 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_6438/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 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.a8050c94371c73104ae5e306f7c80744, i32 8)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 4)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = load i32, ptr %1, align 4, !tbaa !3
  %6 = call i32 @llvm.smax.i32(i32 %5, i32 0)
  %7 = zext i32 %6 to i64
  %8 = shl nuw nsw i64 %7, 2
  %9 = call ptr @malloc(i64 %8)
  store ptr %9, ptr @_QFEd.0, align 8, !tbaa !7
  %10 = icmp sgt i32 %5, 0
  br i1 %10, label %.lr.ph.preheader, label %.preheader213

.lr.ph.preheader:                                 ; preds = %0
  %11 = zext i32 %5 to i64
  br label %.lr.ph

.preheader213.loopexit:                           ; preds = %.lr.ph
  %.unpack165.pre = load ptr, ptr @_QFEd.0, align 8
  br label %.preheader213

.preheader213:                                    ; preds = %.preheader213.loopexit, %0
  %.unpack = phi ptr [ %.unpack165.pre, %.preheader213.loopexit ], [ %9, %0 ]
  br label %17

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.a8050c94371c73104ae5e306f7c80744, i32 11)
  %.unpack201 = load ptr, ptr @_QFEd.0, align 8, !tbaa !7
  %13 = add nsw i64 %indvars.iv, -1
  %14 = getelementptr i32, ptr %.unpack201, i64 %13
  %15 = call i1 @_FortranAioInputInteger(ptr %12, ptr %14, i32 4)
  %16 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %11
  br i1 %exitcond.not, label %.preheader213.loopexit, label %.lr.ph

17:                                               ; preds = %.preheader213, %._crit_edge
  %18 = load i32, ptr %1, align 4, !tbaa !3
  %19 = add i32 %18, -1
  %20 = sext i32 %19 to i64
  %21 = icmp sgt i32 %19, 0
  br i1 %21, label %.lr.ph215, label %._crit_edge.thread

.lr.ph215:                                        ; preds = %17, %31
  %indvars.iv222 = phi i64 [ %indvars.iv.next223, %31 ], [ 1, %17 ]
  %indvar = phi i64 [ %indvar.next, %31 ], [ 0, %17 ]
  %.0214 = phi i32 [ %.1, %31 ], [ 1, %17 ]
  %22 = add nsw i64 %indvars.iv222, -1
  %23 = getelementptr i32, ptr %.unpack, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !3
  %indvars.iv.next223 = add nuw nsw i64 %indvars.iv222, 1
  %sext232 = shl i64 %indvars.iv.next223, 32
  %25 = ashr exact i64 %sext232, 32
  %26 = add nsw i64 %25, -1
  %27 = getelementptr i32, ptr %.unpack, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !3
  %29 = icmp slt i32 %24, %28
  br i1 %29, label %.preheader.preheader, label %31

.preheader.preheader:                             ; preds = %.lr.ph215
  %30 = shl nuw nsw i64 %indvar, 2
  %uglygep = getelementptr i8, ptr %.unpack, i64 %30
  %.sroa.0.0.copyload = load i32, ptr %uglygep, align 4, !tbaa !3
  %.sroa.2.0.uglygep.sroa_idx = getelementptr inbounds i8, ptr %uglygep, i64 4
  %.sroa.2.0.copyload = load i32, ptr %.sroa.2.0.uglygep.sroa_idx, align 4, !tbaa !3
  store i32 %.sroa.2.0.copyload, ptr %23, align 4, !tbaa !3
  store i32 %.sroa.0.0.copyload, ptr %27, align 4, !tbaa !3
  br label %31

31:                                               ; preds = %.preheader.preheader, %.lr.ph215
  %.1 = phi i32 [ 0, %.preheader.preheader ], [ %.0214, %.lr.ph215 ]
  %indvar.next = add nuw nsw i64 %indvar, 1
  %exitcond225.not = icmp eq i64 %indvar.next, %20
  br i1 %exitcond225.not, label %._crit_edge, label %.lr.ph215

._crit_edge:                                      ; preds = %31
  %.not = icmp eq i32 %.1, 0
  br i1 %.not, label %17, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %17, %._crit_edge
  %32 = load i32, ptr %1, align 4, !tbaa !3
  %33 = add i32 %32, -1
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %.lr.ph218, label %._crit_edge219

.lr.ph218:                                        ; preds = %._crit_edge.thread
  %35 = zext i32 %33 to i64
  %min.iters.check = icmp ult i32 %33, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.lr.ph218
  %36 = add nsw i64 %35, -1
  %37 = trunc i64 %36 to i32
  %38 = icmp ugt i32 %37, 2147483645
  %39 = icmp ugt i64 %36, 4294967295
  %40 = or i1 %38, %39
  br i1 %40, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i64 %35, 4294967288
  %ind.end = or i64 %n.vec, 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ <i32 1, i32 0, i32 0, i32 0>, %vector.ph ], [ %52, %vector.body ]
  %vec.phi235 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %53, %vector.body ]
  %41 = getelementptr i32, ptr %.unpack, i64 %index
  %wide.load = load <4 x i32>, ptr %41, align 4, !tbaa !3
  %42 = getelementptr i32, ptr %41, i64 4
  %wide.load236 = load <4 x i32>, ptr %42, align 4, !tbaa !3
  %43 = shl i64 %index, 32
  %44 = ashr exact i64 %43, 32
  %45 = or i64 %44, 1
  %46 = getelementptr i32, ptr %.unpack, i64 %45
  %wide.load237 = load <4 x i32>, ptr %46, align 4, !tbaa !3
  %47 = getelementptr i32, ptr %46, i64 4
  %wide.load238 = load <4 x i32>, ptr %47, align 4, !tbaa !3
  %48 = icmp sgt <4 x i32> %wide.load, %wide.load237
  %49 = icmp sgt <4 x i32> %wide.load236, %wide.load238
  %50 = zext <4 x i1> %48 to <4 x i32>
  %51 = zext <4 x i1> %49 to <4 x i32>
  %52 = add <4 x i32> %vec.phi, %50
  %53 = add <4 x i32> %vec.phi235, %51
  %index.next = add nuw i64 %index, 8
  %54 = icmp eq i64 %index.next, %n.vec
  br i1 %54, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %53, %52
  %55 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %35
  br i1 %cmp.n, label %._crit_edge219, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %vector.scevcheck, %.lr.ph218, %middle.block
  %indvars.iv226.ph = phi i64 [ 1, %vector.scevcheck ], [ 1, %.lr.ph218 ], [ %ind.end, %middle.block ]
  %.0139216.ph = phi i32 [ 1, %vector.scevcheck ], [ 1, %.lr.ph218 ], [ %55, %middle.block ]
  %xtraiter = and i64 %35, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %56 = add nsw i64 %indvars.iv226.ph, -1
  %57 = getelementptr i32, ptr %.unpack, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !3
  %indvars.iv.next227.prol = add nuw nsw i64 %indvars.iv226.ph, 1
  %sext.prol = shl i64 %indvars.iv.next227.prol, 32
  %59 = ashr exact i64 %sext.prol, 32
  %60 = add nsw i64 %59, -1
  %61 = getelementptr i32, ptr %.unpack, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !3
  %63 = icmp sgt i32 %58, %62
  %64 = zext i1 %63 to i32
  %spec.select.prol = add i32 %.0139216.ph, %64
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %spec.select.lcssa.unr = phi i32 [ undef, %scalar.ph.preheader ], [ %spec.select.prol, %scalar.ph.prol ]
  %indvars.iv226.unr = phi i64 [ %indvars.iv226.ph, %scalar.ph.preheader ], [ %indvars.iv.next227.prol, %scalar.ph.prol ]
  %.0139216.unr = phi i32 [ %.0139216.ph, %scalar.ph.preheader ], [ %spec.select.prol, %scalar.ph.prol ]
  %65 = icmp eq i64 %indvars.iv226.ph, %35
  br i1 %65, label %._crit_edge219, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv226 = phi i64 [ %indvars.iv.next227.1, %scalar.ph ], [ %indvars.iv226.unr, %scalar.ph.prol.loopexit ]
  %.0139216 = phi i32 [ %spec.select.1, %scalar.ph ], [ %.0139216.unr, %scalar.ph.prol.loopexit ]
  %66 = add i64 %indvars.iv226, -1
  %67 = getelementptr i32, ptr %.unpack, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !3
  %indvars.iv.next227 = add nuw nsw i64 %indvars.iv226, 1
  %sext = shl i64 %indvars.iv.next227, 32
  %69 = ashr exact i64 %sext, 32
  %70 = add nsw i64 %69, -1
  %71 = getelementptr i32, ptr %.unpack, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !3
  %73 = icmp sgt i32 %68, %72
  %74 = zext i1 %73 to i32
  %spec.select = add i32 %.0139216, %74
  %75 = getelementptr i32, ptr %.unpack, i64 %indvars.iv226
  %76 = load i32, ptr %75, align 4, !tbaa !3
  %indvars.iv.next227.1 = add nuw nsw i64 %indvars.iv226, 2
  %sext.1 = shl i64 %indvars.iv.next227.1, 32
  %77 = ashr exact i64 %sext.1, 32
  %78 = add nsw i64 %77, -1
  %79 = getelementptr i32, ptr %.unpack, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !3
  %81 = icmp sgt i32 %76, %80
  %82 = zext i1 %81 to i32
  %spec.select.1 = add i32 %spec.select, %82
  %exitcond229.not.1 = icmp eq i64 %indvars.iv.next227, %35
  br i1 %exitcond229.not.1, label %._crit_edge219, label %scalar.ph, !llvm.loop !12

._crit_edge219:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %._crit_edge.thread
  %.0139.lcssa = phi i32 [ 1, %._crit_edge.thread ], [ %55, %middle.block ], [ %spec.select.lcssa.unr, %scalar.ph.prol.loopexit ], [ %spec.select.1, %scalar.ph ]
  %83 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28493029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.a8050c94371c73104ae5e306f7c80744, i32 37)
  %84 = call i1 @_FortranAioOutputInteger32(ptr %83, i32 %.0139.lcssa)
  %85 = call i32 @_FortranAioEndIoStatement(ptr %83)
  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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #2

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) }
attributes #2 = { nocallback nofree nosync nounwind 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}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !10}
