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, M, K;
vector<pair<long long, long long> > v;
void vpush(pair<long long, long long> &p) {
  p.second %= K;
  if (p.second == 0) return;
  if (!v.empty() && v.back().first == p.first) {
    v.back().second = (p.second + v.back().second) % K;
    if (v.back().second == 0) v.pop_back();
  } else {
    v.push_back(p);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K >> M;
  pair<long long, long long> cur = {-1, 0};
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (cur.first != x) {
      vpush(cur);
      cur.first = x;
      cur.second = 1;
    } else {
      cur.second++;
    }
  }
  vpush(cur);
  long long sum = 0;
  for (auto &x : v) {
    sum += x.second;
  }
  if (M == 1) {
    cout << sum << '\n';
    return 0;
  }
  long long l = 0, r = v.size() - 1, del = 0;
  while (l < r) {
    long long tot = v[l].second + v[r].second;
    if (v[l].first != v[r].first || tot < K) break;
    del += tot / K * K;
    tot %= K;
    if (tot == 0)
      l++;
    else
      v[l].second = tot;
    r--;
  }
  if (l != r) {
    cout << (sum - del) * M + del << '\n';
  } else {
    long long rem = v[l].second;
    if (rem * M % K != 0) {
      cout << rem * M % K + del << '\n';
    } else {
      cout << 0 << '\n';
    }
  }
}
