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 print = [](const DP &lp) {
    for (P x : lp) cout << x.first << " " << x.second << endl;
  };
  auto sum = [](const DP &lp) {
    Int res = 0;
    for (P x : lp) res += x.second;
    return res;
  };
  Int n, k, m;
  auto merge = [&](DP &lp, DP &lq) {
    while (!lp.empty() && !lq.empty() && lp.back().first == lq.front().first) {
      Int x = lp.back().second + lq.front().second;
      if (x < k) break;
      x %= k;
      lp.back().second = min(lp.back().second, x);
      lq.front().second = x - lp.back().second;
      if (!lp.back().second) lp.pop_back();
      if (!lq.front().second) lq.pop_front();
    }
  };
  cin >> n >> k >> m;
  vector<Int> a(n);
  for (Int i = 0; i < n; i++) cin >> a[i];
  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));
  };
  function<Int(DP, Int, bool)> solve = [&](DP lp, Int m, bool f) {
    Int n = sum(lp);
    if (m == 1) {
      return n;
    }
    if ((Int)lp.size() <= 1) {
      return (n * m) % k;
    }
    if (lp.front().first != lp.back().first) {
      return n * m;
    }
    DP lq = lp;
    merge(lp, lq);
    Int r = sum(lp), l = n - sum(lq);
    if (r + (n - l) > n) {
      if (f) {
        return (r + (n - l)) + (r - l) * (m - 2);
      } else {
        vector<Int> b(r);
        {
          int pos = 0;
          for (auto x : lp)
            for (int i = 0; i < x.second; i++) b[pos++] = x.first;
          assert(pos == r);
          b.erase(b.begin(), b.begin() + l);
        }
        DP latte;
        get(b, latte, k);
        Int res = solve(latte, m, 1);
        if (res) return (r + (n - l) - (r - l) * 2) + res;
        latte.clear();
        b.resize(r);
        {
          int pos = 0;
          for (auto x : lp)
            for (int i = 0; i < x.second; i++) b[pos++] = x.first;
          assert(pos == r);
          b.erase(b.begin() + l, b.begin() + r);
        }
        get(b, latte, k);
        DP malta;
        b.resize(n - l);
        {
          int pos = 0;
          for (auto x : lq)
            for (int i = 0; i < x.second; i++) b[pos++] = x.first;
          assert(pos == n - l);
          b.erase(b.begin(), b.begin() + (r - l));
        }
        get(b, malta, k);
        merge(latte, malta);
        while (!malta.empty()) {
          if (!latte.empty() && latte.back().first == malta.front().first) {
            latte.back().second += malta.front().second;
            latte.back().second %= k;
            if (!latte.back().second) latte.pop_back();
          } else {
            latte.push_back(malta.front());
          }
          malta.pop_front();
        }
        return sum(latte);
      }
    }
    while (!lq.empty()) {
      if (!lp.empty() && lp.back().first == lq.front().first)
        lp.back().second += lq.front().second;
      else
        lp.push_back(lq.front());
      lq.pop_front();
    }
    if (lp.empty()) {
      if (m & 1)
        return n;
      else
        return 0LL;
    }
    assert(0);
  };
  DP lp;
  get(a, lp, k);
  cout << solve(lp, m, 0) << endl;
  return 0;
}
