#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 10;
long long a[MAXN];
long long fl[MAXN], fr[MAXN];
void updl(long long p, long long val) {
  ++p;
  p = MAXN - p;
  for (; p < MAXN; p += p & -p) fl[p] += val;
}
void updr(long long p, long long val) {
  ++p;
  for (; p < MAXN; p += p & -p) fr[p] += val;
}
long long find(long long p) {
  long long res = 0;
  long long now = p;
  for (; now; now -= now & -now) res += fr[now];
  now = MAXN - p - 2;
  for (; now; now -= now & -now) res += fl[now];
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> vctr;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    vctr.push_back(a[i]);
  }
  sort(vctr.begin(), vctr.end());
  vctr.resize(unique(vctr.begin(), vctr.end()) - vctr.begin());
  for (long long i = 0; i < n; ++i)
    a[i] = lower_bound(vctr.begin(), vctr.end(), a[i]) - vctr.begin();
  long long ans = 0;
  long long l = 0, now = 0;
  updl(a[0], 1);
  for (long long i = n - 1; i; --i) {
    now += find(a[i]);
    updr(a[i], 1);
  }
  for (long long r = 1; r < n; ++r) {
    while (l < r - 1 && now <= k) {
      now += find(a[++l]);
      updl(a[l], 1);
    }
    ans += l + (now <= k);
    updr(a[r], -1);
    now -= find(a[r]);
  }
  cout << ans;
  return 0;
}
