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;
int k;
int s[100009];
int c[100009];
int dsu_par[100009];
int dsu_find(int v) {
  if (v == -1) return -1;
  if (dsu_par[v] == v) return v;
  return dsu_par[v] = dsu_find(dsu_par[v]);
}
void dsu_union(int u, int v) { dsu_par[dsu_find(v)] = dsu_find(u); }
int compress(int n) {
  for (int i = 0; i < n; i++) {
    dsu_par[i] = i;
    if (dsu_find(i - 1) == -1)
      c[i] = 1;
    else if (s[dsu_find(i - 1)] == s[i])
      c[i] = c[dsu_find(i - 1)] + 1;
    if (c[i] >= k) {
      int t = i;
      for (int j = 0; j < k; j++) {
        int tmp = dsu_find(t - 1);
        dsu_union(tmp, t);
        t = tmp;
      }
    }
  }
  int nn = 0;
  for (int i = 0; i < n; i++) {
    if (dsu_par[i] == i) s[nn++] = s[i];
  }
  return nn;
}
int main() {
  int n, m;
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", s + i);
  }
  n = compress(n);
  if (n == 0) {
    cout << 0;
    return 0;
  }
  long long rem = 0;
  for (int i = 0, j = n - 1; i <= j;) {
    if (s[i] != s[j]) {
      rem += (long long)m * (long long)(j - i + 1);
      cout << rem;
      return 0;
    }
    int ii = i, jj = j;
    while (ii <= j && s[ii] == s[i]) ii++;
    if (ii > j) {
      long long tmp = ((long long)m * (long long)(j - i + 1)) % (long long)k;
      rem += tmp;
      if (tmp == 0) {
        for (int t = j + 1; j < n; j++) {
          s[t - (j + 1) + i] = s[t];
        }
        rem = compress(n - (j - i + 1));
      }
      cout << rem;
      return 0;
    }
    while (s[jj] == s[j]) jj--;
    int tmp = ii - i + j - jj;
    if (tmp % k == 0) {
      rem += tmp;
      i = ii;
      j = jj;
    } else {
      rem += tmp;
      rem += (long long)(tmp % k) * ((long long)(m - 1));
      rem += (long long)(jj - ii + 1) * (long long)m;
      cout << rem;
      return 0;
    }
  }
}
