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 long long mod = 1000000007;
void process(list<int> &a, long long k) {
  auto cur = a.begin();
  while (cur != a.end()) {
    auto fi = cur, se = cur;
    long long cnt = 0;
    while (se != a.end() && *se == *fi) {
      ++se;
      ++cnt;
      if (cnt == k) break;
    }
    if (cnt == k) {
      if (fi != a.begin()) {
        cur = --fi;
        a.erase(++fi, se);
      } else {
        cur = se;
        a.erase(fi, se);
      }
    } else
      cur = se;
  }
}
int main() {
  long long n, k, m;
  cin >> n >> k >> m;
  list<int> a;
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  if (k >= n) {
    int fi = *(a.begin());
    for (auto it = a.begin(); it != a.end(); ++it) {
      if (*it != fi) {
        cout << n * m << endl;
        return 0;
      }
    }
    cout << n * m % k << endl;
    return 0;
  }
  process(a, k);
  if (a.empty()) {
    cout << 0 << endl;
    return 0;
  }
  list<int> origin = a;
  int colorCnt = 0, prev = 0, fr = 0, ba = 0;
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (prev != *it) ++colorCnt;
    prev = *it;
  }
  while (colorCnt > 2) {
    int tfr = 0, tba = 0, nfi = *(a.begin()), nse = *(--a.end());
    if (nfi != nse) break;
    auto fi = a.begin(), se = --a.end();
    while (*fi == nfi) {
      ++fi;
      ++tfr;
    }
    while (*se == nse) {
      --se;
      ++tba;
      if (tfr + tba == k) break;
    }
    if (tfr + tba == k) {
      if (*se == nse)
        --colorCnt;
      else
        colorCnt -= 2;
      a.erase(a.begin(), fi);
      a.erase(++se, a.end());
      fr += tfr;
      ba += tba;
    } else
      break;
  }
  if (colorCnt >= 2) {
    long long res = a.size(), extra = fr + ba;
    res *= m;
    cout << res + extra << endl;
    return 0;
  }
  list<int> b;
  auto it = origin.begin();
  for (int i = 0; i < fr; ++i, ++it) b.push_back(*it);
  for (int i = 0; i < ((long long)a.size()) * m % k; ++i)
    b.push_back(*(a.begin()));
  it = origin.end();
  for (int i = 0; i < ba; ++i) --it;
  for (; it != origin.end(); ++it) b.push_back(*it);
  process(b, k);
  cout << b.size() << endl;
  return 0;
}
