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, x;
int main() {
  cin >> n >> k >> m;
  vector<pair<long long, long long> > v;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> x;
    if (v.empty() || v.back().first != x) {
      v.push_back({x, 1});
    } else {
      v.back().second++;
      if (v.back().second == k) v.pop_back();
    }
  }
  for (auto it : v) ans += it.second;
  long long sz = v.size();
  long long i, aux = 0;
  for (i = 0; i < sz - i - 1; i++) {
    if (i >= sz - i - 1) break;
    if (v[i].first == v[sz - i - 1].first &&
        v[i].second + v[sz - i - 1].second == k)
      aux += k;
    else
      break;
  }
  if (i < sz - i - 1) {
    if (v[i].first == v[sz - i - 1].first &&
        v[i].second + v[sz - i - 1].second > k)
      aux += k;
    ans = 1ll * m * ans - (m - 1ll) * aux;
  } else {
    aux = 1ll * v[i].second * m % k;
    if (aux) {
      ans -= v[i].second;
      ans += aux;
    } else
      ans = 0;
  }
  cout << ans;
  return 0;
}
