#include <bits/stdc++.h>
using namespace std;
const int inf = 1e6;
const int Linf = 1e9;
const long long LLinf = (long long)1e18;
const int maxn = 1e5 + 5;
int n, a[maxn];
long long k, res = 0;
int sum[maxn], sum1[maxn], cnt;
map<int, int> mmap;
set<int> s;
void Enter() {
  cin >> n >> k;
  for (int i = (1); i <= (n); ++i) cin >> a[i], s.insert(a[i]);
  cnt = 0;
  for (int c : s) mmap[c] = ++cnt;
  for (int i = (1); i <= (n); ++i) a[i] = mmap[a[i]];
}
void update(int key, int x, int delta) {
  for (; x <= cnt; x += x & -x)
    if (key)
      sum[x] += delta;
    else
      sum1[x] += delta;
}
int su(int key, int x) {
  int r = 0;
  for (; x > 0; x &= x - 1)
    if (key)
      r += sum[x];
    else
      r += sum1[x];
  return r;
}
void Init() {
  int j = 1;
  int i = 1;
  long long now = 0;
  for (int i = (1); i <= (n); ++i) {
    now += i - 1 - su(0, a[i]);
    update(0, a[i], 1);
  }
  while (i <= n) {
    update(1, a[i], 1);
    now += su(0, a[i] - 1) + (su(1, cnt) - su(1, a[i]));
    while ((now > k || j <= i) && j <= n) {
      now -= su(1, cnt) - su(1, a[j]) + su(0, a[j] - 1);
      update(0, a[j], -1);
      ++j;
    }
    ++i;
    res += n - j + 1;
  }
  cout << res;
}
void Solve() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Enter();
  Init();
  Solve();
}
