#include <bits/stdc++.h>
using namespace std;
int a[222222], b[222222], B[222222] = {0}, B2[222222] = {0};
map<int, int> M;
void add(int *B, int x, int v) {
  while (x <= 222222) B[x] += v, x += x & -x;
}
int ret(int *B, int x) {
  int r = 0;
  while (x) r += B[x], x -= x & -x;
  return r;
}
int main() {
  int n;
  long long k;
  scanf("%d", &n);
  cin >> k;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]), b[i] = a[i];
  sort(a, a + n);
  int p = unique(a, a + n) - a;
  for (int i = 0; i < p; i++) M[a[i]] = i + 1;
  for (int i = 0; i < n; i++) a[i] = M[b[i]];
  int l = n - 2;
  long long cur = 0, ans = 0;
  for (int i = 0; i < n - 1; i++) {
    b[i] = ret(B, 222222) - ret(B, a[i]);
    cur += b[i];
    add(B, a[i], 1);
  }
  for (int r = n - 1; r >= 0; r--) {
    add(B2, a[r], 1);
    cur += ret(B, 222222) - ret(B, a[r]);
    cur += ret(B2, a[r] - 1);
    while (l >= r || (l >= 0 && cur > k)) {
      cur -= (ret(B, 222222) - ret(B, a[l]));
      cur -= ret(B2, a[l] - 1);
      add(B, a[l], -1);
      l--;
    }
    ans += l + 1;
  }
  cout << ans;
  printf("\n");
  return 0;
}
