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 N = 2 * 1e5;
vector<long long> a;
long long num[N], n, k, m, val;
int main() {
  cin >> n >> k >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> val;
    if (a.size() && a.back() == val) {
      ++num[a.size() - 1];
      if (num[a.size() - 1] == k) a.pop_back();
    } else {
      num[a.size()] = 1;
      a.push_back(val);
    }
  }
  long long x = 0, y = a.size() - 1, b = 0;
  for (int i = 0; i < a.size(); ++i) b += num[i];
  if (m == 1) {
    cout << b;
    return 0;
  }
  int tmp = b;
  while (x < y) {
    if (a[x] != a[y]) break;
    if (num[x] + num[y] == k) {
      b -= k;
      ++x;
      --y;
      continue;
    }
    if (num[x] + num[y] > k) b -= k;
    break;
  }
  long long ans = m * b;
  tmp -= b;
  if (x == y) {
    if (ans % k == 0) tmp = 0;
    ans = ans % k;
  }
  cout << ans + tmp;
  return 0;
}
