program kadai
   implicit none
    integer(8)  ::  n,k
    integer,allocatable  ::  a(:)
    integer(8)  ::  i,j
    integer(8)  ::  big
    integer(8)  ::  num1,num2,num
    integer(8)  ::  small
    integer(8)  ::  kari

    read(*,*) n,k
    allocate(a(n))
    read(*,*) a

    num=0
    big=0
    small=0
    kari=0

    do i=1,n-1
        do j=i+1,n
            if (a(i)>a(j)) then
                big=big+1
            end if
            if (a(i)<a(j)) then
                small=small+1
            end if
        end do
    end do


    !big=mod(big,10**9+7)
    !small=mod(small,10**9+7)

    !kari=dble(k-1)*dble(k)/2
    !kari=mod(kari,10**9+7)
    !write(*,*) kari
    small=mod((mod(k*(k-1)/2,10**9+7))*small,10**9+7)
    big=mod((mod(k*(k+1)/2,10**9+7))*big,10**9+7)
    !num1=dble(kari)*dble(small)
    !num1=mod(num1,10**9+7)
    !kari=mod(kari+k,10**9+7)
    !num2=dble(kari)*dble(big)
   ! write(*,*) num1,num2
    !num2=mod(num2,10**9+7)
   ! write(*,*) num2
    !num=mod(num1+num2,10**9+7)

    write(*,*) mod(big+small,10**9+7)

stop
contains

end program kadai
; 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"

@_QFEa.0 = internal unnamed_addr global ptr null
@_QFEa.8 = internal unnamed_addr global i64 0
@_QQcl.19eff385b39218b195cf95ba7918fa06 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3411/source.f\00"
@_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

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #1 {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.19eff385b39218b195cf95ba7918fa06, i32 11)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 8)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 8)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = load i64, ptr %3, align 8, !tbaa !3
  %9 = call i64 @llvm.smax.i64(i64 %8, i64 0)
  %10 = shl i64 %9, 2
  %11 = call ptr @malloc(i64 %10)
  store ptr %11, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %9, ptr @_QFEa.8, align 8, !tbaa !7
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.19eff385b39218b195cf95ba7918fa06, i32 13)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack130.unpack.unpack132 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  store ptr %.unpack, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack130.unpack.unpack132, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %13 = call i1 @_FortranAioInputDescriptor(ptr %12, ptr nonnull %1)
  %14 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %15 = load i64, ptr %3, align 8, !tbaa !3
  %16 = add i64 %15, -1
  %17 = icmp sgt i64 %16, 0
  br i1 %17, label %.lr.ph164, label %._crit_edge

.lr.ph164:                                        ; preds = %0
  %.unpack135 = load ptr, ptr @_QFEa.0, align 8
  br label %.lr.ph

.loopexit:                                        ; preds = %scalar.ph, %middle.block
  %spec.select.lcssa = phi i64 [ %45, %middle.block ], [ %spec.select, %scalar.ph ]
  %.2.lcssa = phi i64 [ %46, %middle.block ], [ %.2, %scalar.ph ]
  %exitcond.not = icmp eq i64 %22, %15
  %indvar.next = add i64 %indvar, 1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.loopexit, %.lr.ph164
  %indvar = phi i64 [ %indvar.next, %.loopexit ], [ 0, %.lr.ph164 ]
  %18 = phi i64 [ %22, %.loopexit ], [ 1, %.lr.ph164 ]
  %.0163 = phi i64 [ %.2.lcssa, %.loopexit ], [ 0, %.lr.ph164 ]
  %.0110162 = phi i64 [ %spec.select.lcssa, %.loopexit ], [ 0, %.lr.ph164 ]
  %19 = sub i64 %16, %indvar
  %smin = call i64 @llvm.smin.i64(i64 %19, i64 1)
  %20 = add i64 %indvar, %smin
  %21 = sub i64 %15, %20
  %22 = add nuw i64 %18, 1
  %23 = sub i64 %15, %18
  %24 = add i64 %18, -1
  %25 = getelementptr i32, ptr %.unpack135, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !3
  %min.iters.check = icmp ult i64 %21, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %21, -4
  %ind.end = sub i64 %23, %n.vec
  %ind.end167 = add i64 %22, %n.vec
  %27 = insertelement <2 x i64> <i64 poison, i64 0>, i64 %.0163, i64 0
  %28 = insertelement <2 x i64> <i64 poison, i64 0>, i64 %.0110162, i64 0
  %broadcast.splatinsert = insertelement <2 x i32> poison, i32 %26, i64 0
  %broadcast.splat = shufflevector <2 x i32> %broadcast.splatinsert, <2 x i32> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert173 = insertelement <2 x i32> poison, i32 %26, i64 0
  %broadcast.splat174 = shufflevector <2 x i32> %broadcast.splatinsert173, <2 x i32> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ %27, %vector.ph ], [ %42, %vector.body ]
  %vec.phi169 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %43, %vector.body ]
  %vec.phi170 = phi <2 x i64> [ %28, %vector.ph ], [ %36, %vector.body ]
  %vec.phi171 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %37, %vector.body ]
  %29 = add i64 %18, %index
  %30 = getelementptr i32, ptr %.unpack135, i64 %29
  %wide.load = load <2 x i32>, ptr %30, align 4, !tbaa !3
  %31 = getelementptr i32, ptr %30, i64 2
  %wide.load172 = load <2 x i32>, ptr %31, align 4, !tbaa !3
  %32 = icmp sgt <2 x i32> %broadcast.splat, %wide.load
  %33 = icmp sgt <2 x i32> %broadcast.splat174, %wide.load172
  %34 = zext <2 x i1> %32 to <2 x i64>
  %35 = zext <2 x i1> %33 to <2 x i64>
  %36 = add <2 x i64> %vec.phi170, %34
  %37 = add <2 x i64> %vec.phi171, %35
  %38 = icmp slt <2 x i32> %broadcast.splat, %wide.load
  %39 = icmp slt <2 x i32> %broadcast.splat174, %wide.load172
  %40 = zext <2 x i1> %38 to <2 x i64>
  %41 = zext <2 x i1> %39 to <2 x i64>
  %42 = add <2 x i64> %vec.phi, %40
  %43 = add <2 x i64> %vec.phi169, %41
  %index.next = add nuw i64 %index, 4
  %44 = icmp eq i64 %index.next, %n.vec
  br i1 %44, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx175 = add <2 x i64> %37, %36
  %45 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx175)
  %bin.rdx = add <2 x i64> %43, %42
  %46 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %21, %n.vec
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph, %middle.block
  %.ph = phi i64 [ %23, %.lr.ph ], [ %ind.end, %middle.block ]
  %.ph177 = phi i64 [ %22, %.lr.ph ], [ %ind.end167, %middle.block ]
  %.1160.ph = phi i64 [ %.0163, %.lr.ph ], [ %46, %middle.block ]
  %.1111159.ph = phi i64 [ %.0110162, %.lr.ph ], [ %45, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %47 = phi i64 [ %57, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %48 = phi i64 [ %56, %scalar.ph ], [ %.ph177, %scalar.ph.preheader ]
  %.1160 = phi i64 [ %.2, %scalar.ph ], [ %.1160.ph, %scalar.ph.preheader ]
  %.1111159 = phi i64 [ %spec.select, %scalar.ph ], [ %.1111159.ph, %scalar.ph.preheader ]
  %49 = add i64 %48, -1
  %50 = getelementptr i32, ptr %.unpack135, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !3
  %52 = icmp sgt i32 %26, %51
  %53 = zext i1 %52 to i64
  %spec.select = add i64 %.1111159, %53
  %54 = icmp slt i32 %26, %51
  %55 = zext i1 %54 to i64
  %.2 = add i64 %.1160, %55
  %56 = add i64 %48, 1
  %57 = add nsw i64 %47, -1
  %58 = icmp sgt i64 %47, 1
  br i1 %58, label %scalar.ph, label %.loopexit, !llvm.loop !12

._crit_edge:                                      ; preds = %.loopexit, %0
  %.0110.lcssa = phi i64 [ 0, %0 ], [ %spec.select.lcssa, %.loopexit ]
  %.0.lcssa = phi i64 [ 0, %0 ], [ %.2.lcssa, %.loopexit ]
  %59 = load i64, ptr %2, align 8, !tbaa !3
  %60 = add i64 %59, -1
  %61 = mul i64 %60, %59
  %62 = sdiv i64 %61, 2
  %63 = srem i64 %62, 1000000007
  %64 = mul i64 %63, %.0.lcssa
  %65 = srem i64 %64, 1000000007
  %66 = add i64 %59, 1
  %67 = mul i64 %66, %59
  %68 = sdiv i64 %67, 2
  %69 = srem i64 %68, 1000000007
  %70 = mul i64 %69, %.0110.lcssa
  %71 = srem i64 %70, 1000000007
  %72 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.19eff385b39218b195cf95ba7918fa06, i32 49)
  %73 = add nsw i64 %71, %65
  %.lhs.trunc = trunc i64 %73 to i32
  %74 = srem i32 %.lhs.trunc, 1000000007
  %.sext = sext i32 %74 to i64
  %75 = call i1 @_FortranAioOutputInteger64(ptr %72, i64 %.sext)
  %76 = call i32 @_FortranAioEndIoStatement(ptr %72)
  %77 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

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 i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

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

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #2

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { noreturn }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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, !11, !10}
