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;
long long n, k, m;
pair<long long, long long> a[400001];
long long x, d;
int main(void) {
  scanf("%d %d %d", &n, &k, &m);
  for (register long long i = 0; i < n; ++i) {
    scanf("%d", &x);
    if (!d || a[d - 1].first != x)
      a[d++] = make_pair(x, 1);
    else if (a[d - 1].first == x) {
      ++a[d - 1].second;
      if (a[d - 1].second == k) --d;
    }
  }
  long long j = 0;
  if (m > 1)
    while (j < d && a[j].first == a[d - j - 1].first &&
           a[j].second + a[d - 1 - j].second == k)
      ++j;
  if (j == d)
    puts("0");
  else if (d & 1 && j == d >> 1) {
    long long ln = 0;
    for (register long long i = 0; i < j; ++i)
      ln += a[i].second + a[d - 1 - i].second;
    if (!((a[j].second * 1ll * m) % k)) ln = 0;
    printf("%lld\n", ln + (a[j].second * 1ll * m) % k);
  } else {
    long long ln = 0, xln = 0;
    if (m > 1 && d > 1) {
      j = 0;
      while (j < d && a[j].first == a[d - j - 1].first) {
        ln += a[j].second + a[d - 1 - j].second;
        if (a[j].second + a[d - 1 - j].second == k)
          a[j].second = a[d - 1 - j].second = 0, ++j;
        else {
          ln += ((a[j].second + a[d - 1 - j].second) % k) * (m - 1);
          a[j].second = a[d - 1 - j].second = 0;
          break;
        }
      }
    } else if (m > 1) {
      ln = (a[0].second * m) % k;
      a[0].second = 0;
    }
    for (register long long i = 0; i < d; ++i) xln += a[i].second;
    printf("%lld\n", xln * 1ll * m + ln);
  }
  return 0;
}
