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>
long long stk[300010], num[300010];
int o[300010];
long long minu[300010];
int main() {
  int n, k, m;
  int top = 0;
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 0; i < n; i++) scanf("%d", &o[i]);
  long long cntp = 0;
  top = 0;
  for (int i = 0; i < n; i++) {
    if (top > 0 && stk[top - 1] == o[i]) {
      num[top - 1]++;
      if (num[top - 1] == k) {
        cntp += num[top - 1];
        top--;
      }
      continue;
    }
    stk[top] = o[i];
    num[top] = 1;
    top++;
  }
  if (top == 0) {
    printf("0\n");
    return 0;
  } else if (m == 1) {
    printf("%lld\n", (long long)n * m - cntp);
    return 0;
  }
  long long ans = 0;
  long long sum = 0;
  bool flag = false;
  int cnt = 0;
  for (int i = 0; i < top; i++) {
    int l = i;
    int r = top - i - 1;
    if (stk[l] != stk[r]) break;
    if (num[l] + num[r] >= k) {
      long long tmp = (num[l] + num[r]) % k;
      sum += num[l] + num[r] - (num[l] + num[r]) % k;
      if (tmp) {
        if (l == r || l == r - 1) flag = true;
        break;
      }
      cnt++;
      continue;
    }
    if (l == r || l == r - 1) flag = true;
    break;
  }
  if (flag) {
    long long sav;
    if (n & 1)
      sav = (num[n / 2] * m) % k;
    else
      sav = ((num[n / 2] + num[n / 2 - 1]) * m) % k;
    if (sav != 0)
      ans += sav + sum;
    else if (sum > 0)
      printf("%lld\n", sum);
  } else {
    if (cnt == top)
      ans += (m & 1) * (n - cntp);
    else
      ans += n * m - (m - 1) * sum - (m * cntp);
  }
  printf("%lld\n", ans);
  return 0;
}
