#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T min(T &a, T &b) {
  return a < b ? a : b;
}
template <class T>
inline T max(T &a, T &b) {
  return a > b ? a : b;
}
template <class T>
void read(T &x) {
  char ch;
  while ((ch = getchar()) && !isdigit(ch))
    ;
  x = ch - '0';
  while ((ch = getchar()) && isdigit(ch)) x = x * 10 + ch - '0';
}
struct point {
  int x, y;
  point() {}
  point(int _x, int _y) : x(_x), y(_y) {}
};
long long Pow(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 120000;
int n, a[N], h[N];
long long k;
long long ans;
struct Tree {
  int ty;
  long long t[N];
  void add(int x, long long c) {
    for (int i = x; i <= n; i += i & (-i)) t[i] += c;
  }
  long long ask(int x) {
    long long ans = 0;
    for (int i = x; i; i -= i & (-i)) ans += t[i];
    return ans;
  }
} T1, T2;
int main() {
  scanf("%d%I64d", &n, &k);
  T1.ty = 1, T2.ty = 2;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), h[i] = a[i];
  sort(h + 1, h + n + 1);
  for (int i = 1; i <= n; i++) a[i] = lower_bound(h + 1, h + n + 1, a[i]) - h;
  T1.add(a[1], 1);
  long long sum = 0;
  int il = 1;
  for (int i = n; i >= 2; i--) {
    if (sum + T1.ask(n) - T1.ask(a[i]) + T2.ask(a[i] - 1) <= k) {
      sum += T1.ask(n) - T1.ask(a[i]) + T2.ask(a[i] - 1);
      T2.add(a[i], 1);
    } else {
      il = i;
      break;
    }
  }
  il++;
  if (il <= n) ans += n - il + 1;
  for (int i = 2; i <= n - 1; i++) {
    if (il == i)
      sum -= T1.ask(n) - T1.ask(a[il]) + T2.ask(a[il] - 1), T2.add(a[il], -1),
          il++;
    T1.add(a[i], 1);
    sum += T2.ask(a[i] - 1) + T1.ask(n) - T1.ask(a[i]);
    while (il <= n && sum > k)
      sum -= T1.ask(n) - T1.ask(a[il]) + T2.ask(a[il] - 1), T2.add(a[il], -1),
          il++;
    if (il <= n) ans += n - il + 1;
  }
  printf("%I64d\n", ans);
}
