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);
  auto rep = [](vector<array<int, 2>>& b, vector<int>& a, int k) {
    int n = a.size();
    int c = 0;
    b.clear();
    int rem = 0;
    for (int i = 0; i < n; i++) {
      int val = a[i];
      while (i < n && a[i] == val) c++, i++;
      rem += c - c % k;
      b.push_back({c % k, val});
      c = 0;
      i--;
    }
    return rem;
  };
  ll n, k, m;
  cin >> n >> k >> m;
  ll c = n * m;
  vector<int> a(n);
  for (auto& x : a) cin >> x;
  vector<array<int, 2>> b;
  c -= rep(b, a, k);
  if (b.size() == 1) {
    cout << c % k << '\n';
    return 0;
  }
  int sz = b.size();
  int l = 0, r = sz - 1;
  if (m == 1) {
    cout << c << '\n';
  } else {
    auto st = b, en = b;
    int stl = l, enl = l, str = r, enr = r;
    while (l < r) {
      if (b[l][1] != b[r][1]) break;
      ll sum = b[l][0] + b[r][0];
      if (sum < k) break;
      ll d = (sum / k) * k;
      c -= (m - 1) * d;
      int reml = min(d, (ll)b[l][0]);
      d -= reml, b[l][0] -= reml, en[enl][0] -= reml;
      if (b[l][0] == 0) enl++, l++;
      int remr = min(d, (ll)b[r][0]);
      d -= remr, b[r][0] -= remr, st[str][0] -= remr;
      if (b[r][0] == 0) str--, r--;
      assert(d == 0);
    }
    if (l == r) c %= k;
    assert(c >= 0);
    cout << c << '\n';
  }
}
