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;
using Int = long long;
using P = pair<Int, Int>;
using DP = deque<P>;
signed main() {
  auto get = [](vector<Int> &a, DP &lp, int k) {
    Int pre = -1, len = 0, n = a.size();
    for (Int i = 0; i < n; i++) {
      if (a[i] != pre) {
        if (len) lp.push_back(P(pre, len));
        len = 0;
        pre = a[i];
      }
      len++;
      len %= k;
    }
    if (len) lp.push_back(P(pre, len));
  };
  auto sum = [](const DP &lp) {
    Int res = 0;
    for (P x : lp) res += x.second;
    return res;
  };
  function<Int(DP &, Int, Int)> solve = [&](DP &lp, Int m, Int k) {
    Int n = sum(lp);
    if ((Int)lp.size() <= 1) return (n * m) % k;
    if (lp.front().first != lp.back().first) return n * m;
    Int a = lp.front().second;
    Int b = lp.back().second;
    Int s = a + b;
    lp.pop_front();
    lp.pop_back();
    if (s % k) {
      Int t = solve(lp, 1, k);
      if (t) return s + (s % k) * (m - 1) + t * m;
      return (s * m) % k;
    }
    Int t = solve(lp, m, k);
    if (t) return s + t;
    return 0LL;
  };
  Int n, k, m;
  cin >> n >> k >> m;
  vector<Int> a(n);
  for (Int i = 0; i < n; i++) cin >> a[i];
  DP lp;
  get(a, lp, k);
  cout << solve(lp, m, k) << endl;
  return 0;
}
