#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101 * 1000;
int lf[MAXN], rf[MAXN], n, a[MAXN];
vector<int> nums;
void add(int *fen, int pos, int val) {
  while (pos < MAXN) {
    fen[pos] += val;
    pos += pos & -pos;
  }
}
int sum(int *fen, int pos) {
  int tot = 0;
  while (pos) {
    tot += fen[pos];
    pos -= pos & -pos;
  }
  return tot;
}
int main() {
  ios::sync_with_stdio(false);
  long long k;
  cin >> n >> k;
  nums.push_back(-1);
  for (register int i = (0); i < (int)(n); ++i)
    cin >> a[i], nums.push_back(a[i]);
  sort((nums).begin(), (nums).end());
  nums.resize(unique((nums).begin(), (nums).end()) - nums.begin());
  for (register int i = (0); i < (int)(n); ++i)
    a[i] = lower_bound((nums).begin(), (nums).end(), a[i]) - nums.begin();
  long long tot = 0, inv = 0;
  for (register int i = (0); i < (int)(n); ++i) {
    add(rf, a[i], 1);
    inv += sum(rf, ((int)(nums).size())) - sum(rf, a[i]);
  }
  int r = 0;
  for (register int l = (0); l < (int)(n - 1); ++l) {
    add(lf, a[l], 1);
    inv += sum(lf, ((int)(nums).size())) - sum(lf, a[l]);
    inv += sum(rf, a[l] - 1);
    while ((r <= l || inv > k) && r + 1 < n) {
      add(rf, a[r], -1);
      inv -= sum(lf, ((int)(nums).size())) - sum(lf, a[r]);
      inv -= sum(rf, a[r] - 1);
      r++;
    }
    if (inv > k) break;
    tot += n - r;
  }
  cout << tot << endl;
  return 0;
}
