#include <bits/stdc++.h>
using namespace std;
deque<pair<int, long long> > runs;
int m, k;
long long sum = 0;
long long doit() {
  if (runs.size() <= 1) return m * sum % k;
  if (runs.front().first != runs.back().first) return m * sum;
  long long ps = runs.front().second + runs.back().second;
  long long dif = ps - ps % k;
  if (ps % k != 0) return m * sum - (m - 1) * dif;
  runs.pop_front();
  runs.pop_back();
  sum -= ps;
  long long sub = doit();
  if (sub > 0)
    return sub + ps;
  else
    return ps % k;
}
int main() {
  int n;
  scanf("%d %d %d", &n, &k, &m);
  int tmp;
  scanf("%d", &tmp);
  runs.push_back(make_pair(tmp, 1));
  for (int i = 1; i < n; i++) {
    scanf("%d", &tmp);
    if (!runs.empty() && tmp == runs.back().first)
      runs.back().second++;
    else
      runs.push_back(make_pair(tmp, 1));
    runs.back().second %= k;
    if (runs.back().second == 0) runs.pop_back();
  }
  for (deque<pair<int, long long> >::iterator it = runs.begin();
       it != runs.end(); it++)
    sum += it->second;
  printf("%lld\n", doit());
}
