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 n, k, m;
int a[100000 + 10], f[100000 + 10];
int main() {
  cin >> n >> k >> m;
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int new_n = 0;
  for (int i = 0; i < n; i++) {
    if (new_n != 0 && a[i] == a[new_n - 1])
      f[i] = f[new_n - 1] + 1;
    else
      f[i] = 1;
    if (f[i] == k) {
      new_n -= k - 1;
    } else
      a[new_n++] = a[i];
  }
  n = new_n;
  if (n == 0 || m == 1) {
    cout << n << endl;
    return 0;
  }
  vector<pair<int, int> > g;
  for (int i = 0; i < n; i++)
    if (g.size() == 0 || g.back().first != a[i])
      g.push_back(make_pair(a[i], 1));
    else
      g.back().second++;
  int i = 0, j = g.size();
  j--;
  int ans = n;
  while (i < j) {
    if (g[i].first == g[j].first && g[i].second + g[j].second == k) {
      i++;
      j--;
      ans -= k;
      continue;
    }
    cout << ((long long)n) * m - ((long long)k) * (m - 1) * i << endl;
    return 0;
  }
  if (i > j)
    cout << 0 << endl;
  else {
    cout << ((long long)m) * g[i].second % k << endl;
  }
  return 0;
}
