#include <bits/stdc++.h>
using namespace std;
const int maxn = 100007;
vector<int> b;
int n, a[maxn], BIT1[maxn], BIT2[maxn];
long long k, ans;
void add1(int p, int v) {
  for (int i = p; i > 0; i -= i & (-i)) BIT1[i] += v;
}
void add2(int p, int v) {
  for (int i = p; i <= n; i += i & (-i)) BIT2[i] += v;
}
long long get1(int p) {
  long long res = 0;
  for (int i = p; i <= n; i += i & (-i)) res += BIT1[i];
  return res;
}
long long get2(int p) {
  long long res = 0;
  for (int i = p; i > 0; i -= i & (-i)) res += BIT2[i];
  return res;
}
int main() {
  scanf("%d%I64d", &n, &k);
  for (int i = 1, _b = n; i <= _b; i++) scanf("%d", &a[i]), b.push_back(a[i]);
  sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  for (int i = 1, _b = n; i <= _b; i++)
    a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin() + 1;
  int l, r = n;
  long long res = 0;
  for (int i = 1, _b = n; i <= _b; i++) {
    if (i == n) add2(a[i], 1);
    if (i < n) add1(a[i], 1);
    res += get1(a[i] + 1);
  }
  ans = 0;
  for (l = n - 1; l >= 1; l--) {
    while (l < r - 1 && res + get1(a[r - 1] + 1) + get2(a[r - 1] - 1) <= k) {
      r--;
      res += get1(a[r] + 1) + get2(a[r] - 1);
      add2(a[r], 1);
    }
    if (res <= k) ans += n - r + 1;
    res -= get1(a[l] + 1) + get2(a[l] - 1);
    add1(a[l], -1);
  }
  printf("%I64d\n", ans);
  return 0;
}
