#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    T t = bigmod(p, e / 2, M);
    return (t * t) % M;
  }
  return (bigmod(p, e - 1, M) * p) % M;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T multimod(T a, T b, T m) {
  T ans = 0ll;
  a %= m, b %= m;
  while (b) {
    if (b & 1ll) ans = m - ans > a ? (ans + a) : (ans + a - m);
    b >>= 1ll;
    a = (m - a) > a ? a + a : a + a - m;
  }
  return (T)ans;
}
void sc(int &a) { scanf("%d", &a); }
void sc(long long &a) { scanf("%lld", &a); }
void sc(double &a) { scanf("%lf", &a); }
void sc(int &a, int &b) { scanf("%d %d", &a, &b); }
void sc(long long &a, long long &b) { scanf("%lld %lld", &a, &b); }
void sc(int &a, int &b, int &c) { scanf("%d %d %d", &a, &b, &c); }
void sc(int &a, int &b, long long &c) { scanf("%d %d %lld", &a, &b, &c); }
void sc(long long &a, long long &b, long long &c) {
  scanf("%lld %lld %lld", &a, &b, &c);
}
void sc(string &str) { cin >> str; }
void sc(char *(str)) { scanf(" %s", str); }
void sc(char &c) { scanf(" %c", &c); }
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
int arr[(400000 + 7)];
int tmp[(400000 + 7)];
map<int, int> pos;
int seg[4 * (400000 + 7)];
void insert(int ind, int st, int ed, int pos, int val) {
  if (st == ed) {
    seg[ind] += val;
    return;
  }
  int mid = (st + ed) / 2;
  if (pos <= mid)
    insert(ind * 2, st, mid, pos, val);
  else
    insert(ind * 2 + 1, mid + 1, ed, pos, val);
  seg[ind] = max(seg[ind * 2], seg[ind * 2 + 1]);
  return;
}
int main() {
  int i, j, k;
  int n, m;
  string str;
  sc(n, k);
  for (i = 1; i <= n; i++) {
    sc(arr[i]);
    tmp[i - 1] = arr[i];
  }
  sort(tmp, tmp + n);
  int ind = 1;
  pos[tmp[0]] = 1;
  for (i = 1; i < n; i++) {
    if (tmp[i] == tmp[i - 1]) continue;
    pos[tmp[i]] = (++ind);
  }
  j = 0;
  long long res = 0ll;
  for (i = 1; i <= n; i++) {
    int cn = arr[i];
    while (j <= n && seg[1] < k) {
      j++;
      j = max(j, i);
      insert(1, 1, ind, pos[arr[j]], 1);
      if (seg[1] >= k) break;
    }
    res += n - j + 1;
    insert(1, 1, ind, pos[arr[i]], -1);
  }
  cout << res << endl;
  return 0;
}
