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;
int nbValues, nbMerge, nbRepeat;
deque<pair<int, int>> sequence;
decltype(sequence) milieux;
deque<pair<int, int>> get_sub_sequence(const deque<pair<int, int>>& values,
                                       int nbElems) {
  decltype(sequence) seq;
  for (auto value_count : values) {
    if (value_count.second >= nbElems) {
      seq.push_back({value_count.first, nbElems});
      break;
    } else {
      nbElems -= value_count.second;
      seq.push_back(value_count);
    }
  }
  return seq;
}
int main() {
  scanf("%d%d%d", &nbValues, &nbMerge, &nbRepeat);
  for (int iValue = 0; iValue < nbValues; iValue++) {
    int value;
    scanf("%d", &value);
    if (!sequence.empty() && sequence.back().first == value) {
      sequence.back().second++;
      if (sequence.back().second == nbMerge) {
        sequence.pop_back();
      }
    } else {
      sequence.push_back({value, 1});
    }
  }
  milieux = sequence;
  int nbDeleteDeb = 0;
  int nbDeleteFin = 0;
  while (milieux.size() >= 2 && milieux[0].first == milieux.back().first &&
         milieux[0].second + milieux.back().second >= nbMerge) {
    nbDeleteDeb += min(nbMerge, milieux[0].second);
    milieux[0].second -= nbMerge;
    if (milieux[0].second <= 0) {
      milieux.back().second += milieux[0].second;
      nbDeleteFin -= milieux[0].second;
      milieux.pop_front();
    }
    if (milieux.back().second == 0) {
      milieux.pop_back();
    }
  }
  int nbDelete = nbDeleteDeb + nbDeleteFin;
  long long milieux_size = 0;
  for (auto value_count : milieux) {
    milieux_size += value_count.second;
  }
  long long total = milieux_size * (long long)nbRepeat;
  if (milieux.size() == 1) {
    total = (milieux_size * (long long)nbRepeat) % (long long)nbMerge;
  }
  if (total == 0) {
    decltype(sequence) sequence_deb = get_sub_sequence(sequence, nbDeleteDeb);
    reverse(sequence.begin(), sequence.end());
    decltype(sequence) sequence_fin = get_sub_sequence(sequence, nbDeleteFin);
    reverse(sequence_fin.begin(), sequence_fin.end());
    for (auto value_count : sequence_fin) {
      if (!sequence_deb.empty() &&
          sequence_deb.back().first == value_count.first) {
        sequence_deb.back().second += value_count.second;
        sequence_deb.back().second %= nbMerge;
        if (sequence_deb.back().second == 0) {
          sequence_deb.pop_back();
        }
      } else {
        sequence_deb.push_back(value_count);
      }
    }
    nbDelete = sequence_deb.size();
  }
  total += (long long)nbDelete;
  printf("%lld", total);
}
