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;
const int maxn = 100000 + 10;
vector<pair<int, int>> d;
int t[maxn];
int main() {
  int n, m, k;
  while (scanf("%d%d%d", &n, &k, &m) == 3) {
    for (int i = 0; i < n; i++) scanf("%d", &t[i]);
    d.clear();
    int cnt = 1;
    int pre = t[0];
    for (int i = 1; i < n; i++) {
      if (t[i] != pre) {
        if (cnt % k != 0) {
          d.push_back({pre, cnt % k});
          cnt = 1;
        } else {
          if (d.size() && d.back().first == t[i]) {
            cnt = d.back().second + 1;
            d.pop_back();
          } else
            cnt = 1;
        }
        pre = t[i];
      } else
        cnt++;
    }
    if (cnt % k) d.push_back({t[n - 1], cnt % k});
    vector<pair<int, int>> head, tail, now, mid;
    int lim = d.size(), same = true;
    for (int i = 0; i < lim; i++) {
      if (i == lim - 1) {
        now.push_back(d[i]);
        break;
      }
      auto p1 = d[i], p2 = d[lim - 1];
      if (same && p1.first == p2.first) {
        int s = p1.second + p2.second;
        if (s % k != 0) mid.push_back({p1.first, s % k}), same = false;
        head.push_back(d[i]);
        tail.push_back(d[lim - 1]);
        lim--;
      } else {
        same = false;
        now.push_back(p1);
      }
    }
    long long sum_now = 0;
    for (auto i : now) sum_now += i.second;
    sum_now *= (long long)m;
    if (now.size() == 1 && mid.size() == 0) sum_now %= k;
    assert(mid.size() <= 1);
    long long sum_mid = 0;
    for (auto i : mid) sum_mid += i.second;
    sum_mid *= (m - 1);
    if (now.size() == 0) sum_mid %= k;
    long long sum_head = 0;
    if (sum_now + sum_mid == 0) {
      reverse(tail.begin(), tail.end());
      for (auto i : tail) {
        auto& p1 = head.back();
        if (p1.first == i.first) {
          p1.second += i.second;
          p1.second %= k;
          if (p1.second == 0) head.pop_back();
        } else
          head.push_back(p1);
      }
      for (auto i : head) sum_head += i.second;
    } else {
      for (auto i : head) sum_head += (long long)i.second;
      for (auto i : tail) sum_head += (long long)i.second;
    }
    printf("%lld\n", sum_head + sum_mid + sum_now);
  }
  return 0;
}
