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;
const int N = 100005;
struct node {
  int x, y;
  node() {}
  node(int x, int y) : x(x), y(y) {}
} a[N];
int n, k, m, nn;
int c[N];
long long solve(int l, int r) {
  int i, j;
  if (l > r) return 0;
  if (c[l] != c[r]) return 1ll * (r - l + 1) * m;
  for (i = l; i < r && c[i] == c[i + 1]; i++)
    ;
  for (j = r; j > l && c[j] == c[j - 1]; j--)
    ;
  if (i == r) return 1ll * m * (r - l + 1) % k;
  int len = i - l + 1 + r - j + 1;
  long long s;
  len = len % k;
  if (len == 0) {
    s = solve(i + 1, j - 1);
    if (!s)
      return 0;
    else
      return s + 1ll * k;
  }
  return 1ll * (m - 1) * len + 1ll * (r - l + 1 - len) * m + 1ll * len;
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
    if (c[i] == a[nn].x)
      a[nn].y++;
    else
      a[++nn] = node(c[i], 1);
    if (a[nn].y == k) nn--;
  }
  if (!nn) {
    printf("%d\n", nn);
    return 0;
  }
  n = 0;
  for (int i = 1; i <= nn; i++) {
    while (a[i].y) {
      a[i].y--;
      c[++n] = a[i].x;
    }
  }
  if (m == 1) {
    printf("%d\n", n);
    return 0;
  }
  printf("%I64d\n", solve(1, n));
  return 0;
}
