#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
long long n, k, inv, pt, t, ans, seg[5][4 * N], a[N], sorted[N];
void change(int state, int p, int val, int b = 0, int e = n, int ind = 1) {
  if (e - b == 1) {
    seg[state][ind] += val;
    return;
  }
  int mid = (b + e) / 2;
  if (p < mid)
    change(state, p, val, b, mid, ind * 2);
  else
    change(state, p, val, mid, e, ind * 2 + 1);
  seg[state][ind] = seg[state][ind * 2] + seg[state][ind * 2 + 1];
  return;
}
long long sum(int state, int l, int r, int b = 0, int e = n, int ind = 1) {
  if (l <= b && e <= r) return seg[state][ind];
  int mid = (b + e) / 2;
  long long ret = 0;
  if (l < mid) ret += sum(state, l, r, b, mid, ind * 2);
  if (r > mid) ret += sum(state, l, r, mid, e, ind * 2 + 1);
  return ret;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sorted[i] = a[i];
  }
  sort(sorted, sorted + n);
  pt = n - 2;
  for (int i = 0; i < n - 1; i++) {
    int t = lower_bound(sorted, sorted + n, a[i]) - sorted;
    if (t < n - 1) inv += sum(0, t + 1, n);
    change(0, t, 1);
  }
  for (int i = n - 1; i > 0; i--) {
    while (pt >= i) {
      t = lower_bound(sorted, sorted + n, a[pt]) - sorted;
      change(0, t, -1);
      inv -= sum(1, 0, t + 1);
      if (t + 1 < n) inv -= sum(0, t + 1, n);
      pt--;
    }
    t = lower_bound(sorted, sorted + n, a[i]) - sorted;
    change(1, t, 1);
    inv += sum(0, 0, n) - sum(0, 0, t + 1);
    inv += sum(1, 0, t);
    while (pt && inv > k) {
      t = lower_bound(sorted, sorted + n, a[pt]) - sorted;
      change(0, t, -1);
      inv -= sum(1, 0, t);
      if (t + 1 < n) inv -= sum(0, t + 1, n);
      pt--;
    }
    if (inv > k) break;
    ans += pt + 1;
  }
  cout << ans << endl;
}
