#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
const int N = 1e5 + 7;
int a[N], L[4 * N], R[4 * N], inv[N];
vector<int> v;
void add(int* seg, int x, int sgn, int tag = 1, int s = 0, int e = N) {
  seg[tag] += sgn;
  if (e - s <= 1) return;
  int mid = (s + e) / 2;
  if (x < mid)
    return add(seg, x, sgn, tag * 2, s, mid);
  else
    return add(seg, x, sgn, tag * 2 + 1, mid, e);
}
inline int get(int* seg, int l, int r, int tag = 1, int s = 0, int e = N) {
  if (l >= e || r <= s) return 0;
  if (l <= s && r >= e) return seg[tag];
  int mid = (s + e) / 2;
  return get(seg, l, r, tag * 2, s, mid) + get(seg, l, r, tag * 2 + 1, mid, e);
}
int32_t main() {
  int n = in();
  long long k;
  cin >> k;
  for (int i = 0; i < n; i++) {
    a[i] = in();
    v.push_back(a[i]);
  }
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  for (int i = 0; i < n; i++)
    a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
  long long ans = 0;
  int s = 0, e = n - 1;
  while (s < n) {
    int x = get(L, a[s] + 1, N);
    if (x + ans <= k)
      ans += x, add(L, a[s], 1), inv[s] = x, s++;
    else
      break;
  }
  long long an = 0;
  if (s == n) return cout << (n * 1ll * (n - 1)) / 2 << endl, 0;
  while (e) {
    ans += get(L, a[e] + 1, N) + get(R, 0, a[e]);
    add(R, a[e], 1);
    e--;
    while (s && ans > k) {
      s--;
      ans -= (inv[s] + get(R, 0, a[s]));
      add(L, a[s], -1);
    }
    if (!s) break;
    an += s;
  }
  cout << an << endl;
}
