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 T>
void mini(T &l, T r) {
  l = min(l, r);
}
template <class T>
void maxi(T &l, T r) {
  l = max(l, r);
}
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
using llint = long long;
const int N = 1e5 + 10;
int a[N * 4];
int n, k, m;
llint mrg(int *a, int n) {
  vector<pair<int, int> > v;
  llint ret = 0;
  for (int i = 0; i < n; ++i) {
    if (v.empty() || v.back().first != a[i]) {
      v.push_back(make_pair(a[i], 1));
    } else {
      v.back().second++;
    }
    while (!v.empty() && v.back().second == k) {
      v.pop_back();
      ret += k;
    }
  }
  return n - ret;
}
llint go(int *a, int n) {
  if (n == 0) return 0;
  int hd = n;
  int tl = n;
  for (int i = 0; i < n; ++i) {
    if (a[i] == a[n - 1]) {
      a[tl++] = a[i];
    } else {
      hd = i;
      break;
    }
  }
  int cnt = 0;
  llint del = 0;
  llint ret = 0;
  for (int i = tl - 1; i >= hd; --i) {
    if (a[i] == a[tl - 1]) {
      ++cnt;
    } else {
      break;
    }
  }
  for (int i = 0; i < tl; ++i) 42;
  42;
  if (cnt == n) {
    ret += 1ll * n * m % k;
  } else {
    if (cnt % k == 0) {
      ret += 0;
      llint tmp = go(a + hd, n - cnt);
      42;
      if (tmp == 0) {
        ret += 1ll * cnt % k;
      } else {
        if (hd > 0)
          ret += 1ll * cnt;
        else
          ret += 1ll * cnt % k;
      }
      ret += tmp;
      42;
    } else {
      llint tmp = mrg(a + hd, n - cnt);
      for (int i = 0; i < tl; ++i) 42;
      42;
      if (tmp == 0) {
        ret += 1ll * cnt * m % k;
      } else {
        ret += 1ll * cnt % k * (m - 1);
        ret += 1ll * cnt;
      }
      ret += 1ll * tmp * m;
    }
  }
  42;
  return ret;
}
void run() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  printf("%lld\n", go(a, n));
}
int main() {
  run();
  return 0;
}
