10 5 1000000000
1 1 1 2 2 1 2 2 2 2
 5 3 3
1 2 2 1 1
 2 4 1
1 1
 1 1000000000 1000000000
100000
 5 3 2
1 1 2 1 1
 5 2 4
1 2 3 2 1
 1 10 10
1

10000000000
 0
 2
 0
 7
 0
 0

#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());
}
