#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 */
scalar_t__ getCnt(int *, int, int, int);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ quick_sort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int *a = malloc(n * sizeof(int));
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  quick_sort(a, 0, n - 1);
  int cnt = 0;
  for (int i = 0; i < n - 1; i++) {
    cnt += getCnt(a, n, k, i);
  }
  printf("%d\n", cnt);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c6 <main+0x76>
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118f <main+0x3f>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1070 <quick_sort@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1223 <main+0xd3>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   1040 <getCnt@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e5 <main+0x95>
mov    -0x20(%rbp),%esi
lea    0xdd9(%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   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
xor    %r12d,%r12d
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    (%rsp),%r13d
lea    0x0(,%r13,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %r13d,%r13d
jle    11be <main+0x6e>
lea    0xe6f(%rip),%r15
mov    %r14,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%rbp
movslq (%rsp),%r13
add    $0x4,%rbx
cmp    %r13,%rbp
jl     11a0 <main+0x50>
add    $0xffffffff,%r13d
mov    %r14,%rdi
xor    %esi,%esi
mov    %r13d,%edx
call   1070 <quick_sort@plt>
mov    (%rsp),%esi
cmp    $0x2,%esi
jl     11fe <main+0xae>
xor    %ebp,%ebp
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    0x4(%rsp),%edx
mov    %r14,%rdi
mov    %ebp,%ecx
call   1040 <getCnt@plt>
add    %eax,%r12d
add    $0x1,%ebp
mov    (%rsp),%esi
lea    -0x1(%rsi),%eax
cmp    %eax,%ebp
jl     11e0 <main+0x90>
lea    0xe01(%rip),%rdi
mov    %r12d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i32* @malloc(i32 %12)
store i32* %13, i32** %4
store i32 0, i32* %5
br label %14
14: ; preds = %24, %0
%15 = load i32, i32* %5
%16 = load i32, i32* %2
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %18
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %14
27: ; preds = %14
%28 = load i32*, i32** %4
%29 = load i32, i32* %2
%30 = sub nsw i32 %29, 1
%31 = call i32 @quick_sort(i32* %28, i32 0, i32 %30)
store i32 0, i32* %6
store i32 0, i32* %7
br label %32
32: ; preds = %47, %27
%33 = load i32, i32* %7
%34 = load i32, i32* %2
%35 = sub nsw i32 %34, 1
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %50
37: ; preds = %32
%38 = load i32*, i32** %4
%39 = load i32, i32* %2
%40 = load i32, i32* %3
%41 = load i32, i32* %7
%42 = call i64 @getCnt(i32* %38, i32 %39, i32 %40, i32 %41)
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = add nsw i64 %44, %42
%46 = trunc i64 %45 to i32
store i32 %46, i32* %6
br label %47
47: ; preds = %37
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %32
50: ; preds = %32
%51 = load i32, i32* %6
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%6 = load i32, i32* %1
%7 = shl i32 %6, 2
%8 = call i32* @malloc(i32 %7)
%9 = icmp sgt i32 %6, 0
br i1 %9, label %16, label %10
10: ; preds = %16, %0
%11 = phi i32 [ %6, %0 ], [ %21, %16 ]
%12 = add nsw i32 %11, -1
%13 = call i32 @quick_sort(i32* %8, i32 0, i32 %12)
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 1
br i1 %15, label %27, label %24
16: ; preds = %0, %16
%17 = phi i64 [ %20, %16 ], [ 0, %0 ]
%18 = getelementptr inbounds i32, i32* %8, i64 %17
%19 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = add nuw nsw i64 %17, 1
%21 = load i32, i32* %1
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %16, label %10
24: ; preds = %27, %10
%25 = phi i32 [ 0, %10 ], [ %34, %27 ]
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %25)
ret i32 0
27: ; preds = %10, %27
%28 = phi i32 [ %36, %27 ], [ %14, %10 ]
%29 = phi i32 [ %35, %27 ], [ 0, %10 ]
%30 = phi i32 [ %34, %27 ], [ 0, %10 ]
%31 = load i32, i32* %2
%32 = call i64 @getCnt(i32* %8, i32 %28, i32 %31, i32 %29)
%33 = trunc i64 %32 to i32
%34 = add i32 %30, %33
%35 = add nuw nsw i32 %29, 1
%36 = load i32, i32* %1
%37 = add nsw i32 %36, -1
%38 = icmp slt i32 %35, %37
br i1 %38, label %27, label %24
}