#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 17;
struct ordered_multiset {
  int seg[4 * MAXN], a[MAXN], sz;
  ordered_multiset() {
    for (int i = 0; i < 4 * MAXN; i++) seg[i] = 0;
    for (int i = 0; i < MAXN; i++) a[i] = 0;
    sz = 0;
  }
  void add(int pos, int val, int v = 1, int l = 0, int r = MAXN) {
    if (pos < l || r <= pos) return;
    if (l + 1 == r) {
      seg[v] += val;
      return;
    }
    const int mid = (l + r) / 2;
    add(pos, val, v << 1, l, mid);
    add(pos, val, (v << 1) + 1, mid, r);
    seg[v] = seg[v << 1] + seg[(v << 1) + 1];
  }
  int get(int lp, int rp, int v = 1, int l = 0, int r = MAXN) {
    if (rp <= l || r <= lp) return 0;
    if (lp <= l && r <= rp) {
      return seg[v];
    }
    const int mid = (l + r) / 2;
    return get(lp, rp, v << 1, l, mid) + get(lp, rp, (v << 1) + 1, mid, r);
  }
  void insert(int val) {
    add(val, 1);
    a[val]++;
    sz++;
  }
  void erase(int val) {
    if (a[val]) add(val, -1), a[val]--, sz--;
  }
  int find_by_order(int k, int v = 1, int l = 0, int r = MAXN) {
    if (l + 1 == r) return l;
    const int mid = (l + r) / 2;
    if (seg[v << 1] > k)
      return find_by_order(k, v << 1, l, mid);
    else
      return find_by_order(k - seg[v << 1], (v << 1) + 1, mid, r);
  }
  int order_of_key(int val) {
    int ans = get(0, val);
    return ans;
  }
  void clear() {
    for (int i = 0; i < 4 * MAXN; i++) seg[i] = 0;
    for (int i = 0; i < MAXN; i++) a[i] = 0;
    sz = 0;
  }
  int size() { return sz; }
};
long long n, a[MAXN], k, ans;
ordered_multiset om, om2;
void compress() {
  map<int, int> mp;
  vector<int> v;
  for (int i = 1; i <= n; i++) v.push_back(a[i]);
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  for (int i = 0; i < v.size(); i++) mp[v[i]] = i + 1;
  for (int i = 1; i <= n; i++) a[i] = mp[a[i]];
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  compress();
  long long inv = 0, invpre = 0, invsuf = 0, r = n + 1;
  om2.insert(a[1]);
  while (inv + invsuf <= k && r > 2) {
    r--;
    if (a[r] < a[1]) inv++;
    invsuf += om.order_of_key(a[r]);
    om.insert(a[r]);
  }
  if (invsuf + inv > k)
    om.erase(a[r]), r++, inv -= (a[r - 1] < a[1]),
        invsuf -= om.order_of_key(a[r - 1]);
  ans += n - r + 1;
  for (int i = 2; i <= n && r != n + 1; i++) {
    invpre += om2.size() - om2.order_of_key(a[i] + 1);
    inv += om.order_of_key(a[i]);
    om2.insert(a[i]);
    if (invpre > k) break;
    while ((r == i || inv + invpre + invsuf > k) && r != n + 1) {
      om.erase(a[r]);
      invsuf -= om.order_of_key(a[r]);
      inv -= om2.size() - om2.order_of_key(a[r] + 1);
      r++;
    }
    ans += n - r + 1;
  }
  cout << ans << endl;
  return 0;
}
