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;
void run();
int main() {
  ios::sync_with_stdio(false);
  run();
}
deque<pair<long long, long long>> a;
long long n, k, m;
void prepend(deque<pair<long long, long long>> &x, pair<int, int> p) {
  if (x.empty() or x.front().first != p.first) {
    x.push_front(p);
  } else {
    x.front().second += p.second;
  }
  while (not x.empty() and (x.front().second %= k) == 0) {
    x.pop_front();
  }
}
void append(deque<pair<long long, long long>> &x, pair<int, int> p) {
  if (x.empty() or x.back().first != p.first) {
    x.push_back(p);
  } else {
    x.back().second += p.second;
  }
  while (not x.empty() and (x.back().second %= k) == 0) {
    x.pop_back();
  }
}
void run() {
  cin >> n >> k >> m;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    append(a, {x, 1});
  }
  auto pre = a;
  auto mid = a;
  auto aft = a;
  while (true) {
    if (mid.size() >= 2 and mid.front().first == mid.back().first) {
      long long tot = (mid.front().second + mid.back().second);
      long long rem = tot % k;
      pair<int, int> p = mid.front();
      if (rem == 0) {
        pre.pop_back();
        aft.pop_front();
        mid.pop_front();
        mid.pop_back();
      } else {
        pre.pop_back();
        append(pre, {p.first, rem});
        mid.pop_front();
        append(mid, p);
        aft.pop_front();
      }
    } else if (mid.size() == 1) {
      mid.front().second *= (m - 2);
      append(pre, mid.front());
      mid.clear();
      for (auto i : aft) append(pre, i);
      aft.clear();
    } else {
      break;
    }
  }
  long long res = 0;
  for (auto i : pre) res += i.second;
  for (auto i : mid) res += i.second * (m - 2);
  for (auto i : aft) res += i.second;
  cout << res << endl;
}
