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;
int s[123456];
int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 0; i < n; i++) scanf("%d", &s[i]);
  deque<pair<int, long long> > dq;
  int cnt = 1, cur = s[0];
  for (int i = 1; i < n; i++) {
    if (s[i] == cur)
      cnt++;
    else {
      if (cnt % k) {
        dq.push_back(make_pair(cur, cnt % k));
        cnt = 1;
      } else if (!dq.empty() && dq.back().first == s[i]) {
        pair<int, long long> tmp = dq.back();
        dq.pop_back();
        cur = s[i];
        cnt = tmp.second + 1;
      } else
        cnt = 1;
      cur = s[i];
    }
  }
  if (cnt % k) dq.push_back(make_pair(cur, cnt % k));
  long long ans = 0;
  if (m == 1) {
    for (pair<int, long long> &i : dq) ans += i.second;
  } else {
    deque<pair<int, long long> > tmp = dq;
    while (tmp.size() && tmp.size() != 1) {
      if (tmp.front().first == tmp.back().first &&
          tmp.front().second + tmp.back().second == k) {
        tmp.pop_front();
        tmp.pop_back();
      } else {
        if (tmp.front().first == tmp.back().first) {
          tmp.back().second = (tmp.back().second + tmp.front().second) % k;
          tmp.pop_front();
        }
        break;
      }
    }
    if (tmp.size() == 1) {
      ans = (tmp.back().second * (m % k)) % k;
      if (ans != 0) {
        for (pair<int, long long> &i : dq) ans += i.second;
        ans -= tmp.front().second;
      }
    } else {
      if (tmp.size() == dq.size()) {
        for (pair<int, long long> &i : dq) {
          ans += i.second;
        }
      } else {
        while (tmp.size()) {
          ans += tmp.back().second;
          tmp.pop_back();
        }
        ans *= m - 1;
        for (pair<int, long long> &i : dq) ans += i.second;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
