#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, data1[4 * N], data2[4 * N], a[N];
map<int, int> com;
long long int k, ans;
vector<int> all;
void add1(int node, int st, int en, int p, int val) {
  data1[node] += val;
  if (en - st < 2) return;
  int mid = (st + en) / 2;
  if (p < mid)
    add1(node * 2 + 0, st, mid, p, val);
  else
    add1(node * 2 + 1, mid, en, p, val);
}
void add2(int node, int st, int en, int p, int val) {
  data2[node] += val;
  if (en - st < 2) return;
  int mid = (st + en) / 2;
  if (p < mid)
    add2(node * 2 + 0, st, mid, p, val);
  else
    add2(node * 2 + 1, mid, en, p, val);
}
int get1(int node, int st, int en, int l, int r) {
  if (en <= l or r <= st) return 0;
  if (l <= st and en <= r) return data1[node];
  int mid = (st + en) / 2;
  return get1(node * 2 + 0, st, mid, l, r) + get1(node * 2 + 1, mid, en, l, r);
}
int get2(int node, int st, int en, int l, int r) {
  if (en <= l or r <= st) return 0;
  if (l <= st and en <= r) return data2[node];
  int mid = (st + en) / 2;
  return get2(node * 2 + 0, st, mid, l, r) + get2(node * 2 + 1, mid, en, l, r);
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> a[i], all.push_back(a[i]);
  sort(all.begin(), all.end());
  int compress = 1;
  com[all[0]] = compress;
  for (int i = 1; i < all.size(); ++i)
    if (all[i] != all[i - 1]) com[all[i]] = ++compress;
  for (int i = 0; i < n; ++i) a[i] = com[a[i]];
  int l = 0, r = n - 1;
  long long int now = (int)(a[l] > a[r]);
  long long int backup;
  if ((k == 0) and (now)) return cout << 0, 0;
  add1(1, 0, N, a[l], 1);
  add2(1, 0, N, a[r], 1);
  while (r > l + 1) {
    backup = now;
    now += get2(1, 0, N, 0, a[r - 1]);
    now += get1(1, 0, N, a[r - 1] + 1, N);
    if (now > k) {
      now = backup;
      break;
    }
    add2(1, 0, N, a[r - 1], 1);
    r--;
  }
  ans += n - r;
  for (l = 1; l < n; ++l) {
    now += get1(1, 0, N, a[l] + 1, N);
    now += get2(1, 0, N, 0, a[l]);
    add1(1, 0, N, a[l], 1);
    while (((l == r) or (now > k)) and (r < n)) {
      now -= get2(1, 0, N, 0, a[r]);
      now -= get1(1, 0, N, a[r] + 1, N);
      add2(1, 0, N, a[r], -1);
      r++;
    }
    ans += (n - r);
  }
  cout << ans;
}
