#include <bits/stdc++.h>
using namespace std;
void draganov_style() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
}
const int NMAX = 2e5 + 4;
long long N, n, m, k, cnt, ans, l[NMAX], c[NMAX], r[NMAX], tmp[NMAX];
void calc() {
  cnt = 0;
  stack<pair<int, int> > kstack;
  for (int i = 0; i < n; i++) {
    if (kstack.empty()) {
      kstack.push(make_pair(l[i], 1));
    } else {
      pair<int, int> up = kstack.top();
      if (l[i] == up.first && up.second + 1 < k) {
        kstack.pop();
        kstack.push(make_pair(up.first, up.second + 1));
      } else if (l[i] == up.first && up.second + 1 == k) {
        kstack.pop();
      } else {
        kstack.push(make_pair(l[i], 1));
      }
    }
  }
  while (!kstack.empty()) {
    pair<int, int> up = kstack.top();
    for (int j = 0; j < up.second; j++) {
      tmp[cnt++] = up.first;
    }
    kstack.pop();
  }
  for (int i = 0; i < cnt; i++) {
    l[i] = r[i] = c[i] = tmp[cnt - 1 - i];
  }
  n = cnt;
}
void sumArr(int l1, int r1, int l2, int r2) {
  cnt = 0;
  for (int i = l1; i < r1; i++) tmp[cnt++] = l[i];
  for (int i = l2; i < r2; i++) tmp[cnt++] = r[i];
  for (int i = 0; i < cnt; i++) l[i] = tmp[i];
  n = cnt;
}
int brute() {
  vector<int> li;
  int res = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      li.push_back(l[j]);
    }
  }
  stack<pair<int, int> > kstack;
  for (int i = 0; i < n * m; i++) {
    if (kstack.empty()) {
      kstack.push(make_pair(li[i], 1));
    } else {
      pair<int, int> up = kstack.top();
      if (li[i] == up.first && up.second + 1 < k) {
        kstack.pop();
        kstack.push(make_pair(up.first, up.second + 1));
      } else if (li[i] == up.first && up.second + 1 == k) {
        kstack.pop();
      } else {
        kstack.push(make_pair(li[i], 1));
      }
    }
  }
  while (!kstack.empty()) {
    pair<int, int> up = kstack.top();
    res += up.second;
    kstack.pop();
  }
  return res;
}
int main() {
  draganov_style();
  cin >> n >> k >> m;
  for (int i = 0; i < n; i++) {
    cin >> l[i];
  }
  calc();
  if (m == 1 || !cnt) {
    cout << cnt;
    return 0;
  }
  if (m == 2) {
    for (int j = 0; j < n; j++) {
      l[n + j] = l[j];
    }
    n *= 2;
    calc();
    cout << n;
    return 0;
  }
  long long lc = 0, rc = n - 1, fl = 0;
  while (true) {
    int ltmp = lc, rtmp = rc, ktmp = 0;
    if (c[ltmp] != c[rtmp]) break;
    while (ktmp != k && ltmp <= rtmp && c[ltmp] == c[rc]) {
      ltmp++;
      ktmp++;
    }
    if (ltmp == rc + 1) {
      fl = 1;
      break;
    }
    while (ktmp != k && rtmp >= ltmp && c[rtmp] == c[lc]) {
      rtmp--;
      ktmp++;
    }
    if (ktmp < k) break;
    rc = rtmp;
    lc = ltmp;
  }
  long long EL = 0, el = c[lc];
  long long ls = lc, rs = rc;
  if (fl) {
    while (rs >= 0 && c[rs] == el) rs--, EL++;
    while (ls < n && c[ls] == el) ls++, EL++;
  }
  if (fl) {
    N = n;
    sumArr(0, lc, rc + 1, n);
    ans = (rc - lc + 1LL) * (m - 2) + EL;
    ans %= k;
    calc();
    if (!ans)
      ans += n;
    else if (rs && lc)
      ans += (N - ls) + (rs + 1);
  } else {
    ans = (n - lc) + (rc + 1) + (m - 2LL) * (rc - lc + 1);
  }
  cout << ans;
  return 0;
}
