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>
int n, m, k;
int a[100010];
int num[100010];
int stack[100010];
int t;
void release() {
  while (t >= 2 && stack[t] == stack[t - 1])
    if ((num[t] + num[t - 1]) % k == 0)
      t -= 2;
    else {
      num[t - 1] = (num[t] + num[t - 1]) % k;
      --t;
    }
}
int main() {
  scanf("%d %d %d", &n, &k, &m);
  int tot = 0, last = 0;
  int x, cnt = 0, sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    if (x == last)
      ++cnt;
    else {
      if (last && cnt % k) {
        stack[++t] = last;
        num[t] = cnt % k;
        release();
      }
      last = x;
      cnt = 1;
    }
  }
  if (cnt % k) {
    stack[++t] = last;
    num[t] = cnt % k;
    release();
  }
  for (int i = 1; i <= t; ++i) {
    a[tot] = stack[i];
    sum += num[i];
    num[tot++] = num[i];
  }
  int p = 0, q = tot - 1;
  int left = 0, right = 0, middle;
  while (a[p] == a[q] && p < q && num[p] + num[q] >= k &&
         (num[p] + num[q]) % k == 0) {
    left += num[++p];
    right += num[--q];
  }
  if (q >= 0 && p < tot)
    if (a[p] == a[q] && p < q && num[p] + num[q] >= k) {
      if (num[p] < num[q]) {
        left += num[p];
        right += (num[p] + num[q]) / k * k - num[p];
        num[q] -= (num[p] + num[q]) / k * k - num[p];
        ++p;
      } else {
        right += num[q];
        left += (num[p] + num[q]) / k * k - num[q];
        num[p] -= (num[p] + num[q]) / k * k - num[q];
        --q;
      }
    }
  middle = sum - left - right;
  if (p < q)
    printf("%d\n", left + right + middle * m);
  else if (p == q) {
    if (num[p] * m % k == 0)
      printf("0\n");
    else
      printf("%d\n", left + right + num[p] * m % k);
  }
  return 0;
}
