#include <bits/stdc++.h>
using namespace std;
const long long logN = 20;
const long long N = 100005;
const long long M = 1000000007;
const long long M2 = 998244353;
const long long INF = 1e12;
long long pow1(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % M;
    }
    a = (a * a) % M;
    b >>= 1;
  }
  return res % M;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T = 1;
  while (T--) {
    long long n, k;
    cin >> n >> k;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long i = 0, j = 0;
    set<pair<long long, long long>> st;
    map<long long, long long> mp;
    mp[a[0]]++;
    st.insert(make_pair(mp[a[0]], a[0]));
    long long ans = 0;
    while (i < n && j < n) {
      if (j < i) {
        j = i;
        mp[a[i]] = 1;
        st.insert(make_pair(mp[a[i]], a[i]));
      }
      auto tmp = *st.rbegin();
      if (tmp.first >= k) {
        ans += (n - j);
        pair<long long, long long> p1 = make_pair(mp[a[i]], a[i]);
        st.erase(p1);
        mp[a[i]]--;
        if (mp[a[i]] != 0) st.insert(make_pair(mp[a[i]], a[i]));
        i++;
      } else {
        j++;
        if (j == n)
          break;
        else {
          pair<long long, long long> p1 = make_pair(mp[a[j]], a[j]);
          st.erase(p1);
          mp[a[j]]++;
          st.insert(make_pair(mp[a[j]], a[j]));
        }
      }
    }
    cout << ans << "\n";
  }
}
