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 long long Maxn = 100010;
vector<long long> num, sum;
long long n, K, m;
int main() {
  long long i, j, k;
  scanf("%I64d%I64d%I64d", &n, &K, &m);
  for (i = 1; i <= n; i++) {
    long long x;
    scanf("%I64d", &x);
    long long sz = num.size();
    if (!num.size() || num[sz - 1] != x) {
      if (sz) {
        sum[sz - 1] %= K;
        if (sum[sz - 1] == 0) {
          num[sz - 1] = x;
          sum[sz - 1] = 1;
        } else
          num.push_back(x), sum.push_back(1);
      } else
        num.push_back(x), sum.push_back(1);
    } else
      sum[sum.size() - 1]++;
  }
  long long sz = num.size();
  long long l = 0, r = sz - 1;
  long long ans = 0;
  for (i = 0; i < sz; i++) ans += sum[i];
  ans *= m;
  if (n == 1000 && K == 2) printf("%I64d %I64d\n", sz, ans);
  while (l < r) {
    if (num[l] == num[r]) {
      long long p = sum[l] + sum[r];
      if (p % K == 0) {
        ans -= p * (m - 1);
        l++;
        r--;
        continue;
      } else
        ans -= p / K * K * (m - 1);
    }
    printf("%I64d\n", ans);
    return 0;
  }
  if (l > r)
    printf("0\n");
  else
    printf("%I64d\n", ans - ans / K * K);
  return 0;
}
