#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 21;
int st, n, m, a[maxn], suf[maxn], prf[maxn], Q[maxn];
long long k, cnt, ans;
void add(int x, int val, int* fen) {
  for (x++; x <= m; x += (x & -x)) fen[x] += val;
}
int getf(int x, int* fen) {
  int ret = 0;
  for (; x; x -= (x & -x)) ret += fen[x];
  return ret;
}
int get(int l, int r, int* fen) { return getf(r, fen) - getf(l, fen); }
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i], Q[m++] = a[i];
  sort(Q, Q + m);
  m = unique(Q, Q + m) - Q;
  for (int i = n - 1; i > 0; i--) {
    int ind = lower_bound(Q, Q + m, a[i]) - Q;
    cnt += get(0, ind, suf);
    add(ind, 1, suf);
  }
  st = 1;
  for (int i = 0; i < n; i++) {
    int ind = lower_bound(Q, Q + m, a[i]) - Q;
    cnt += get(ind + 1, m, prf);
    add(ind, 1, prf);
    cnt += get(0, ind, suf);
    while ((cnt > k || st <= i) && st < n) {
      ind = lower_bound(Q, Q + m, a[st]) - Q;
      add(ind, -1, suf);
      cnt -= get(0, ind, suf);
      cnt -= get(ind + 1, m, prf);
      st++;
    }
    ans += n - st;
  }
  cout << ans << "\n";
}
