#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, k;
  cin >> n >> k >> m;
  deque<pair<long long, long long> > q;
  for (long long i = 0; i < n; i++) {
    long long cur;
    cin >> cur;
    if (!q.empty() && q.front().first == cur) {
      long long c = q.front().second;
      q.pop_front();
      if (c + 1 < k) q.push_front({cur, c + 1});
    } else {
      q.push_front({cur, 1});
    }
  }
  vector<pair<long long, long long> > tmp, tmpr;
  tmp.reserve(q.size());
  while (!q.empty()) {
    tmp.push_back(q.front());
    q.pop_front();
  }
  if (!tmp.empty())
    for (long long i = tmp.size() - 1; i >= 0; i--) {
      q.push_front(tmp[i]);
    }
  tmpr = tmp;
  reverse(tmp.begin(), tmp.end());
  if (m == 1) {
    long long answ = 0;
    for (long long i = 0; i < tmp.size(); i++) {
      answ += tmp[i].second;
    }
    cout << answ;
    cin >> n;
    return 0;
  }
  while (q.size() > 1 && q.back().first == q.front().first &&
         q.back().second + q.front().second >= k) {
    pair<long long, long long> c = {q.back().first,
                                    (q.back().second + q.front().second) % k};
    q.pop_back();
    q.pop_front();
    if (c.second > 0) {
      q.push_front(c);
      tmpr.pop_back();
      tmp.back().second = c.second;
    } else {
      tmpr.pop_back();
      tmp.pop_back();
    }
  }
  long long answ = 0;
  for (long long i = 0; i < tmp.size(); i++) {
    answ += tmp[i].second;
  }
  for (long long i = 0; i < tmpr.size(); i++) {
    answ += tmpr[i].second;
  }
  if (q.size() == 1) {
    long long cnt = 0;
    if (!tmp.empty() && tmp.back().first == q.front().first) {
      cnt += tmp.back().second;
      answ -= tmp.back().second;
      tmp.pop_back();
    }
    if (!tmpr.empty() && tmpr.back().first == q.front().first) {
      cnt += tmpr.back().second;
      answ -= tmpr.back().second;
      tmpr.pop_back();
    }
    long long c = ((m - 2) * q.front().second + cnt) % k;
    if (c == 0) {
      cout << 0;
    } else {
      cout << c + answ;
    }
  } else {
    long long cnt = 0;
    while (!q.empty()) {
      cnt += q.front().second;
      q.pop_front();
    }
    answ += cnt * (m - 2);
    cout << answ;
  }
  cin >> n;
  return 0;
}
