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 Pair = std::pair<int, int>;
long long GetSize(const std::deque<Pair> &a) {
  return std::accumulate(a.begin(), a.end(), 0, [](long long s, const Pair &x) {
    return s + x.second;
  });
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  int n, k;
  long long m;
  std::cin >> n >> k >> m;
  std::deque<Pair> a;
  while (n--) {
    int x;
    std::cin >> x;
    if (a.empty() or a.back().first != x)
      a.push_back({x, 1});
    else {
      if (++(a.back().second) == k) a.pop_back();
    }
  }
  long long Y = GetSize(a);
  ;
  while (a.size() > 1 and a.front().first == a.back().first) {
    if ((a.front().second = (a.front().second + a.back().second) % k) == 0)
      a.pop_front();
    a.pop_back();
  }
  long long X = GetSize(a);
  ;
  if (a.empty()) {
    std::cout << 0;
  } else if (a.size() > 1) {
    ;
    std::cout << (m - 1) * X + Y;
  } else {
    auto e = (a.front().second * m) % k;
    ;
    if (e) {
      std::cout << e + Y - X;
    } else {
      std::cout << 0;
    }
  }
  std::cout << "\n";
  return 0;
}
