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;
void doRoutine() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void process(vector<int64_t> &a, int64_t k) {
  int64_t n = a.size();
  vector<pair<int64_t, int64_t> > pcs;
  for (int64_t i = 0; i < n; ++i) {
    if (pcs.empty() || pcs.back().second != a[i]) {
      pcs.push_back({1, a[i]});
    } else {
      ++pcs.back().first;
      if (pcs.back().first == k) {
        pcs.pop_back();
      }
    }
  }
  vector<int64_t> res;
  for (auto pr : pcs) {
    for (int64_t i = 0; i < pr.first; ++i) {
      res.push_back(pr.second);
    }
  }
  a = res;
}
signed main() {
  doRoutine();
  int64_t n, k, m;
  cin >> n >> k >> m;
  vector<int64_t> a(n);
  for (int64_t i = 0; i < n; ++i) {
    cin >> a[i];
  }
  process(a, k);
  n = a.size();
  if (m <= 2) {
    vector<int64_t> b;
    for (int64_t j = 0; j < m; ++j) {
      for (int64_t i = 0; i < n; ++i) {
        b.push_back(a[i]);
      }
    }
    process(b, k);
    cout << (int64_t)b.size() << endl;
  } else {
    int64_t ans = m * n;
    int64_t i = 0, j = n - 1;
    while (j - i + 1 >= k) {
      if (a[i] != a[j]) {
        cout << ans << endl;
        return 0;
      }
      int64_t pi = i, pj = j;
      while (a[i + 1] == a[i]) {
        ++i;
      }
      while (pj - j + 1 + i - pi + 1 < k && a[j - 1] == a[j]) {
        --j;
      }
      if (pj - j + 1 + i - pi + 1 == k) {
        ans -= k * (m - 1);
      } else {
        cout << ans << endl;
        return 0;
      }
      ++i;
      --j;
    }
    bool is_eq = true;
    for (int64_t t = i; t < j; ++t) {
      if (a[t] != a[t + 1]) {
        is_eq = false;
      }
    }
    if (is_eq) {
      int64_t sum = 0;
      int64_t t = j;
      while (t >= 0 && a[t] == a[j]) {
        --t;
      }
      sum += j - t;
      int64_t right = t;
      t = i;
      while (t < n && a[t] == a[i]) {
        ++t;
      }
      sum += t - i;
      int64_t left = t;
      sum += (m - 2) * (j - i + 1);
      ans -= (sum / k) * k;
      if (sum % k == 0) {
        vector<int64_t> rest;
        for (int64_t t = 0; t <= right; ++t) {
          rest.push_back(a[t]);
        }
        for (int64_t t = left; t < n; ++t) {
          rest.push_back(a[t]);
        }
        process(rest, k);
        cout << rest.size() << endl;
        return 0;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
