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(n), f(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int sz = 0, len = 0;
  for (int i = 0; i < n;) {
    int v = a[i], c = 0;
    while (i < n && a[i] == v) i++, c++;
    c %= k;
    if (c == 0) continue;
    a[sz] = v;
    f[sz++] = c;
    len += c;
  }
  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 {
    ans = len - mid;
    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 += 1ll * mid * m + dx * (m - 1);
  }
  cout << ans << endl;
  return 0;
}
