#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1000;
const int maxlog = 18;
long long fen[maxn][5], a[maxn], b[maxn];
void add(int x, long long val, int id) {
  for (x++; x < maxn; x += x & -x) {
    fen[x][id] += val;
  }
}
long long sum(int x, int id) {
  long long res = 0;
  for (x++; x > 0; x -= x & -x) {
    res += fen[x][id];
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  copy(a, a + n, b);
  sort(b, b + n);
  for (int i = 0; i < n; ++i) {
    a[i] = lower_bound(b, b + n, a[i]) - b;
  }
  long long inver = 0;
  for (int i = n - 1; i >= 0; --i) {
    inver += sum(a[i] - 1, 0);
    add(a[i], 1, 0);
  }
  long long res = 0, left = 0, right = 0;
  while (left < n) {
    inver = inver + sum(a[left] - 1, 0) + sum(n + 1, 2) - sum(a[left], 2);
    add(a[left], 1, 2);
    while ((right == left) || (inver > k && right != n)) {
      inver = inver - sum(a[right] - 1, 0) - sum(n + 1, 2) + sum(a[right], 2);
      add(a[right], -1, 0);
      ++right;
    }
    res += n - right;
    ++left;
  }
  cout << res << endl;
  return 0;
}
