#include <bits/stdc++.h>
using namespace std;
int myabs(int x) { return x < 0 ? -x : x; }
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
int toInt(char xx) { return xx - '0'; }
char toChar(int xx) { return xx + '0'; }
bool isNum(char xx) { return ('0' <= xx && xx <= '9'); }
bool isCharacter(char xx) {
  return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
bool isUpper(char xx) { return ('A' <= xx && xx <= 'Z'); }
bool isLower(char xx) { return ('a' <= xx && xx <= 'z'); }
bool isPalin(string x) {
  int len = x.length();
  for (int i = 0; i <= len / 2; ++i) {
    if (x[i] != x[len - 1 - i]) return false;
  }
  return true;
}
void swapInt(int &x, int &y) {
  x = x ^ y;
  y = x ^ y;
  x = x ^ y;
}
string tolowerStr(string x) {
  string ret = "";
  for (int i = 0; i < (int)x.size(); ++i) {
    ret.push_back(tolower(x[i]));
  }
  return ret;
}
string toupperStr(string x) {
  string ret = "";
  for (int i = 0; i < (int)x.size(); ++i) {
    ret.push_back(toupper(x[i]));
  }
  return ret;
}
template <class T>
bool isInArray(T x, vector<T> vt) {
  for (int i = 0; i < (int)vt.size(); ++i) {
    if (vt[i] == x) {
      return true;
    }
  }
  return false;
}
string trim(string x) {
  int l = 0, r = x.size() - 1;
  char arr[] = {'\f', '\v', '\t', '\r', '\n', ' '};
  vector<char> delimiter(arr, arr + sizeof(arr) / sizeof(char));
  while (isInArray(x[l], delimiter)) {
    l++;
  }
  while (isInArray(x[r], delimiter)) {
    r--;
  }
  return x.substr(l, r - l + 1);
}
vector<string> getToken(string x, vector<char> tokens) {
  int icounter = 0, lastIndex = x.length() - 1;
  vector<string> ret;
  for (;;) {
    string tmp = "";
    while (icounter <= lastIndex && isInArray(x[icounter], tokens)) icounter++;
    while (icounter <= lastIndex && !isInArray(x[icounter], tokens)) {
      tmp.push_back(x[icounter]);
      icounter++;
    }
    if (tmp.length() > 0) ret.push_back(tmp);
    if (icounter > lastIndex) break;
  }
  return ret;
}
inline void clear_buffer() {
  string tmp;
  getline(cin, tmp);
}
int nextIndexInCircle(int n, int currentPosition, int firstPointIndex) {
  if (firstPointIndex == 0) {
    return (currentPosition + 1) % n;
  } else {
    if (currentPosition == n - 1) {
      return n;
    } else {
      return (currentPosition + 1) % n;
    }
  }
}
const int bfsz = 1 << 16;
char bf[bfsz + 5];
int rsz = 0;
int ptr = 0;
char gc() {
  if (rsz <= 0) {
    ptr = 0;
    rsz = fread(bf, 1, bfsz, stdin);
    if (rsz <= 0) return EOF;
  }
  --rsz;
  return bf[ptr++];
}
void ga(char &c) {
  c = EOF;
  while (!isalpha(c)) c = gc();
}
int gs(char s[]) {
  int l = 0;
  char c = gc();
  while (isspace(c)) c = gc();
  while (c != EOF && !isspace(c)) {
    s[l++] = c;
    c = gc();
  }
  s[l] = '\0';
  return l;
}
template <class T>
bool gi(T &v) {
  v = 0;
  char c = gc();
  while (c != EOF && c != '-' && !isdigit(c)) c = gc();
  if (c == EOF) return false;
  bool neg = c == '-';
  if (neg) c = gc();
  while (isdigit(c)) {
    v = v * 10 + c - '0';
    c = gc();
  }
  if (neg) v = -v;
  return true;
}
template <class T>
inline void checkmin(T &a, T b) {
  if (b < a) a = b;
}
void ft_create(vector<int> &t, int n) { t.assign(n + 1, 0); }
int ft_get(vector<int> &t, int idx) {
  int ret = 0;
  while (idx > 0) {
    ret += t[idx];
    idx -= (idx & (-idx));
  }
  return ret;
}
void ft_update(vector<int> &t, int idx) {
  int incrementValue = 1;
  while (idx < 100001) {
    t[idx] += incrementValue;
    idx += (idx & (-idx));
  }
}
const int maxn = 1e6 + 10;
int n, k;
int a[maxn];
void read() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
}
void init() {}
void solve() {
  int l = 1, r = 1;
  map<int, int> cnt;
  long long ret = 0;
  while (l <= n) {
    while (r <= n && cnt[a[r]] < k) {
      cnt[a[r]]++;
      if (cnt[a[r]] == k) break;
      r++;
    }
    if (cnt[a[r]] == k) {
      ret += (long long)(n - r + 1);
    }
    if (r > n) {
      break;
    }
    cnt[a[r]]--;
    cnt[a[l]]--;
    l++;
  }
  cout << ret;
}
int main() {
  int ntest = 1;
  for (int itest = 1; itest <= ntest; ++itest) {
    read();
    init();
    solve();
  }
  return 0;
}
