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 double pi = acos(-1);
const int N = 1e5 + 5;
int n, m, k, arr[N << 1];
vector<int> v, vv;
set<int> s;
long long tot;
int main() {
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
    arr[i + n] = arr[i];
  }
  int st = 0;
  while (st < n) {
    int f = arr[st];
    int cnt = 0;
    while (v.size() && v.back() == f) {
      ++cnt;
      v.pop_back();
    }
    while (st < n && arr[st] == f) {
      ++st;
      ++cnt;
    }
    cnt %= k;
    while (cnt--) v.push_back(f);
  }
  if (m == 1) {
    cout << v.size() << "\n";
    return 0;
  }
  st = n;
  vv = v;
  while (st < 2 * n) {
    int f = arr[st];
    int cnt = 0;
    while (vv.size() && vv.back() == f) {
      ++cnt;
      vv.pop_back();
    }
    while (st < 2 * n && arr[st] == f) {
      ++st;
      ++cnt;
    }
    cnt %= k;
    while (cnt--) vv.push_back(f);
  }
  if (m == 2) {
    printf("%d\n", vv.size());
    return 0;
  }
  if (v.empty()) {
    puts("0");
    return 0;
  }
  s.clear();
  for (int i : v) s.insert(i);
  tot = 1ll * v.size() * m;
  if (s.size() == 1) {
    cout << tot % k;
    return 0;
  }
  if (k >= v.size()) {
    printf("%lld", tot);
    return 0;
  }
  int ff = v[0];
  long long flag = 0;
  int c = 0, ss = 0, e = v.size();
  ff = v[0];
  while (1) {
    c = 0;
    ff = v[ss];
    int ns = ss;
    int ne = e;
    for (; ns < ne && v[ns] == ff; ns++) ++c;
    for (; ns < ne - 1 && v[ne - 1] == ff; ne--) ++c;
    if (c == k) {
      flag += k;
      ss = ns;
      e = ne;
    } else
      break;
  }
  vector<int> vec = v;
  v.clear();
  for (int i = ss; i < e; i++) v.push_back(vec[i]);
  vec = v;
  st = 0;
  v.clear();
  while (st < vec.size()) {
    int f = vec[st];
    int cnt = 0;
    while (v.size() && v.back() == f) {
      ++cnt;
      v.pop_back();
    }
    while (st < vec.size() && vec[st] == f) {
      ++st;
      ++cnt;
    }
    cnt %= k;
    while (cnt--) v.push_back(f);
  }
  s.clear();
  for (int i : v) s.insert(i);
  if (s.size() == 1) {
    cout << v.size() * 1ll * m % k + flag * (!!(v.size() * 1ll * m % k));
    return 0;
  }
  vv = v;
  st = 0;
  while (st < v.size()) {
    int f = v[st];
    int cnt = 0;
    while (vv.size() && vv.back() == f) {
      ++cnt;
      vv.pop_back();
    }
    while (st < v.size() && v[st] == f) {
      ++st;
      ++cnt;
    }
    cnt %= k;
    while (cnt--) vv.push_back(f);
  }
  vector<int> x = vv;
  vector<int> y = vv;
  st = 0;
  while (st < x.size()) {
    int f = x[st];
    int cnt = 0;
    while (y.size() && y.back() == f) {
      ++cnt;
      y.pop_back();
    }
    while (st < x.size() && x[st] == f) {
      ++st;
      ++cnt;
    }
    cnt %= k;
    while (cnt--) y.push_back(f);
  }
  m -= 2;
  long long ans = vv.size() + 1ll * (y.size() - vv.size()) * (m / 2);
  if (m & 1) {
    x = v;
    y = vv;
    st = 0;
    while (st < x.size()) {
      int f = x[st];
      int cnt = 0;
      while (y.size() && y.back() == f) {
        ++cnt;
        y.pop_back();
      }
      while (st < x.size() && x[st] == f) {
        ++st;
        ++cnt;
      }
      cnt %= k;
      while (cnt--) y.push_back(f);
    }
    ans += y.size() - vv.size();
  }
  printf("%lld\n", ans + flag * (!!ans));
  return 0;
}
