#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 41;
const int mod = 1e9 + 7;
const int inf = 1e9 + 90;
const long long INF = 1e18;
struct st {
  vector<int> t;
  st() { t.resize(N * 4); }
  void upd(int pos, int val, int l = 0, int r = N, int v = 0) {
    if (r - l == 1) {
      t[v] += val;
    } else {
      int m = (l + r) / 2;
      if (pos < m)
        upd(pos, val, l, m, v + v + 1);
      else
        upd(pos, val, m, r, v + v + 2);
      t[v] = t[v + v + 1] + t[v + v + 2];
    }
  }
  int get(int L, int R, int l = 0, int r = N, int v = 0) {
    if (L <= l && r <= R) return t[v];
    if (R <= l || r <= L) return 0;
    int m = (l + r) / 2;
    return get(L, R, l, m, v + v + 1) + get(L, R, m, r, v + v + 2);
  }
};
vector<int> w;
long long ans;
int a[N];
int main() {
  int n;
  long long k;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    w.push_back(a[i]);
  }
  sort(w.begin(), w.end());
  w.resize(unique(w.begin(), w.end()) - w.begin());
  for (int i = 1; i <= n; ++i) {
    a[i] = lower_bound(w.begin(), w.end(), a[i]) - w.begin() + 1;
  }
  long long inv = 0;
  st R;
  st L;
  for (int i = 1; i <= n; ++i) {
    inv += R.get(a[i] + 1, N);
    R.upd(a[i], 1);
  }
  if (inv <= k) cout << n * 1ll * (n - 1) / 2, exit(0);
  int r = 1;
  for (int i = 1; i <= n; ++i) {
    while (r < i) {
      inv -= L.get(a[r] + 1, N);
      inv -= R.get(0, a[r]);
      R.upd(a[r], -1);
      ++r;
    }
    inv += L.get(a[i] + 1, N);
    inv += R.get(0, a[i]);
    L.upd(a[i], 1);
    while (r <= n && inv > k) {
      inv -= L.get(a[r] + 1, N);
      inv -= R.get(0, a[r]);
      R.upd(a[r], -1);
      ++r;
    }
    if (inv <= k) {
      ans += n - r + 1;
    }
  }
  cout << ans;
}
