#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 100 * 1000 + 13;
long long a[MAXN], BIT[2][MAXN];
unordered_map<long long, long long> compress;
vector<long long> A;
long long bitC(long long x) {
  x--;
  long long ret = 0;
  for (; x > 0; x -= x & (-x)) ret += BIT[1][x];
  return ret;
}
long long bitD(long long x) {
  long long ret = 0;
  for (long long y = MAXN - 1; y > 0; y -= y & (-y)) ret += BIT[0][y];
  for (; x > 0; x -= x & (-x)) ret -= BIT[0][x];
  return ret;
}
void bitUpdM(long long i, long long x) {
  for (; x < MAXN; x += x & (-x)) BIT[i][x]--;
  return;
}
void bitUpdP(long long i, long long x) {
  for (; x < MAXN; x += x & (-x)) BIT[i][x]++;
  return;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> a[i], A.push_back(a[i]);
  sort(A.begin(), A.end());
  A.resize(unique(A.begin(), A.end()) - A.begin());
  for (long long i = 0; i < A.size(); i++) compress[A[i]] = i + 1;
  for (long long i = 0; i < n; i++) a[i] = compress[a[i]];
  long long r = n - 1, l = n - 2, inv = 0;
  for (long long i = 0; i < n; i++) {
    inv += bitD(a[i]);
    bitUpdP(0, a[i]);
  }
  bitUpdM(0, a[n - 1]), bitUpdP(1, a[n - 1]);
  long long ans = 0;
  while (r) {
    if (l == r) {
      inv -= bitC(a[l]) + bitD(a[l]);
      bitUpdM(0, a[l]);
      l--;
    }
    while (l > -1 and inv > k) {
      inv -= bitC(a[l]) + bitD(a[l]);
      bitUpdM(0, a[l]);
      l--;
    }
    r--;
    ans += 1 + l;
    inv += bitC(a[r]) + bitD(a[r]);
    bitUpdP(1, a[r]);
  }
  cout << ans << endl;
  return 0;
}
