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;
long long n, k, m;
vector<int> val, num;
vector<int> a, aa;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k >> m;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    aa.push_back(x);
    if (val.empty() || val.back() != x) {
      val.push_back(x);
      num.push_back(1);
    } else {
      ++num.back();
      if (num.back() == k) {
        val.pop_back();
        num.pop_back();
      }
    }
  }
  if (val.empty()) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < val.size(); ++i) {
    for (int j = 0; j < num[i]; ++j) a.push_back(val[i]);
  }
  n = a.size();
  if (m == 1) {
    cout << n << endl;
    return 0;
  }
  if (k >= n) {
    if (val.size() > 1)
      cout << n * m << endl;
    else
      cout << (n * m) % k << endl;
    return 0;
  }
  vector<int> va, nu;
  for (int i = 0; i < n; ++i) {
    if (va.empty() || va.back() != a[i]) {
      va.push_back(a[i]);
      nu.push_back(1);
    } else {
      ++nu.back();
      if (nu.back() == k) {
        va.pop_back();
        nu.pop_back();
      }
    }
  }
  long long w = 0;
  long long last = n;
  vector<int> vaa = va;
  vector<int> nuu = nu;
  bool go = true;
  for (int i = 0; go && i < vaa.size(); ++i) {
    int x = vaa[i];
    int q = nuu[i];
    if (va.empty() || va.back() != x)
      go = false;
    else {
      if (nu.back() + q == k) {
        w += k;
        if (w < n) last -= nu.back();
        va.pop_back();
        nu.pop_back();
      } else if (nu.back() + q > k) {
        w += k;
        if (w < n) last -= nu.back();
        va.pop_back();
        nu.pop_back();
        go = false;
      } else
        go = false;
    }
    if (w >= n) go = false;
  }
  if (w <= n) {
    cout << m * n - (m - 1) * w << endl;
    return 0;
  }
  int d = (n * (m - 1)) % k;
  vector<int> r;
  for (int i = 0; i < last; ++i) r.push_back(aa[i]);
  for (int i = 0; i < d; ++i) r.push_back(aa[last - 1]);
  for (int i = last; i < n; ++i) r.push_back(aa[i]);
  val.clear();
  num.clear();
  for (int i = 0; i < r.size(); ++i) {
    int x = r[i];
    if (val.empty() || val.back() != x) {
      val.push_back(x);
      num.push_back(1);
    } else {
      ++num.back();
      if (num.back() == k) {
        val.pop_back();
        num.pop_back();
      }
    }
  }
  cout << accumulate(num.begin(), num.end(), 0) << endl;
  return 0;
}
