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 <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &p) {
  return out << "(" << p.first << ", " << p.second << ")";
}
template <class A>
ostream &operator<<(ostream &out, const vector<A> &v) {
  out << "[";
  for (int i = int(0); i < int(int(v.size())); i++) {
    if (i > 0) out << ", ";
    out << v[i];
  }
  return out << "]";
}
inline int gett() { return clock() * 1000 / CLOCKS_PER_SEC; }
const long double EPS = 1e-9;
const int INF = int(1e9);
const long long INF64 = long long(INF) * INF;
const long double PI = 3.1415926535897932384626433832795;
const int N = 1000 * 1000 + 555;
int n, k, m, a[N];
inline bool read() {
  if (!(cin >> n >> k >> m)) return false;
  for (int i = int(0); i < int(n); i++) assert(scanf("%d", &a[i]) == 1);
  return true;
}
inline vector<pair<int, int> > getV(int a[N], int n) {
  vector<pair<int, int> > ans;
  int u = 0;
  while (u < n) {
    int v = u;
    while (v < n && a[v] == a[u]) v++;
    ans.push_back(make_pair(a[u], v - u));
    u = v;
  }
  return ans;
}
inline vector<pair<int, int> > shrink(const vector<pair<int, int> > &v) {
  vector<pair<int, int> > nv;
  for (int i = int(0); i < int(int(v.size())); i++) {
    int ost = v[i].second % k;
    while (int(nv.size()) > 0 && nv.back().first == v[i].first) {
      ost = (ost + nv.back().second) % k;
      nv.pop_back();
    }
    if (ost > 0) nv.push_back(make_pair(v[i].first, ost));
  }
  return nv;
}
inline void solve() {
  if (n == 1) {
    cout << (n * 1ll * m) % k << endl;
    return;
  }
  if (k >= n) {
    bool sm = 1;
    for (int i = int(0); i < int(n - 1); i++)
      if (a[i] != a[i + 1]) sm = 0;
    if (sm) {
      cout << (n * 1ll * m) % k << endl;
    } else {
      cout << (n * 1ll * m) << endl;
    }
  } else {
    if (m <= 3) {
      int sz = 0;
      for (int _i = int(0); _i < int(m); _i++)
        for (int i = int(0); i < int(n); i++) a[sz++] = a[i];
      assert(sz == n * m);
      n = sz, m = 1;
      vector<pair<int, int> > v = getV(a, n);
      vector<pair<int, int> > nv = shrink(v);
      int len = 0;
      for (int i = int(0); i < int(int(nv.size())); i++) len += nv[i].second;
      cout << len << endl;
    } else {
      vector<pair<int, int> > v = getV(a, n);
      v = shrink(v);
      list<pair<int, int> > cv((v).begin(), (v).end());
      vector<pair<int, int> > subl, subr;
      while (int(cv.size()) > 1) {
        auto lf = cv.begin();
        auto rg = --cv.end();
        if (lf->first != rg->first) break;
        long long ost = (lf->second + rg->second) % k;
        if (ost > 0) {
          if (lf->second > ost)
            subl.push_back(make_pair(lf->first, lf->second - ost));
          subr.push_back(*rg);
          lf->second = ost;
          cv.erase(rg);
        } else {
          subl.push_back(*lf);
          subr.push_back(*rg);
          cv.erase(lf);
          cv.erase(rg);
        }
      }
      reverse((subr).begin(), (subr).end());
      if (int(cv.size()) <= 1) {
        long long len = int(cv.size()) > 0 ? cv.begin()->second : 0;
        len = (len * 1ll * m) % k;
        if (len == 0) {
          vector<pair<int, int> > cur(subl);
          cur.insert(cur.end(), (subr).begin(), (subr).end());
          vector<pair<int, int> > nv = shrink(cur);
          int len = 0;
          for (int i = int(0); i < int(int(nv.size())); i++)
            len += nv[i].second;
          cout << len << endl;
        } else {
          int ll = 0, lr = 0;
          for (int i = int(0); i < int(int(subl.size())); i++)
            ll += subl[i].second;
          for (int i = int(0); i < int(int(subr.size())); i++)
            lr += subr[i].second;
          cout << ll + len + lr << endl;
        }
      } else {
        int ll = 0, lr = 0;
        for (int i = int(0); i < int(int(subl.size())); i++)
          ll += subl[i].second;
        for (int i = int(0); i < int(int(subr.size())); i++)
          lr += subr[i].second;
        long long len = 0;
        for (auto p : cv) len += p.second;
        cout << ll + len * 1ll * m + lr << endl;
      }
    }
  }
}
int main() {
  srand(time(NULL));
  cout << fixed << setprecision(10);
  while (read()) {
    solve();
  }
  return 0;
}
