#include <bits/stdc++.h>
using namespace std;
long long n, k;
void show(set<pair<long long, long long>> &s) {
  for (auto x : s) printf("(%lld %lld), ", x.first, x.second);
  printf("\n");
}
int main() {
  scanf("%lld%lld", &n, &k);
  vector<long long> v(n);
  for (auto &x : v) scanf("%lld", &x);
  set<pair<long long, long long>> st;
  map<long long, long long> m;
  long long ans = 0;
  for (long long i = 0, j = 0; i < n; i++) {
    while (j < n && (st.empty() || (*--st.end()).first < k)) {
      long long x = v[j];
      if (m.find(x) == m.end()) {
        m[x] = 1;
      } else {
        auto it = st.find({m[x], x});
        if (it != st.end()) st.erase(it);
        m[x]++;
      }
      st.emplace(m[x], x);
      j++;
    }
    if (!st.empty() && (*--st.end()).first >= k) ans += n - j + 1;
    long long x = v[i];
    auto it = st.find({m[x], x});
    st.erase(it);
    m[x]--;
    if (m[x]) st.emplace(m[x], x);
  }
  printf("%lld\n", ans);
}
