#include <bits/stdc++.h>
using namespace std;
vector<int> v[500000];
int tmp[500000];
int arr[500000];
int brr[500000];
int pos[500000];
int main() {
  map<int, int> my;
  int n, k, i, a, cnt;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; i++) {
    scanf("%d", &tmp[i]);
  }
  cnt = 1;
  for (i = 1; i <= n; i++) {
    if (my[tmp[i]] == 0) {
      my[tmp[i]] = cnt;
      arr[i] = cnt;
      cnt++;
    } else {
      arr[i] = my[tmp[i]];
    }
  }
  for (i = 1; i <= n; i++) {
    v[arr[i]].push_back(i);
  }
  long long int ans;
  int len;
  ans = 0;
  k--;
  for (i = 0; i <= n; i++) {
    brr[arr[i]] = v[arr[i]].size() - 1;
  }
  set<int> st;
  for (i = 1; i <= n; i++) {
    a = lower_bound(v[arr[i]].begin(), v[arr[i]].end(), i) - v[arr[i]].begin();
    if (a + k <= brr[arr[i]]) {
      st.insert(v[arr[i]][a + k]);
      pos[i] = v[arr[i]][a + k];
    }
  }
  long long int res = 0;
  set<int>::iterator it;
  for (i = 1; i <= n; i++) {
    if (st.size() > 0) {
      it = st.begin();
      a = *it;
      res += n - a + 1;
    }
    st.erase(pos[i]);
  }
  cout << res << endl;
}
