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;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T amax(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
const long long N = 0;
void solve() {
  long long n, k, m;
  cin >> n >> k >> m;
  vector<pair<long long, long long> > v;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    if (v.empty() || x != v.back().second) {
      v.push_back({1, x});
    } else {
      v.back().first++;
    }
    if (v.back().first == k) v.pop_back();
  }
  if (m < 3) {
    vector<pair<long long, long long> > z;
    for (long long i = 0; i < m; i++) {
      for (auto x : v) {
        z.push_back(x);
      }
    }
    vector<pair<long long, long long> > p;
    for (auto x : z) {
      if (p.empty() || p.back().second != x.second) {
        p.push_back(x);
      } else {
        x.first += p.back().first;
        p.pop_back();
        if (x.first >= k) x.first -= k;
        if (x.first) {
          p.push_back(x);
        }
      }
    }
    long long ans = 0;
    for (auto x : p) ans += x.first;
    cout << ans;
    return;
  }
  long long ans = 0;
  for (auto x : v) ans += x.first;
  ans *= 2;
  deque<pair<long long, long long> > mid((v).begin(), (v).end());
  while ((long long)((mid).size()) > 1 &&
         mid.front().second == mid.back().second &&
         mid.front().first + mid.back().first >= k) {
    long long val = mid.front().second;
    long long tmp = mid.front().first + mid.back().first;
    ans -= mid.front().first;
    mid.pop_front();
    ans -= mid.back().first;
    mid.pop_back();
    tmp -= k;
    if (tmp) {
      mid.push_back({tmp, val});
    }
  }
  if ((long long)((mid).size()) == 1) {
    long long tmp = m * mid.front().first;
    ans -= 2 * mid.front().first;
    tmp %= k;
    if (tmp == 0) {
      cout << 0;
    } else {
      cout << ans + tmp;
    }
    return;
  }
  if ((long long)((mid).size()) == 0) {
    cout << 0;
    return;
  }
  long long tmp = 0;
  for (auto x : mid) tmp += x.first;
  cout << ans + tmp * (m - 2);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
