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 int inf = 100000007;
const long long linf = 1ll * inf * inf;
const int N = 500000 + 7;
const int M = 30;
const int multipleTest = 0;
int n, m, k;
int a[N];
long long calcSingle(deque<pair<int, long long>> x) {
  vector<pair<int, long long>> stk;
  long long tol = 0;
  for (pair<int, long long> c : x) {
    if (stk.empty() || stk.back().first != c.first)
      stk.push_back(c);
    else {
      stk.back().second += c.second;
    }
    while (!stk.empty() && stk.back().second >= k) {
      long long tmp = stk.back().second / k;
      tol += tmp * k;
      stk.back().second -= tmp * k;
      if (stk.back().second == 0) stk.pop_back();
    }
  }
  if (!stk.empty() && stk.back().second >= k) {
    long long tmp = stk.back().second / k;
    tol += tmp * k;
    stk.back().second -= tmp * k;
  }
  return tol;
}
long long calcEliminate(deque<pair<int, long long>>& x) {
  vector<pair<int, long long>> stk;
  long long tol = 0;
  for (pair<int, long long> c : x) {
    if (stk.empty() || stk.back().first != c.first)
      stk.push_back(c);
    else {
      stk.back().second += c.second;
    }
    while (!stk.empty() && stk.back().second >= k) {
      long long tmp = stk.back().second / k;
      tol += tmp * k;
      stk.back().second -= tmp * k;
      if (stk.back().second == 0) stk.pop_back();
    }
  }
  if (!stk.empty() && stk.back().second >= k) {
    long long tmp = stk.back().second / k;
    tol += tmp * k;
    stk.back().second -= tmp * k;
  }
  x.clear();
  for (auto c : stk) {
    x.push_back(c);
    cout << x.back().first << ' ' << x.back().second << '\n';
  }
  return tol;
}
deque<pair<int, long long>> lhs, rhs;
deque<pair<int, long long>> add(deque<pair<int, long long>> a,
                                deque<pair<int, long long>> b) {
  auto res = a;
  for (auto xx : b) {
    res.push_back(xx);
  }
  return res;
}
long long calc(deque<pair<int, long long>> x) {
  long long res = 0;
  while (!x.empty()) {
    if (x.size() == 1) {
      long long tmp = x.back().second * m;
      if (tmp % k == 0) {
        res += tmp + calcSingle(add(lhs, rhs));
      } else {
        res += (tmp / k) * k;
        lhs.push_back(make_pair(x.back().first, tmp % k));
        res += calcSingle(add(lhs, rhs));
      }
      x.pop_back();
    } else if (x.back().first == x.front().first) {
      long long tmp = x.back().second + x.front().second;
      lhs.push_back(x.front());
      rhs.push_front(x.back());
      x.pop_front();
      x.pop_back();
      if (tmp % k == 0) {
        res += tmp * (m - 1);
        continue;
      } else {
        res += (tmp / k) * k * (m - 1) + calcSingle(x) * (m - 2);
        res += calcSingle(add(lhs, x));
        res += calcSingle(add(x, rhs));
        return res;
      }
    } else {
      long long tmp = x.back().second;
      rhs.push_front(x.back());
      x.pop_back();
      if (tmp % k == 0) {
        res += tmp * (m - 1);
        continue;
      } else {
        res += (tmp / k) * k * (m - 1) + calcSingle(x) * (m - 2);
        res += calcSingle(add(lhs, x));
        res += calcSingle(add(x, rhs));
        return res;
      }
    }
  }
  return res;
}
void solve() {
  cin >> n >> k >> m;
  for (int i = (0), _b = (n); i < _b; ++i) scanf("%d", a + i);
  deque<pair<int, long long>> tmp;
  int cnt = 0;
  for (int i = (0), _b = (n); i < _b; ++i) {
    ++cnt;
    if (i == n - 1 || a[i] != a[i + 1]) {
      tmp.push_back(make_pair(a[i], cnt));
      cnt = 0;
    }
  }
  if (m == 1) {
    cout << n - calcSingle(tmp) << '\n';
  } else {
    long long tol = 1ll * n * m;
    tol -= calcEliminate(tmp) * m;
    cout << tol - calc(tmp) << '\n';
  }
}
int main() {
  int Test = 1;
  if (multipleTest) {
    cin >> Test;
  }
  for (int i = 0; i < Test; ++i) {
    solve();
  }
}
