#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long n, m, a, b, c, k, temp, x, y;
const int MAXN = 100000 + 11;
inline long long max(long long a, long long b) { return ((a > b) ? a : b); }
inline long long min(long long a, long long b) { return ((a > b) ? b : a); }
inline long long gcd(long long a, long long b) {
  if (b == 0) return a;
  a %= b;
  return gcd(b, a);
}
inline vector<long long> read(int n) {
  vector<long long> v(n);
  for (int i = 0; i < v.size(); i++) cin >> v[i];
  return v;
}
vector<int> tree[200000];
void bfst() {
  for (int i = n - 1; i > 0; --i)
    merge(tree[i << 1].begin(), tree[i << 1].end(), tree[i << 1 | 1].begin(),
          tree[i << 1 | 1].end(), back_inserter(tree[i]));
}
long long qfstgreater(int l, int r, int val) {
  long long res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1)
      res += tree[l].end() - upper_bound(tree[l].begin(), tree[l].end(), val),
          l++;
    if (r & 1)
      res += tree[r - 1].end() -
             upper_bound(tree[r - 1].begin(), tree[r - 1].end(), val),
          r--;
  }
  return res;
}
long long qfstlesser(int l, int r, int val) {
  long long res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1)
      res += lower_bound(tree[l].begin(), tree[l].end(), val) - tree[l].begin(),
          l++;
    if (r & 1)
      res += lower_bound(tree[r - 1].begin(), tree[r - 1].end(), val) -
             tree[r - 1].begin(),
          r--;
  }
  return res;
}
void solveforthiscase(const int& test) {
  cin >> n >> k;
  vector<long long> v = read(n);
  for (int i = 0; i < n; i++) tree[i + n].push_back(v[i]);
  bfst();
  long long inv = 0, ans = 0, r = n - 1;
  for (; r > 0; r--) {
    long long ti = 0;
    if (v[r] < v[0]) ti++;
    ti += qfstlesser(r + 1, n, v[r]);
    if (inv + ti > k) break;
    inv += ti;
  }
  r++;
  if (r == 1) {
    cout << (n * (n - 1)) / 2;
    return;
  }
  ans += (n - r);
  for (int l = 1; l < n; l++) {
    inv += qfstgreater(0, l, v[l]) + qfstlesser(r, n, v[l]);
    while (r < n && inv > k) {
      inv -= qfstlesser(r + 1, n, v[r]);
      inv -= qfstgreater(0, l + 1, v[r++]);
    }
    if (r == n) break;
    ans += n - r;
  }
  cout << ans;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  clock_t start, end;
  start = clock();
  int test = 1;
  for (int i = 1; i <= test; i++) solveforthiscase(i);
  end = clock();
  long double t_t = (long double)(end - start) / (long double)(CLOCKS_PER_SEC);
  if (false) cerr << (long double)t_t * 1000 << " ms ";
}
