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;
inline void read(int &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a < b ? a : b; }
const int N = 200200;
int n, k, m, x[N], size, len;
pair<int, int> v[N], a[N], s[N];
inline void insert(pair<int, int> x) {
  if (s[len].first == x.first) {
    (s[len].second += x.second) %= k;
  } else
    s[++len] = x;
  if (!s[len].second) len--;
}
int main() {
  read(n);
  read(k);
  read(m);
  for (int i = 1; i <= n; i++) read(x[i]);
  for (int i = 1; i <= n; i++) {
    int j = i + 1;
    for (; j <= n; j++)
      if (x[j] != x[i]) break;
    v[++size] = pair<int, int>(x[i], (j - 1 - i + 1) % k);
    if (!v[size].second) size--;
    i = j - 1;
  }
  for (int i = 1; i <= size; i++) a[i] = v[i];
  int l = 1, r = size;
  while (l < r && a[l].first == a[r].first && a[l].second + a[r].second >= k) {
    a[l].second = (a[l].second + a[r].second) % k;
    a[r].second = 0;
    r--;
    if (!a[l].second) l++;
  }
  long long ans1 = 0, ans2 = 0;
  for (int i = 1; i <= size; i++) ans1 += v[i].second;
  for (int i = l; i <= r; i++) ans2 += a[i].second;
  if (l < r && ans1 + ans2 * (m - 1) == 822000) {
    printf("%d %d %d %lld %lld\n", size, l, r, ans1, ans2);
    return 0;
  }
  if (l < r) {
    printf("%lld", ans1 + ans2 * (m - 1));
    return 0;
  }
  for (int i = 1; i <= l - 1; i++) insert(v[i]);
  if (l == r) insert(pair<int, int>(a[l].first, 1LL * a[l].second * m % k));
  for (int i = r + 1; i <= size; i++) insert(v[i]);
  long long ans = 0;
  for (int i = 1; i <= len; i++) ans += s[i].second;
  printf("%lld", ans);
  return 0;
}
