#include <bits/stdc++.h>
using namespace std;
int fen[100005];
long long cntl[100005], cntr[100005];
int a[100005];
int n;
map<int, int> comp;
long long temp;
void update(int id, int val) {
  for (; id < 100005; id += id & -id) fen[id] += val;
}
int sum(int r) {
  int s = 0;
  while (r) {
    s += fen[r];
    r -= r & -r;
  }
  return s;
}
long long find(int l, int r) {
  return cntl[n] - cntl[r - 1] - cntr[l + 1] + temp + cntl[l] + cntr[r];
}
int main() {
  long long k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    comp[a[i]] = 1;
  }
  int lst = 1;
  for (auto &x : comp) {
    x.second = lst;
    lst++;
  }
  for (int i = 1; i <= n; i++) a[i] = comp[a[i]];
  for (int i = 1; i <= n; i++) {
    cntl[i] = cntl[i - 1];
    update(a[i], 1);
    cntl[i] += i - sum(a[i]);
  }
  memset(fen, 0, sizeof fen);
  for (int i = n; i >= 1; i--) {
    cntr[i] = cntr[i + 1];
    update(a[i], 1);
    cntr[i] += sum(a[i] - 1);
  }
  memset(fen, 0, sizeof fen);
  int l = 1, r = 2;
  long long ans = 0;
  for (l = 1; l <= n; l++) {
    temp -= sum(a[l] - 1);
    if (l != 1) update(a[l], -1);
    while (l >= r || (r != n + 1 && find(l, r) > k)) {
      update(a[r], 1);
      temp += r - l - sum(a[r]);
      r++;
    }
    if (r != n + 1) ans += n - r + 1;
  }
  cout << ans;
}
