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 double EPS = 1e-8;
const double Pi = acos(-1);
bool inline equ(double a, double b) { return fabs(a - b) < EPS; }
int _R(int& x) { return scanf("%d", &x); }
int _R(long long& x) { return scanf("%" PRId64, &x); }
int _R(double& x) { return scanf("%lf", &x); }
int _R(char* s) { return scanf("%s", s); }
int R() { return 0; }
template <typename T1, typename... T2>
int R(T1& x, T2&... tail) {
  int tmp = _R(x);
  return tmp + R(tail...);
}
template <typename Iter, typename F>
inline void out(Iter s, Iter e, F of) {
  bool flag = 0;
  for (Iter it = s; it != e; it++) {
    if (flag)
      printf(" ");
    else
      flag = 1;
    of(*it);
  }
  puts("");
}
const int N = 1e5 + 10;
int n;
long long k, m;
vector<pair<int, int> > reduce(vector<int>& vec) {
  vector<pair<int, int> > res;
  int j = 0;
  for (int i = 0; i < ((int)(vec).size()); i++) {
    j = i + 1;
    while (j < (int)(vec).size() and vec[i] == vec[j]) ++j;
    long long rem = j - i;
    while ((int)(res).size() and res.back().first == vec[i]) {
      rem += res.back().second;
      res.pop_back();
    }
    rem %= k;
    if (rem) {
      res.push_back({vec[i], rem});
    }
    i = j - 1;
  }
  return res;
}
int main() {
  R(n, k, m);
  long long ans = 0;
  vector<int> a;
  for (int i = (0); i <= (n - 1); i++) {
    int x;
    R(x);
    a.push_back(x);
  }
  vector<pair<int, int> > vec = reduce(a);
  if ((int)(vec).size() == 1) {
    ans = (m * vec[0].second) % k;
    cout << ans << endl;
    return 0;
  }
  if ((int)(vec).size() == 0) {
    cout << "0\n";
    return 0;
  }
  if (m == 1) {
    ans = 0;
    for (pair<int, int> p : vec) ans += p.second;
    cout << ans << endl;
    return 0;
  }
  int r = (int)(vec).size() - 1;
  for (int l = 0; l < ((int)(vec).size()); l++) {
    if (vec[l].first != vec[r].first) {
      ans = 0;
      for (pair<int, int> p : vec) ans += p.second;
      for (int i = (l); i <= (r); i++) ans += (m - 1) * vec[i].second;
      cout << ans << endl;
      return 0;
    }
    if (l > r) {
      ans = 0;
      cout << ans << endl;
      return 0;
    }
    if (l == r) {
      long long all = m * (vec[l].second);
      all %= k;
      if (all > 0) {
        ans = all % k;
        for (int i = (0); i <= (l - 1); i++) ans += vec[i].second;
        for (int i = (r + 1); i <= ((int)(vec).size() - 1); i++)
          ans += vec[i].second;
        cout << ans << endl;
        return 0;
      } else {
        cout << "0\n";
        return 0;
      }
    }
    long long cnt = vec[l].second + vec[r].second;
    if (cnt % k > 0) {
      ans = (m - 1) * (cnt % k);
      for (int i = (l + 1); i <= (r - 1); i++) ans += (m - 2) * vec[i].second;
      for (int i = (0); i <= (r - 1); i++) ans += vec[i].second;
      for (int i = (l + 1); i <= ((int)(vec).size() - 1); i++)
        ans += vec[i].second;
      cout << ans << endl;
      return 0;
    }
    r--;
  }
}
