#include <bits/stdc++.h>
using namespace std;
template <class T>
void mini(T &l, T r) {
  l = min(l, r);
}
template <class T>
void maxi(T &l, T r) {
  l = max(l, r);
}
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
using llint = long long;
const int N = 1e5 + 10;
int a[N * 4];
int n, k, m;
llint mrg(int *a, int n) {
  vector<pair<int, int> > v;
  llint ret = 0;
  for (int i = 0; i < n; ++i) {
    if (v.empty() || v.back().first != a[i]) {
      v.push_back(make_pair(a[i], 1));
    } else {
      v.back().second++;
    }
    while (!v.empty() && v.back().second == k) {
      v.pop_back();
      ret += k;
    }
  }
  int nw = 0;
  for (auto p : v) {
    assert(p.second < k);
    for (int i = 0; i < p.second; ++i) a[nw++] = p.first;
  }
  assert(nw == n - ret);
  return n - ret;
}
llint go(int *a, int n) {
  if (n == 0) return 0;
  int hd = n;
  int tl = n;
  for (int i = 0; i < n; ++i) {
    if (a[i] == a[n - 1]) {
      a[tl++] = a[i];
    } else {
      hd = i;
      break;
    }
  }
  int cnt = 0;
  llint del = 0;
  llint ret = 0;
  for (int i = tl - 1; i >= hd; --i) {
    if (a[i] == a[tl - 1]) {
      ++cnt;
    } else {
      break;
    }
  }
  for (int i = 0; i < tl; ++i) 42;
  42;
  if (cnt == n) {
    ret += 1ll * n * m % k;
  } else {
    if (cnt % k == 0) {
      ret += 0;
      llint tmp = go(a + hd, n - cnt);
      42;
      if (tmp == 0) {
        ret += 1ll * cnt % k;
      } else {
        if (hd > 0)
          ret += 1ll * cnt;
        else
          ret += 1ll * cnt % k;
      }
      ret += tmp;
      42;
    } else {
      llint tmp = mrg(a + hd, n - cnt);
      for (int i = 0; i < tl; ++i) 42;
      42;
      if (tmp == 0) {
        ret += 1ll * cnt * m % k;
      } else {
        ret += 1ll * cnt % k * (m - 1);
        ret += 1ll * cnt;
      }
      ret += 1ll * tmp * m;
    }
  }
  42;
  return ret;
}
void run() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  n = mrg(a, n);
  printf("%lld\n", go(a, n));
}
int main() {
  run();
  return 0;
}
