#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
struct SegmentTree {
  static const int treeRoot = 1;
  struct Segment {
    int l, r, m;
  };
  Segment segs[2000000];
  int __leftChild(int x) { return x << 1; }
  int __rightChild(int x) { return x << 1 ^ 1; }
  void __buildTree(int n, int l, int r) {
    segs[n].l = l;
    segs[n].r = r;
    segs[n].m = 0;
    if (l != r - 1) {
      int lc = __leftChild(n), rc = __rightChild(n);
      int m = (l + r) / 2;
      __buildTree(lc, l, m);
      __buildTree(rc, m, r);
    }
    return;
  }
  void __updateTree(int n, int p, int v) {
    if (segs[n].l == segs[n].r - 1) {
      segs[n].m += v;
    } else {
      int lc = __leftChild(n), rc = __rightChild(n);
      int m = (segs[n].l + segs[n].r) / 2;
      if (p < m) {
        __updateTree(lc, p, v);
      } else {
        __updateTree(rc, p, v);
      }
      segs[n].m = max(segs[lc].m, segs[rc].m);
    }
    return;
  }
  int __queryTree(int n, int l, int r) {
    if (segs[n].l == l && segs[n].r == r) {
      return segs[n].m;
    } else {
      int res = -inf, m = (segs[n].l + segs[n].r) / 2;
      if (l < m) {
        res = max(res, __queryTree(__leftChild(n), l, min(r, m)));
      }
      if (m < r) {
        res = max(res, __queryTree(__rightChild(n), max(m, l), r));
      }
      return res;
    }
  }
  void init(int n) { return n ? __buildTree(treeRoot, 0, n) : void(); }
  void update(int p, int v) { return __updateTree(treeRoot, p, v); }
  int query(int l, int r) { return __queryTree(treeRoot, l, r); }
};
SegmentTree rmq;
int ary[1000000];
int k, n;
void reassignValues() {
  vector<pair<int, int> > v;
  int ct = 0;
  for (int i = 0; i != n; ++i) {
    v.push_back(make_pair(ary[i], i));
  }
  sort(v.begin(), v.end());
  ary[v[0].second] = ct = 0;
  for (int i = 1; i != n; ++i) {
    ary[v[i].second] = ct += v[i].first > v[i - 1].first;
  }
}
int main() {
  cin.sync_with_stdio(false);
  while (cin >> n >> k) {
    long long res = 0;
    int l, r = l = 0;
    rmq.init(n);
    for (int i = 0; i != n; ++i) {
      cin >> ary[i];
    }
    reassignValues();
    for (int i = 0; i != n; ++i) {
      rmq.update(ary[i], 1);
      while (l < n && rmq.query(0, n) >= k) {
        rmq.update(ary[l++], -1);
      }
      res += l;
    }
    cout << res << endl;
  }
}
