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;
int main() {
  int n, k, m;
  cin >> n >> k >> m;
  vector<int> a, f;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (!a.empty() && a.back() == x) {
      f.back() += 1;
      if (f.back() == k) {
        a.pop_back();
        f.pop_back();
      }
    } else {
      a.push_back(x);
      f.push_back(1);
    }
  }
  int len = 0, sz = a.size();
  for (int x : f) len += x;
  if (m == 1) {
    cout << len << endl;
    return 0;
  }
  int i = 0;
  while (i < sz && a[i] == a[sz - 1 - i] && f[i] + f[sz - 1 - i] == k) i++;
  int mid = 0;
  for (int j = 0; j < sz; j++)
    if (i <= j && j <= sz - 1 - i) mid += f[j];
  long long int ans = 0;
  if (i == sz) {
    if (m % 2 == 1) ans = len;
  } else if (i == sz / 2) {
    if (sz % 2 == 0) {
      if (m % 2 == 1) ans = len;
    } else {
      assert(mid == f[sz / 2]);
      long long int x = (1ll * mid * m) % k;
      if (x == 0)
        ans = 0;
      else
        ans = x + len - mid;
    }
  } else {
    long long int dx = 0;
    if (a[i] == a[sz - 1 - i])
      dx = -(f[i] + f[sz - 1 - i]) + (f[i] + f[sz - 1 - i]) % k;
    ans = len - mid + 1ll * mid * m + dx * (m - 1);
  }
  cout << ans << endl;
  return 0;
}
