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 maxn = 100005;
int n, k, m;
deque<pair<int, int> > init;
int main() {
  cin >> n >> k >> m;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    if (init.empty()) {
      init.push_back(pair<int, int>(a, 1));
    } else {
      pair<int, int> cur = init.back();
      init.pop_back();
      if (cur.first == a) {
        cur.second++;
        cur.second %= k;
        if (cur.second) init.push_back(cur);
      } else {
        init.push_back(cur);
        init.push_back(pair<int, int>(a, 1));
      }
    }
  }
  deque<pair<int, int> > mid = init;
  deque<pair<int, int> > Left, Right;
  while (mid.size() >= 2 && mid.front().first == mid.back().first &&
         mid.front().second + mid.back().second >= k) {
    pair<int, int> left = mid.front();
    mid.pop_front();
    pair<int, int> right = mid.back();
    mid.pop_back();
    int tmp = (right.second + left.second) % k;
    int cn_right = min(right.second, tmp);
    int cn_left = tmp - cn_right;
    if (right.second - cn_right != 0)
      Right.push_front(pair<int, int>(right.first, right.second - cn_right));
    if (left.second - cn_left != 0)
      Left.push_back(pair<int, int>(left.first, left.second - cn_left));
    right.second = cn_right;
    left.second = cn_left;
    if (left.second != 0) mid.push_front(left);
    if (right.second != 0) mid.push_back(right);
  }
  int last = 0;
  for (auto it = mid.begin(); it != mid.end(); it++) {
    last += it->second;
  }
  long long ans;
  if (mid.size() != 1) {
    ans = (long long)last * m + n - last;
  } else {
    pair<int, int> at = mid.front();
    at.second = ((long long)at.second * m) % k;
    if (at.second) {
      if (Left.empty())
        Left.push_back(at);
      else
        Right.push_front(at);
    }
    while (!Right.empty() && !Left.empty()) {
      pair<int, int> left = Left.back();
      Left.pop_back();
      pair<int, int> right = Right.front();
      Right.pop_front();
      if (left.first == right.first) {
        left.second += right.second;
        left.second %= k;
        if (left.second) Left.push_back(left);
      } else {
        Left.push_back(left);
        Left.push_back(right);
      }
    }
    ans = 0;
    for (auto it = Left.begin(); it != Left.end(); it++) {
      ans += it->second;
    }
  }
  cout << ans << endl;
  return 0;
}
