#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 10;
int N;
long long K;
int V[NMAX], Left[NMAX], Right[NMAX], BIT1[NMAX], BIT2[NMAX];
void Update(int *BIT, int pos, int value) {
  for (; pos <= N; pos += pos & -pos) BIT[pos] += value;
}
int Query(int *BIT, int pos) {
  int ret = 0;
  for (; pos >= 1; pos -= pos & -pos) ret += BIT[pos];
  return ret;
}
struct Element {
  int value, pos;
  Element() {}
  Element(int value, int pos) {
    this->value = value;
    this->pos = pos;
  }
  bool operator>(const Element &rhs) const {
    if (value > rhs.value) return true;
    return false;
  }
  bool operator==(const Element &rhs) const { return value == rhs.value; }
} E[NMAX];
int main() {
  ios_base::sync_with_stdio(false);
  int i, j;
  cin >> N >> K;
  for (i = 1; i <= N; ++i) {
    cin >> V[i];
    E[i] = Element(V[i], i);
  }
  sort(E + 1, E + N + 1, greater<Element>());
  j = N;
  for (i = 1; i <= N; ++i) {
    if (E[i] == E[i - 1])
      V[E[i].pos] = V[E[i - 1].pos];
    else
      V[E[i].pos] = j--;
  }
  for (i = 1; i <= N; ++i) {
    Left[i] = Query(BIT1, N) - Query(BIT1, V[i]);
    Update(BIT1, V[i], 1);
  }
  for (i = N; i >= 1; --i) {
    Right[i] = Query(BIT2, V[i] - 1);
    Update(BIT2, V[i], 1);
  }
  memset(BIT1, 0, sizeof(BIT1));
  memset(BIT2, 0, sizeof(BIT2));
  long long res = 0, Count = 0;
  for (i = N - 1; i >= 1; --i) {
    if (V[i] > V[N]) ++Count;
    Count += Left[i];
    Update(BIT1, V[i], 1);
  }
  Update(BIT2, V[N], 1);
  i = N - 1, j = N;
  while (Count > K) {
    if (V[i] > V[N]) --Count;
    Update(BIT1, V[i], -1);
    Count -= Left[i];
    --i;
  }
  if (i == 0) {
    cout << "0\n";
    return 0;
  }
  int val1 = Query(BIT1, N), val2 = Query(BIT1, V[j - 1]);
  while (Count + val1 - val2 + Right[j - 1] <= K && j - 1 > i) {
    --j;
    Count += val1 - val2;
    Count += Right[j];
    val1 = Query(BIT1, N), val2 = Query(BIT1, V[j - 1]);
    Update(BIT2, V[j], 1);
  }
  res += N - j + 1;
  for (--i; i >= 1; --i) {
    Update(BIT1, V[i + 1], -1);
    Count -= Query(BIT2, V[i + 1] - 1);
    Count -= Left[i + 1];
    int val1 = Query(BIT1, N), val2 = Query(BIT1, V[j - 1]);
    while (Count + val1 - val2 + Right[j - 1] <= K && j - 1 > i) {
      --j;
      Count += val1 - val2;
      Count += Right[j];
      val1 = Query(BIT1, N), val2 = Query(BIT1, V[j - 1]);
      Update(BIT2, V[j], 1);
    }
    res += N - j + 1;
  }
  cout << res << '\n';
  return 0;
}
