#include <bits/stdc++.h>
using namespace std;
char buff[(int)2e6 + 17];
const long long inf = (long long)1e9 + 7ll;
const int maxn = (int)1e5 + 17;
int n, m, k;
long long ans;
int a[maxn];
bool read() {
  if (scanf("%d %d %d", &n, &k, &m) != 3) return false;
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  return true;
}
void solve_for_2(set<pair<int, int> >& tl, set<pair<int, int> >& tr) {
  for (;;) {
    if (tl.empty() || tr.empty()) {
      printf("%lld\n", ans);
      return;
    }
    if (a[tl.rbegin()->first] != a[tr.begin()->first]) {
      printf("%lld\n", ans);
      return;
    }
    long long p = tl.rbegin()->second + tr.begin()->second;
    ans -= p - p % k;
    tl.erase(*tl.rbegin());
    tr.erase(*tr.begin());
    if (p % k != 0) {
      printf("%lld\n", ans);
      return;
    }
  }
}
void solve() {
  set<pair<int, int> > x, y;
  for (int l = 0; l < n;) {
    int r = l;
    for (; r < n && a[r] == a[l]; ++r)
      ;
    x.insert(make_pair(l, r - l));
    y.insert(make_pair(r - l, l));
    l = r;
  }
  ans = n;
  for (;;) {
    if (y.empty() || y.rbegin()->first < k) break;
    pair<int, int> cur = *y.rbegin();
    y.erase(cur);
    auto it = x.find(make_pair(cur.second, cur.first));
    if (*it == *x.begin()) {
      ans -= cur.first - cur.first % k;
      x.erase(it);
      if (cur.first % k != 0) {
        x.insert(make_pair(cur.second, cur.first % k));
        y.insert(make_pair(cur.first % k, cur.second));
      }
    } else if (*it == *x.rbegin()) {
      ans -= cur.first - cur.first % k;
      x.erase(it);
      if (cur.first % k != 0) {
        x.insert(make_pair(cur.second, cur.first % k));
        y.insert(make_pair(cur.first % k, cur.second));
      }
    } else {
      auto _pr = it;
      --_pr;
      auto pr = *_pr;
      auto _nx = it;
      ++_nx;
      auto nx = *_nx;
      ans -= cur.first - cur.first % k;
      x.erase(it);
      if (cur.first % k != 0) {
        x.insert(make_pair(cur.second, cur.first % k));
        y.insert(make_pair(cur.first % k, cur.second));
      } else {
        if (a[pr.first] == a[nx.first]) {
          x.erase(pr);
          x.erase(nx);
          y.erase(make_pair(pr.second, pr.first));
          y.erase(make_pair(nx.second, nx.first));
          x.insert(make_pair(pr.first, pr.second + nx.second));
          y.insert(make_pair(pr.second + nx.second, pr.first));
        }
      }
    }
  }
  if (m == 1) {
    printf("%lld\n", ans);
    return;
  }
  ans *= m;
  auto tl = x;
  auto tr = x;
  if (m == 2) {
    solve_for_2(tl, tr);
    return;
  }
  for (;;) {
    if (x.empty()) {
      solve_for_2(tl, tr);
      return;
    }
    if (static_cast<int>(x.size()) == 1) {
      if (a[tl.rbegin()->first] == a[x.begin()->first] &&
          a[x.begin()->first] == a[tr.begin()->first]) {
        long long p = tl.rbegin()->second + x.begin()->second * (m - 2ll) +
                      tr.begin()->second;
        auto cur = *tl.rbegin();
        tl.erase(*tl.rbegin());
        tr.erase(*tr.begin());
        ans -= p - p % k;
        if (p % k != 0) tl.insert(make_pair(cur.first, p % k));
        solve_for_2(tl, tr);
      } else {
        printf("%lld\n", ans);
      }
      return;
    }
    if (a[x.begin()->first] != a[x.rbegin()->first]) {
      printf("%lld\n", ans);
      return;
    }
    auto cur = *x.begin();
    long long p = x.begin()->second + x.rbegin()->second;
    ans -= (m - 1ll) * (p - p % k);
    x.erase(x.begin());
    x.erase(--x.end());
    tl.erase(*tl.rbegin());
    tr.erase(*tr.begin());
    if (p % k != 0) {
      printf("%lld\n", ans);
      return;
    }
  }
}
int main() {
  while (read()) solve();
  return 0;
}
