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 = 101010;
int a[maxn];
int b[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  int n, k, m;
  cin >> n >> k >> m;
  bool allEqual = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != a[1]) {
      allEqual = 0;
    }
  }
  if (allEqual) {
    cout << m * 1ll * n % k;
    return 0;
  }
  if (k >= n) {
    cout << m * 1ll * n;
    return 0;
  }
  int seqLen = 0, ln = 0;
  for (int i = 1; i <= n; i++) {
    if (seqLen == k) {
      ln -= k;
      seqLen = 0;
    }
    b[++ln] = a[i];
    if (!seqLen || a[i] == a[i - 1]) {
      seqLen++;
    } else {
      seqLen = 1;
    }
  }
  if (seqLen == k) {
    ln -= k;
  }
  int l = 1, r = ln;
  long long ans = ln * 1ll * m;
  while (r - l + 1 >= k && b[l] == b[r]) {
    int i = l, j = r, tmp;
    while (i < j && b[i] == b[r]) {
      i++;
    }
    while (i < j && b[l] == b[j]) {
      j--;
    }
    if (i == j || (i - l) + (r - j) >= k) {
      tmp = k;
      while (tmp && l < i) {
        tmp--;
        l++;
      }
      while (tmp && r > j) {
        tmp--;
        r--;
      }
      ans -= (m - 1) * 1ll * k;
    } else {
      break;
    }
  }
  if (r - l + 1 < k) {
    allEqual = 1;
    for (int i = l; i <= r; i++) {
      if (a[i] != a[l]) {
        allEqual = 0;
      }
    }
    if (!allEqual) {
      cout << ans;
      return 0;
    }
    int rem = (r - l + 1) * 1ll * m % k;
    int ln2 = 0;
    for (int i = 1; i < l; i++) {
      a[++ln2] = b[i];
    }
    for (int i = 1; i <= rem; i++) {
      a[++ln2] = b[l];
    }
    for (int i = r + 1; i <= ln; i++) {
      a[++ln2] = b[i];
    }
    bool found = 1;
    int cnt = 0;
    while (ln2 >= k && found) {
      found = 0;
      cnt = 0;
      for (int i = 1; i <= ln2; i++) {
        if (cnt == k) {
          ln = 0;
          for (int j = 1; j < cnt - k; j++) {
            b[++ln] = a[j];
          }
          for (int j = i; j <= ln2; j++) {
            b[++ln] = a[j];
          }
          ln2 = ln;
          for (int j = 1; j <= ln; j++) {
            a[j] = b[j];
          }
          found = 1;
          break;
        }
        if (i > 1 && a[i] == a[i - 1]) {
          cnt++;
        } else {
          cnt = 1;
        }
      }
      if (cnt == k) {
        ln2 -= k;
        found = 1;
      }
    }
    cout << ln2;
    return 0;
  }
  cout << ans;
  return 0;
}
