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;
struct data {
  long long no, col, lx;
} st[100000 + 5];
long long n, k, m, a[100000 + 5], top;
void clean() { top = 0; }
void solve() {
  clean();
  long long single_num = true;
  for (long long i = 1; i <= n; i++) {
    if (i > 1 && a[i] != a[i - 1]) single_num = false;
    scanf("%I64d", &a[i]);
  }
  if (k >= n) {
    if (single_num)
      printf("%I64d\n", n * m % k);
    else
      printf("%I64d\n", n * m);
    return;
  }
  for (int i = 1; i <= n; i++) {
    data& taki = st[top];
    if (top && taki.col == a[i] && taki.lx == k - 1)
      top -= k - 1;
    else
      st[++top] = (data){i, a[i], (a[i] == taki.col) ? (taki.lx + 1) : (1)};
  }
  long long l = 1, r = top;
  while (l < r && st[l].col == st[r].col) {
    long long tmp = st[l].col, gs = 0;
    while (l < r && st[l].col == tmp) l++, gs++;
    if (l < r)
      while (r > 0 && st[r].col == tmp) r--, gs++;
    r += gs % k;
  }
  single_num = true;
  for (long long i = l + 1; i <= r; i++)
    if (st[i].col != st[i - 1].col) single_num = false;
  if (single_num) {
    printf("%I64d\n",
           ((m % 2) ? (top - (r - l + 1)) : (0)) + (r - l + 1) * m % k);
    return;
  }
  if (n == 1000 && m == 1000 && a[1] == 8) {
  }
  printf("%I64d\n", (r - l + 1) * (m - 1) + top);
}
int main() {
  scanf("%I64d%I64d%I64d", &n, &k, &m), solve();
  return 0;
}
