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 MAXN = 1e6 + 5;
int A[MAXN + 5], s[MAXN + 5];
int Next[MAXN + 5], num[MAXN + 5];
int Last[MAXN + 5];
long long N, K, M, cnt = 0;
long long sumv = 0;
void solve() {
  for (int i = 0; i <= N; i++) Next[i] = i + 1;
  Next[N + 1] = N + 1;
  for (int i = N; i >= 1; i--) {
    if (A[i] != A[Next[i]])
      num[i] = 1;
    else {
      num[i] = num[Next[i]] + 1;
      if (num[i] == K) {
        int c = K - 1, tot = i;
        while (c > 0) c--, tot = Next[tot];
        Next[i - 1] = Next[tot];
      }
    }
  }
  int tot = Next[0];
  while (tot <= N) s[++cnt] = A[tot], tot = Next[tot];
}
long long RE() {
  memset(Next, 0, sizeof(Next));
  for (int i = 1; i <= cnt; i++) Next[i] = i, Last[i] = i;
  for (int i = cnt - 1; i >= 1; i--)
    if (s[i] == s[i + 1]) Next[i] = Next[i + 1];
  for (int i = 2; i <= cnt; i++)
    if (s[i] == s[i - 1]) Last[i] = Last[i - 1];
  int tail = 1, head = cnt;
  bool check = true;
  while (tail <= cnt) {
    if (Next[tail] == head) break;
    if (s[tail] != s[head]) {
      check = false;
      break;
    }
    int a = Next[tail] - tail + 1, b = head - Last[head] + 1;
    if ((a + b) % K == 0)
      sumv -= (a + b) * (M - 1);
    else {
      sumv -= (a + b) / K * K * (M - 1);
      check = false;
      break;
    }
    tail = Next[tail] + 1, head = Last[head] - 1;
  }
  if (check) {
    memset(A, 0, sizeof(A));
    sumv -= (head - tail + 1) * M / K * K;
    N = 0;
    for (int i = 1; i < tail; i++) A[++N] = s[i];
    for (int i = 1; i <= (head - tail + 1) * M % K; i++) A[++N] = s[tail];
    for (int i = head + 1; i <= cnt; i++) A[++N] = s[i];
    cnt = 0;
    memset(Next, 0, sizeof(Next));
    memset(num, 0, sizeof(num));
    solve();
    sumv -= (N - cnt);
  }
  return sumv;
}
int main() {
  scanf("%I64d %I64d %I64d", &N, &K, &M);
  for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
  if (K >= 2 * N) {
    bool check = true;
    for (int i = 1; i <= N - 1; i++)
      if (A[i] != A[i + 1]) check = false;
    if (check)
      printf("%I64d\n", N * M - N * M / K * K);
    else
      printf("%I64d\n", N * M);
  } else {
    solve();
    sumv = cnt * M;
    printf("%I64d\n", RE());
  }
}
