#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 1e5 + 5;
const int base = 350;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
long long n, m, t, k, T, ans, tong, d[N], a[N], b[N], h[N], c[N], st[N][2],
    lazy[N];
vector<long long> adj[N];
vector<long long> kq;
long long pw(long long k, long long n) {
  long long total = 1;
  for (; n; n >>= 1) {
    if (n & 1) total = total * k % mod;
    k = k * k % mod;
  }
  return total;
}
void add(long long x, long long y, long long id) {
  for (; x <= n; x += x & -x) st[x][id] += y;
}
long long sget(long long x, long long id) {
  long long total = 0;
  for (; x; x -= x & -x) total += st[x][id];
  return total;
}
long long sum(long long l, long long r, long long id) {
  if (r < l) return 0;
  return sget(r, id) - sget(l - 1, id);
}
void sol() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    kq.push_back(a[i]);
  }
  sort(kq.begin(), kq.end());
  kq.erase(unique(kq.begin(), kq.end()), kq.end());
  for (int i = 1; i <= n; i++)
    a[i] = lower_bound(kq.begin(), kq.end(), a[i]) - kq.begin() + 1;
  int j = n + 1;
  add(a[1], 1, 0);
  while (tong <= k && j > 1) {
    --j;
    tong += sum(a[j] + 1, n, 0);
    tong += sum(1, a[j] - 1, 1);
    add(a[j], 1, 1);
  }
  ans += n - j;
  for (int i = 2; i <= n; i++) {
    tong += sum(a[i] + 1, n, 0);
    tong += sum(1, a[i] - 1, 1);
    add(a[i], 1, 0);
    while ((j <= i || tong > k) && j <= n) {
      tong -= sum(a[j] + 1, n, 0);
      tong -= sum(1, a[j] - 1, 1);
      add(a[j], -1, 1);
      ++j;
    }
    ans += n - j + 1;
  }
  cout << ans;
}
int main() {
  if (fopen("cowpatibility"
            ".in",
            "r")) {
    freopen(
        "cowpatibility"
        ".in",
        "r", stdin);
    freopen(
        "cowpatibility"
        ".out",
        "w", stdout);
  }
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int ntest = 1;
  while (ntest-- > 0) sol();
}
