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;
vector<int> v;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, m, x;
  cin >> n >> k >> m;
  vector<pair<int, int>> tinue;
  int last = 0, cont = 0;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    v.push_back(x);
    if (last == 0) last = x;
    if (x == last)
      ++cont;
    else {
      tinue.push_back(make_pair(last, cont));
      last = x, cont = 1;
    }
    if (cont == k) {
      int tmp = k;
      while (tmp--) v.pop_back();
      if (!tinue.empty())
        last = tinue.back().first, cont = tinue.back().second, tinue.pop_back();
      else
        last = cont = 0;
    }
  }
  if (k >= n) {
    int ok = 1;
    for (int i = 1; i < v.size(); ++i) {
      if (v[i] != v[i - 1]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      cout << (long long)((long long)m * (long long)n) % (long long)k << "\n";
    } else
      cout << (long long)((long long)m * (long long)n) << "\n";
    return 0;
  }
  if (m < 2) {
    cout << v.size() << "\n";
    return 0;
  }
  int head = 0, tail = v.size() - 1;
  while (tail - head >= k) {
    int oldh = head, oldt = tail;
    int num = v[head];
    int cnt = 1;
    while (v[head + cnt] == num && cnt < k) ++cnt;
    if (cnt == k)
      head = head + cnt;
    else {
      int tcnt = 0;
      while (v[tail - tcnt] == num) ++tcnt;
      if (tcnt + cnt >= k) {
        tail = tail - tcnt;
        head = head + (k - tcnt);
      }
    }
    if (oldh == head && oldt == tail) break;
  }
  long long ans = 0;
  ans += (long long)head - 0ll;
  ans += (long long)(v.size() - 1 - tail);
  ans += (long long)(tail - head + 1) * (long long)m;
  int ok = 1;
  for (int i = head + 1; i <= tail; ++i) {
    if (v[i] != v[i - 1]) {
      ok = 0;
      break;
    }
  }
  if (ok) {
    long long rem =
        ((long long)(tail - head + 1) * (long long)m) % (long long)k;
    if (rem == 0)
      ans = 0;
    else
      ans -= (long long)(tail - head + 1) * (long long)m - rem;
  }
  cout << ans << "\n";
  return 0;
}
