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 LL = long long;
int n, m, k;
LL sum(std::list<std::pair<int, LL>> &list) {
  LL ret = 0;
  for (auto t : list) {
    ret += t.second;
  }
  return ret;
}
LL calc(std::list<std::pair<int, LL>> &list) {
  std::list<std::pair<int, LL>> w;
  for (auto t : list) {
    if (t.second == 0) {
      continue;
    } else if (!w.empty() && t.first == w.back().first) {
      (w.back().second += t.second) %= k;
    } else {
      w.emplace_back(t);
    }
  }
  return sum(w);
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  std::list<std::pair<int, LL>> A, front, back;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    if (A.empty() || x != A.back().first)
      A.emplace_back(x, 1);
    else if (A.back().first == x) {
      if (++A.back().first == k) A.pop_back();
    }
  }
  while (A.size() > 1) {
    if (A.back().first == A.front().first &&
        A.back().second + A.front().second >= k) {
      back.emplace_front(A.back());
      LL tmp = k - A.back().second;
      front.emplace_back(A.front().first, tmp);
      A.pop_back();
      if ((A.front().second -= tmp) == 0) A.pop_front();
    } else {
      break;
    }
  }
  if (A.empty()) {
    front.insert(front.end(), back.begin(), back.end());
    printf("%lld\n", calc(front));
  } else if (A.size() == 1) {
    front.emplace_back(A.front().first, A.front().second * m % k);
    front.insert(front.end(), back.begin(), back.end());
    printf("%lld\n", calc(front));
  } else {
    LL result = sum(A) * m + sum(front) + sum(back);
    printf("%lld\n", result);
  }
}
