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 main() {
  long long n, k, m;
  scanf("%lld %lld %lld", &n, &k, &m);
  vector<pair<int, long long> > b;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (b.size() && b.back().first == x) {
      if (++b.back().second == k) b.pop_back();
    } else
      b.push_back({x, 1});
  }
  if (m == 1) {
    long long ans = 0;
    for (int i = 0; i < b.size(); i++) ans += b[i].second;
    printf("%lld\n", ans);
    return 0;
  }
  deque<pair<int, long long> > mid;
  for (int i = 0; i < b.size(); i++) mid.push_back(b[i]);
  for (; mid.size() >= 2;) {
    if (mid.front().first == mid.back().first) {
      if (mid.front().second + mid.back().second == k) {
        mid.pop_front();
        mid.pop_back();
      } else {
        if (mid.front().second + mid.back().second > k) {
          mid.back().second = mid.front().second + mid.back().second - k;
          mid.pop_front();
        }
        break;
      }
    } else
      break;
  }
  if (m == 2) {
    long long ans = 0;
    for (int i = 0; i < b.size(); i++) ans += b[i].second;
    for (; !mid.empty(); mid.pop_back()) ans += mid.back().second;
    printf("%lld\n", ans);
    return 0;
  }
  if (mid.size() == 1) {
    mid.back().second = mid.back().second * m % k;
    m = 3;
    if (mid.back().second == 0) {
      b[b.size() / 2].second = 0;
      for (int i = b.size() / 2 - 1, j = i + 2; i >= 0 & j < b.size(); i--, j++)
        if (b[i].first == b[j].first) {
          if (b[i].second + b[j].second == k)
            b[i].second = b[j].second = 0;
          else {
            if (b[i].second + b[j].second > k) {
              b[i].second = b[i].second + b[j].second - k;
              b[j].second = 0;
            }
            break;
          }
        } else
          break;
      long long ans = 0;
      for (int i = 0; i < b.size(); i++) ans += b[i].second;
      printf("%lld\n", ans);
      return 0;
    }
    long long ans = mid.back().second - b[b.size() / 2].second;
    for (int i = 0; i < b.size(); i++) ans += b[i].second;
    printf("%lld\n", ans);
    return 0;
  }
  long long ans = 0;
  for (; !mid.empty(); mid.pop_back()) ans += mid.back().second;
  ans *= (m - 1);
  for (int i = 0; i < b.size(); i++) ans += b[i].second;
  printf("%lld\n", ans);
  return 0;
}
