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;
using ll = long long;
using pii = pair<int, int>;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k, m;
  cin >> n >> k >> m;
  vector<array<int, 2>> b;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (b.empty() || b.back()[0] != x) {
      b.push_back({x, 0});
    }
    b.back()[1]++;
    if (b.back()[1] == k) b.pop_back();
  }
  n = b.size();
  ll len = 0;
  for (auto x : b) len += x[1];
  if (b.size() == 0 || m == 1) {
    cout << len << '\n';
    return 0;
  }
  ll r = 0, er = 0;
  for (int i = 0; i < n; i++) {
    if (b[n - 1 - i][0] != b[i][0]) break;
    int sum = b[n - 1 - i][1] + b[i][1];
    er += sum / k * k;
    sum %= k;
    if (sum) break;
    r++;
  }
  if (r == n) {
    cout << len * (m % 2) << '\n';
    return 0;
  } else if (2 * r + 1 == n) {
    int sum = b[r][1] * m;
    sum %= k;
    if (sum) {
      cout << len - b[r][1] + sum << '\n';
    } else {
      cout << 0 << '\n';
    }
    return 0;
  } else {
    cout << len * m - er * (m - 1) << '\n';
    return 0;
  }
}
