#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1001;
long long n, k, res, cnt;
int a[N], seg1[N << 2], seg2[N << 2], r = 1;
set<pair<int, int>> s;
void pre() {
  int cnt = -1, lst = -1;
  for (auto k = s.begin(); k != s.end(); k++) {
    if ((*k).first == lst)
      a[(*k).second] = cnt;
    else {
      lst = (*k).first;
      a[(*k).second] = ++cnt;
    }
  }
}
void add1(int x, int k, int s = 0, int e = n, int id = 1) {
  if (x < s || e <= x) return;
  if (e - s == 1) {
    seg1[id] += k;
    return;
  }
  int mid = (e + s) >> 1;
  add1(x, k, s, mid, id * 2);
  add1(x, k, mid, e, id * 2 + 1);
  seg1[id] = seg1[id * 2] + seg1[id * 2 + 1];
}
int get1(int l, int r, int s = 0, int e = n, int id = 1) {
  if (l <= s && e <= r) return seg1[id];
  if (r <= s || e <= l) return 0;
  int mid = (e + s) >> 1;
  return get1(l, r, s, mid, id * 2) + get1(l, r, mid, e, id * 2 + 1);
}
void add2(int x, int k, int s = 0, int e = n, int id = 1) {
  if (x < s || e <= x) return;
  if (e - s == 1) {
    seg2[id] += k;
    return;
  }
  int mid = (e + s) >> 1;
  add2(x, k, s, mid, id * 2);
  add2(x, k, mid, e, id * 2 + 1);
  seg2[id] = seg2[id * 2] + seg2[id * 2 + 1];
}
int get2(int l, int r, int s = 0, int e = n, int id = 1) {
  if (l <= s && e <= r) return seg2[id];
  if (r <= s || e <= l) return 0;
  int mid = (e + s) >> 1;
  return get2(l, r, s, mid, id * 2) + get2(l, r, mid, e, id * 2 + 1);
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s.insert({a[i], i});
  }
  pre();
  for (int i = 1; i < n; i++) {
    cnt += get1(a[i] + 1, n);
    add1(a[i], 1);
  }
  for (int i = 0; i < n; i++) {
    cnt += get1(0, a[i]) + get2(a[i] + 1, n);
    add2(a[i], 1);
    if (cnt <= k && !i) {
      cout << 1LL * n * (n - 1) / 2 << "\n";
      return 0;
    }
    while (r < n && cnt > k) {
      cnt -= get1(0, a[r]) + get2(a[r] + 1, n);
      add1(a[r], -1);
      r++;
    }
    res += (n - r);
    if (r == n) break;
  }
  cout << res << "\n";
}
