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, tot;
vector<pair<long long, long long> > v;
int main() {
  long long i, j;
  scanf("%lld", &n);
  scanf("%lld", &k);
  scanf("%lld", &m);
  stack<pair<long long, long long> > stk;
  for (i = 1; i <= n; i++) {
    long long x;
    scanf("%lld", &x);
    if (stk.size() && stk.top().first == x) {
      pair<long long, long long> p = stk.top();
      stk.pop();
      if (p.second + 1 == k) continue;
      p.second++;
      stk.push(p);
    } else
      stk.push({x, 1});
  }
  long long sum = 0;
  while (stk.size()) {
    sum += stk.top().second;
    v.push_back(stk.top());
    stk.pop();
  }
  if (n == 1) return cout << (sum * m) % k << endl, 0;
  reverse(v.begin(), v.end());
  int sz = v.size();
  for (i = 0; i < sz; i++) {
    j = sz - i - 1;
    if (v[i].first == v[j].first && v[i].second + v[j].second == k)
      continue;
    else
      break;
  }
  if (i == v.size()) {
    printf("%lld\n", m % 2 ? sum : 0);
    return 0;
  }
  j = sz - i - 1;
  if (v[i].first != v[j].first) {
    long long cnt = 0, cc = 0;
    for (int xx = i; xx <= j; xx++) cnt += v[xx].second;
    for (int xx = 0; xx <= j; xx++) cc += v[xx].second;
    for (int xx = i; xx < sz; xx++) cc += v[xx].second;
    long long ans = cc + (m - 2) * cnt;
    return cout << ans << endl, 0;
  }
  if (i == j) {
    long long tot = v[i].second * m;
    if (tot % k == 0)
      return cout << 0 << endl, 0;
    else {
      long long cnt = 0, cc = 0;
      for (int xx = 0; xx < i; xx++) cc += v[xx].second;
      for (int xx = i + 1; xx < sz; xx++) cc += v[xx].second;
      return cout << cc + (tot % k) << endl, 0;
    }
  }
  long long cc = 0, cnt = 0;
  for (int xx = i + 1; xx < j; xx++) cnt += v[xx].second;
  for (int xx = 0; xx < j; xx++) cc += v[xx].second;
  for (int xx = i + 1; xx < sz; xx++) cc += v[xx].second;
  long long ans =
      cc + ((v[i].second + v[j].second) % k) * (m - 1) + cnt * (m - 2);
  cout << ans << endl;
  return 0;
}
