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>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename T>
T gcd(T a, T b) {
  T m;
  while (b != T(0)) {
    m = a % b;
    a = b;
    b = m;
  }
  return a;
}
template <typename T>
T lcm(T a, T b) {
  return a == 0 && b == 0 ? 0 : (a / gcd(a, b)) * b;
}
int const MAXN = 1 << 19;
int N, M, K;
int solve() {
  std::vector<std::pair<int, int> > st;
  cin >> N >> K >> M;
  for (int i = 1; i <= N; ++i) {
    int a;
    cin >> a;
    if (!st.empty() && st.back().first == a)
      st.back().second++;
    else
      st.push_back(std::pair<int, int>(a, 1));
    if (st.back().second == K) st.pop_back();
  }
  if (st.empty()) {
    printf("0\n");
    return 0;
  }
  int rn = st.size();
  if (rn == 1) {
    long long total = st[0].second * 1ll * M;
    printf("%lld\n", (long long)(total % K));
    return 0;
  }
  if (st[0].first != st.back().first || st[0].second + st.back().second < K) {
    long long ans = 0;
    for (std::pair<int, int> p : st) ans += p.second;
    ans *= M;
    printf("%lld\n", ans);
    return 0;
  }
  int p = 0;
  while (p < rn && st[p].first == st[rn - p - 1].first &&
         st[p].second + st[rn - p - 1].second == K)
    ++p;
  if (p >= (rn + 1) / 2) p = rn;
  if (p == rn) {
    long long ans = 0;
    if (M % 2 == 0)
      ans = 0;
    else {
      for (std::pair<int, int> p : st) ans += p.second;
    }
    printf("%lld\n", ans);
    return 0;
  }
  if (rn % 2 == 1 && p == rn / 2) {
    long long ans = 0;
    long long middle = M * 1ll * st[p].second;
    if (middle % K == 0)
      ans = 0;
    else {
      for (int i = 0; i < p; ++i) ans += st[i].second;
      ans += middle % K;
      for (int i = p + 1; i < rn; ++i) ans += st[i].second;
    }
    printf("%lld\n", ans);
    return 0;
  }
  {
    long long ans = 0;
    for (int i = 0; i < p; ++i) ans += st[i].second;
    for (int i = p; i < rn - p; ++i) ans += st[i].second * 1ll * M;
    for (int i = rn - p; i < rn; ++i) ans += st[i].second;
    if (st[p].first == st[rn - p - 1].first &&
        st[p].second + st[rn - p - 1].second >= K) {
      ans -= (M - 1) * 1ll * K;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
int main(int argc, char* argv[]) {
  ::std::ios::sync_with_stdio(false);
  ::std::cin.tie(0);
  ::std::cout.tie(0);
  solve();
  return 0;
}
