#include <bits/stdc++.h>
using namespace std;
struct MySet {
  int N, S[100001];
  void Init(int X) {
    N = X;
    memset(S, 0, sizeof(S));
  }
  void Add(int X, int Delta) {
    while (X <= N) {
      S[X] += Delta;
      X += X & -X;
    }
  }
  int Sum(int X) {
    int Ans = 0;
    while (X) {
      Ans += S[X];
      X ^= X & -X;
    }
    return Ans;
  }
};
int Data[100000];
int Find(int X, int N) {
  int L = 0, R = N - 1;
  while (true) {
    int Mid = (L + R) / 2;
    if (Data[Mid] == X) return Mid + 1;
    if (Data[Mid] < X)
      L = Mid + 1;
    else
      R = Mid - 1;
  }
}
int main() {
  int N;
  long long K;
  cin >> N >> K;
  static int A[100000];
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    Data[i] = A[i];
  }
  sort(Data, Data + N);
  for (int i = 0; i < N; i++) A[i] = Find(A[i], N);
  static long long Left[100000], Right[100000];
  MySet All;
  All.Init(N);
  Left[0] = 0;
  for (int i = 1; i < N; i++) {
    All.Add(A[i - 1], 1);
    Left[i] = Left[i - 1] + All.Sum(N) - All.Sum(A[i]);
  }
  All.Init(N);
  Right[N - 1] = 0;
  for (int i = N - 2; i >= 0; i--) {
    All.Add(A[i + 1], 1);
    Right[i] = Right[i + 1] + All.Sum(A[i] - 1);
  }
  long long Ans = 0, Total = 0;
  MySet List;
  All.Init(N);
  List.Init(N);
  for (int i = 0; i < N; i++) List.Add(A[i], 1);
  for (int i = 0, j = 0; j < N && Left[i] <= K; i++) {
    if (i == j) {
      Total -= All.Sum(N) - All.Sum(A[i]);
      List.Add(A[i], -1);
      j++;
    }
    Total += List.Sum(A[i] - 1);
    All.Add(A[i], 1);
    while (j < N && Left[i] + Right[j] + Total > K) {
      Total -= All.Sum(N) - All.Sum(A[j]);
      List.Add(A[j++], -1);
    }
    Ans += N - j;
  }
  cout << Ans << endl;
  return 0;
}
