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 ni() {
  int val;
  scanf("%i", &val);
  return val;
}
pair<int, int> npi() {
  pair<int, int> val;
  scanf("%i %i", &val.first, &val.second);
  return val;
}
int64_t nll() {
  int64_t val;
  scanf("%I64d", &val);
  return val;
}
vector<int> nvi(int n, int corr = 0) {
  vector<int> a(n);
  for (int i = 0; i < n; ++i) a[i] = ni() + corr;
  return move(a);
}
char nc() {
  char val;
  do {
    val = getchar();
  } while (val == ' ' || val == '\r' || val == '\n');
  return val;
}
char ncs() {
  char val;
  do {
    val = getchar();
  } while (false);
  return val;
}
string ns() {
  static char buff[1024 * 4000];
  scanf("%s", buff);
  return string{buff};
}
int64_t gcd(int64_t a, int64_t b) {
  while (b) {
    auto tmp = a % b;
    a = b;
    b = tmp;
  }
  return a;
}
int64_t tr2(int xv1, int yv1, int xv2, int yv2, int x3, int y3) {
  return 1LL * (xv2 - xv1) * (y3 - yv1) - 1LL * (yv2 - yv1) * (x3 - xv1);
}
const int maxn = 100000;
int n, k, m;
vector<pair<int, int>> v;
int tot;
int64_t ans;
const string input_dir = "inputs\\";
string input_file = input_dir + "input.txt";
string output_file = input_dir + "output.txt";
void init_streams() {}
void ret(int64_t res) {
  cout << res << endl;
  exit(0);
}
vector<int> eat(vector<int> a, int k) {
  if (a.size() < k) return move(a);
  vector<int> cnt(a.size());
  vector<int> prev;
  prev.reserve(a.size());
  if (a.size() > 0) {
    cnt[0] = 1;
    prev.push_back(0);
  }
  for (int i = 1; i < a.size(); ++i) {
    ++cnt[i];
    if (!prev.empty() && a[i] == a[prev.back()]) cnt[i] += cnt[prev.back()];
    prev.push_back(i);
    if (cnt[i] == k) prev.resize(prev.size() - k);
  }
  for (auto& v : prev) v = a[v];
  return move(prev);
}
int main() {
  init_streams();
  auto n = ni(), k = ni(), m = ni();
  auto a = nvi(n);
  a = eat(a, k);
  vector<pair<int, int>> st;
  for (int i = 0; i < a.size(); ++i) {
    if (!i || st.back().first != a[i])
      st.emplace_back(make_pair(a[i], 1));
    else
      ++st.back().second;
  }
  auto ans = 1LL * m * a.size();
  if (1 == m || 1 == st.size()) ret(ans % k);
  int l = 0, r = st.size() - 1;
  while (l < r) {
    if (st[l].first != st[r].first) ret(ans);
    auto sm = st[l].second + st[r].second;
    if (sm >= k) ans = ans - 1LL * k * (m - 1);
    if (sm != k) ret(ans);
    ++l;
    --r;
  }
  if (l == r) {
    auto tot_left = 1LL * st[l].second * m;
    ans -= tot_left - (tot_left % k);
    if (0 == tot_left % k) ans = 0;
  }
  ret(ans);
  return 0;
}
