#include <bits/stdc++.h>
using namespace std;
typedef priority_queue<long long, vector<long long>, greater<long long>>
    min_heap;
long long const ms = 1e6;
long long arr[ms + 1], inv[ms + 1];
long long n;
long long lso(long long i) { return (i & -i); }
void update(long long *bit, long long p, long long v) {
  if (p == 0) return;
  for (long long i = p; i <= n; i += lso(i)) bit[i] += v;
}
long long until(long long *bit, long long p) {
  long long ret = bit[p];
  for (long long i = p - lso(p); i > 0; i -= lso(i)) ret += bit[i];
  return ret;
}
long long range(long long *bit, long long i, long long j) {
  return until(bit, j) - until(bit, i - 1);
}
long long l[ms + 1], r[ms + 1];
void add(long long *bit, long long l, long long r, long long p,
         long long &sum) {
  sum += range(bit, l, r);
  update(bit, p, 1);
}
void rem(long long *bit, long long l, long long r, long long p,
         long long &sum) {
  sum -= range(bit, l, r);
  update(bit, p, -1);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  long long k;
  cin >> n >> k;
  vector<long long> in(n + 1);
  in[0] = -1;
  for (long long i = 1; i <= n; i++) cin >> in[i], arr[i] = in[i];
  sort(in.begin(), in.end());
  for (long long i = 1; i <= n; i++)
    arr[i] = lower_bound(in.begin(), in.end(), arr[i]) - in.begin();
  memset(l, 0, sizeof l);
  memset(r, 0, sizeof r);
  long long sum = 0, ans = 0;
  long long pl = n - 1, pr = n - 1;
  add(r, 1, arr[n] - 1, arr[n], sum);
  for (long long i = 1; i <= n - 1; i++) {
    sum += until(r, arr[i] - 1);
    add(l, arr[i] + 1, n, arr[i], sum);
  }
  while (pl > 0) {
    if (pl <= pr && sum <= k) {
      ans += pl;
      sum += range(l, arr[pr] + 1, n);
      add(r, 1, arr[pr] - 1, arr[pr], sum);
      pr--;
    } else {
      sum -= until(r, arr[pl] - 1);
      rem(l, arr[pl] + 1, n, arr[pl], sum);
      pl--;
    }
  }
  cout << ans << '\n';
  return 0;
}
