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;
struct Dv {
  long long left;
  long long right;
  long long prev;
  bool def;
};
vector<long long> solve(vector<long long> data, long long &del, long long m,
                        long long k, long long n) {
  vector<Dv> g;
  for (long long i = 0; i < n; i++) {
    Dv dv = {i - 1, i + 1, 0, false};
    g.push_back(dv);
  }
  for (long long i = 0; i < n; i++) {
    long long PREV;
    if (g[i].left < 0) {
      PREV = 1;
    } else {
      PREV = g[g[i].left].prev * (data[g[i].left] == data[i]) + 1;
    }
    g[i].prev = PREV;
    long long R = g[i].right;
    if (PREV >= k) {
      g[i].def = true;
      del += k * m;
      long long now = g[i].left;
      for (long long j = 0; j < k - 1; j++) {
        g[now].def = true;
        now = g[now].left;
      }
      if (R < n) g[R].left = now;
      if (now >= 0) g[now].right = R;
    } else if (R < n)
      g[R].left = i;
  }
  vector<long long> ret;
  long long ind = -1;
  for (long long i = 0; i < n; i++) {
    if (!g[i].def) {
      ind = i;
      break;
    }
  }
  if (ind == -1) return ret;
  while (ind < n) {
    ret.push_back(data[ind]);
    ind = g[ind].right;
  }
  return ret;
}
int32_t main() {
  long long n, k, m;
  cin >> n >> k >> m;
  vector<long long> data(n);
  for (long long i = 0; i < n; i++) cin >> data[i];
  bool both = true;
  for (long long i = 1; i < n; i++) {
    both &= (data[i] == data[i - 1]);
  }
  if (both) {
    cout << (n * m) % k << endl;
    return 0;
  }
  long long del = 0;
  long long N = data.size();
  data = solve(data, del, m, k, n);
  n = data.size();
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (m == 1) {
    cout << N - del << endl;
    return 0;
  }
  vector<long long> prev(n), next(n);
  next[n - 1] = 1;
  for (long long i = n - 2; i >= 0; i--)
    next[i] = (data[i] == data[i + 1]) * next[i + 1] + 1;
  prev[0] = 1;
  for (long long i = 1; i < n; i++)
    prev[i] = (data[i] == data[i - 1]) * prev[i - 1] + 1;
  long long L = 0, R = n - 1;
  vector<long long> lk, rk;
  bool prod = false;
  while (true) {
    if (next[L] == R - L + 1) {
      long long ost = m * (R - L + 1);
      long long och = ost % k;
      del += ost - och;
      if (och == 0) {
        prod = true;
      }
      break;
    }
    if (data[L] != data[R]) break;
    long long vm = next[L] + prev[R];
    if (vm < k) {
      cout << N * m - del << endl;
      return 0;
    }
    long long OL = L;
    long long P = next[L];
    L += min(k, P);
    for (long long j = OL; j < L; j++) {
      lk.push_back(data[j]);
    }
    long long OR = R;
    if (k > P) {
      R -= k - P;
    }
    for (long long j = OR; j > R; j--) rk.push_back(data[j]);
    del += k * (m - 1);
  }
  if (prod) {
    if (lk.size() == 0 || rk.size() == 0) {
      cout << N * m - del << endl;
      return 0;
    }
    vector<long long> rrk;
    for (long long j = rk.size() - 1; j >= 0; j--) rrk.push_back(rk[j]);
    rk = rrk;
    long long PREV[lk.size()], NEXT[rk.size()];
    NEXT[rk.size() - 1] = 1;
    long long SZ = rk.size();
    for (long long i = SZ - 2; i >= 0; i--)
      NEXT[i] = (rk[i] == rk[i + 1]) * NEXT[i + 1] + 1;
    PREV[0] = 1;
    for (long long i = 1; i < lk.size(); i++)
      PREV[i] = (lk[i] == lk[i - 1]) * PREV[i - 1] + 1;
    long long RR = lk.size() - 1;
    long long LL = 0;
    while (LL < rk.size() && RR >= 0) {
      if (lk[RR] != rk[LL]) break;
      long long SUM = PREV[RR] + NEXT[LL];
      if (SUM < k) break;
      long long ORR = RR;
      RR -= min(PREV[ORR], k);
      if (k > PREV[ORR]) {
        LL += k - PREV[ORR];
      }
      del += k;
    }
  }
  cout << N * m - del << endl;
  return 0;
}
