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;
constexpr int N{100500};
constexpr int INF{numeric_limits<int>::max() / 2};
constexpr long long INFll{numeric_limits<long long>::max() / 2};
int a[N];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  long long m, k;
  cin >> n >> k >> m;
  bool f{1};
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<int> b;
  int s{};
  bool c{};
  for (int i = 0; i < n; ++i) {
    if (b.size() > 0 && b.back() == a[i]) {
      b.push_back(a[i]);
      if (c) {
        ++s;
      } else {
        s = 0;
        int j = b.size() - 1;
        while (j >= 0) {
          if (a[i] != b[j]) break;
          ++s;
          --j;
        }
        c = 1;
      }
    } else {
      c = 1;
      s = 1;
      b.push_back(a[i]);
    }
    if (s == k) {
      s = 0;
      c = 0;
      for (int i = 0; i < k; ++i) {
        b.pop_back();
      }
    }
  }
  n = b.size();
  for (int i = 0; i < n; ++i) a[i] = b[i];
  for (int i = 1; i < n; ++i) {
    if (a[i] != a[i - 1]) {
      f = 0;
    }
  }
  long long ans{m * n};
  if (f) {
    cout << ans % k << "\n";
    return 0;
  }
  int l{-1};
  int r{n};
  long long cur{};
  int rem{};
  b.clear();
  while (1) {
    cur = 1;
    ++l;
    while (l + 1 < n && a[l + 1] == a[l]) {
      ++l;
      ++cur;
    }
    while (r > 0 && a[r - 1] == a[l]) {
      --r;
      ++cur;
    }
    if (l < r) {
      if (cur >= k) ans -= (m - 1) * (cur - (cur % k));
    } else {
      if (cur >= k) {
        ans -= (m * (cur / 2) / k) * k;
        rem = (m * (cur / 2)) % k;
        for (int i = 0; i < r; ++i) {
          b.push_back(a[i]);
        }
        for (int i = 0; i < rem; ++i) {
          b.push_back(a[l]);
        }
        for (int i = l + 1; i < n; ++i) {
          b.push_back(a[i]);
        }
      }
      break;
    }
    if (cur % k > 0) {
      rem = cur % k;
      cur = a[l];
      for (int i = 0; i < r; ++i) {
        b.push_back(a[i]);
      }
      for (int i = 0; i < rem; ++i) {
        b.push_back(cur);
      }
      for (int i = l + 1; i < r; ++i) {
        b.push_back(a[i]);
      }
      for (int i = r + 1; i < n; ++i) {
        b.push_back(a[i]);
      }
      break;
    }
  }
  n = b.size();
  l = n / 2;
  r = l;
  ++l;
  while (1) {
    --l;
    if (l < 0) break;
    cur = 1;
    while (l > 0 && b[l - 1] == b[l]) {
      --l;
      ++cur;
    }
    while (r < n - 1 && b[r + 1] == b[l]) {
      ++cur;
      ++r;
    }
    if (cur >= k) ans -= (cur / k) * k;
    if (cur % k > 0) {
      if (cur >= k) ans -= cur - (cur % k);
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}
