#include <bits/stdc++.h>
using namespace std;
const int N = 123456;
int n;
int a[N];
int fn[N];
int fn2[N];
vector<int> values;
int compress(int x) {
  return (int)(lower_bound(values.begin(), values.end(), x) - values.begin()) +
         2;
}
void modify(int p, int v) {
  for (; p < N; p = (p | (p - 1)) + 1) {
    fn[p] += v;
  }
}
int findsum(int p) {
  int s = 0;
  for (; p; p &= (p - 1)) {
    s += fn[p];
  }
  return s;
}
void modify2(int p, int v) {
  for (; p < N; p = (p | (p - 1)) + 1) {
    fn2[p] += v;
  }
}
int findsum2(int p) {
  int s = 0;
  for (; p; p &= (p - 1)) {
    s += fn2[p];
  }
  return s;
}
int main() {
  scanf("%d", &n);
  long long k;
  scanf("%lld", &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    values.push_back(a[i]);
  }
  memset(fn, 0, sizeof(fn));
  sort(values.begin(), values.end());
  values.resize(unique(values.begin(), values.end()) - values.begin());
  long long tot_inv = 0;
  for (int i = 1; i <= n; i++) {
    tot_inv += i - 1 - findsum(compress(a[i]));
    modify(compress(a[i]), +1);
  }
  memset(fn, 0, sizeof(fn));
  long long low_inv = 0;
  long long high_inv = 0;
  long long separated = 0;
  long long ans = 0;
  int high = n + 1;
  for (int i = 1; i <= n; i++) {
    low_inv += i - 1 - findsum(compress(a[i]));
    modify(compress(a[i]), +1);
  }
  for (int low = n; low >= 1; low--) {
    while (low_inv + high_inv + separated <= k && high > low) {
      high_inv += findsum2(compress(a[high - 1]) - 1);
      modify2(compress(a[high - 1]), +1);
      separated += low - findsum(compress(a[high - 1]));
      high--;
    }
    low_inv -= low - findsum(compress(a[low]));
    modify(compress(a[low]), -1);
    separated -= findsum2(compress(a[low]) - 1);
    ans += max(0, n - (high + 1) + 1);
  }
  printf("%lld\n", ans);
  return 0;
}
