#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-9;
const int MAXN = 102400;
int a[MAXN];
int n;
int p1, p2;
long long k, ans;
long long cur;
long long total;
class interval_tree {
  int t[4 * MAXN];

 public:
  void inc(int index, int delta = 1, int v = 1, int tl = 1, int tr = n) {
    if (tl == tr) {
      t[v] += delta;
      return;
    }
    int med = (tl + tr) / 2;
    if (index <= med) inc(index, delta, 2 * v, tl, med);
    if (med < index) inc(index, delta, 2 * v + 1, med + 1, tr);
    t[v] = t[2 * v] + t[2 * v + 1];
  }
  int sum(int l, int r, int v = 1, int tl = 1, int tr = n) {
    if (l > r) return 0;
    if (tl == l && tr == r) return t[v];
    int res = 0;
    int med = (tl + tr) / 2;
    if (l <= med) res += sum(l, min(r, med), 2 * v, tl, med);
    if (med < r) res += sum(max(med + 1, l), r, 2 * v + 1, med + 1, tr);
    return res;
  }
} tleft, tright;
void compress() {
  vector<pair<int, int> > v(n);
  for (long long i = 0; i < n; ++i) {
    v[i].second = i;
    v[i].first = a[i];
  }
  sort((v).begin(), (v).end());
  for (long long i = 0; i < n; ++i) v[i].first = i;
  for (long long i = 0; i < n; ++i) a[v[i].second] = v[i].first + 1;
}
int main() {
  cin >> n >> k;
  for (long long i = 0; i < n; ++i) scanf("%d", &a[i]);
  compress();
  cur = 0;
  for (long long i = 0; i < n; ++i) {
    cur += tright.sum(a[i] + 1, n);
    tright.inc(a[i]);
  }
  while (p1 + 1 < n) {
    int val = a[p1];
    cur += tleft.sum(val + 1, n);
    cur += tright.sum(1, val - 1);
    tleft.inc(val);
    while (true) {
      if (p2 + 1 >= n) break;
      if (cur <= k && p1 < p2) break;
      ++p2;
      int val = a[p2 - 1];
      cur -= tleft.sum(val + 1, n);
      cur -= tright.sum(1, val - 1);
      tright.inc(val, -1);
    }
    if (cur <= k && p1 < p2 && p2 < n) ans += n - p2;
    ++p1;
  }
  cout << ans << endl;
}
