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 inf = 0x3f3f3f3f;
const int maxn = 100005;
int a[maxn], f[maxn], t[maxn], top;
int main() {
  long long n, m, k, ans = 0;
  scanf("%lld%lld%lld", &n, &k, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  top = 0;
  for (int i = 1; i <= n; i++) {
    t[++top] = a[i];
    if (top == 1 || t[top] != t[top - 1])
      f[top] = 1;
    else
      f[top] = f[top - 1] + 1;
    if (f[top] == k) top -= k;
  }
  int l = 1, r = top;
  while (l < r && t[l] == t[r]) {
    int L = l, R = r, cnt = 0;
    while (L < R && t[L] == t[l] && cnt < k) {
      ++cnt;
      ++L;
    }
    while (L < R && t[r] == t[R] && cnt < k) {
      ++cnt;
      --R;
    }
    if (cnt == k) {
      ans += k;
      l = L;
      r = R;
    } else
      break;
  }
  int flag = 1;
  for (int i = l + 1; i <= r; i++) {
    if (t[i] != t[i - 1]) {
      flag = 0;
      break;
    }
  }
  if (flag) {
    if ((long long)(r - l + 1) * m % k != 0)
      printf("%lld\n", (long long)(r - l + 1) * m % k + ans);
    else
      printf("0\n");
  } else
    printf("%lld\n", (long long)(r - l + 1) * m + ans);
}
