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 main() {
  int n, k, m;
  long long temp = 0;
  scanf("%d%d%d", &n, &k, &m);
  deque<pair<int, int>> q;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    temp++;
    if (q.empty() || q.back().first != a)
      q.push_back({a, 1});
    else
      q.back().second++;
    if (q.back().second == k) temp -= q.back().second, q.pop_back();
  }
  long long ans = temp * m;
  temp = 0;
  while (q.size() > 1) {
    if (q.front().first == q.back().first) {
      int x = q.front().second + q.back().second;
      int y = q.front().first;
      q.pop_back();
      q.pop_front();
      if (x == k)
        ans -= (m - 1LL) * x, temp += k;
      else {
        if (x > k) ans -= (m - 1LL) * k;
        break;
      }
    } else
      break;
  }
  if (q.size() == 1)
    ans = q.front().second * 1LL * m % k +
          (q.front().second * 1LL * m % k ? temp : 0);
  printf("%lld\n", ans);
}
