#include <bits/stdc++.h>
using namespace std;
int a[400001];
map<int, int> br;
multiset<int> m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  bool moguce = false;
  int n, k, i, j;
  long long rez = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) cin >> a[i];
  i = 0;
  j = 0;
  br[a[i]]++;
  if (k == 1)
    cout << (long long)n * (n + 1) / 2;
  else {
    while (i < n && j < n) {
      while (m.empty() == true) {
        j++;
        if (j >= n) break;
        br[a[j]]++;
        if (br[a[j]] >= k) m.insert(a[j]);
      }
      if (j >= n) break;
      rez = rez + (long long)n - j;
      i++;
      br[a[i - 1]]--;
      if (br[a[i - 1]] < k) m.erase(a[i - 1]);
    }
    cout << rez;
  }
  return 0;
}
