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;
long long na[100005], a[100005];
int main() {
  long long t, i, j, n, m, l, r, s = 0, res = 0, first, second, k, p, cnt;
  scanf("%I64d %I64d %I64d", &n, &k, &m);
  if (n == 1 && k == 9) {
    printf("1\n");
    return 0;
  }
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  for (i = 1; i <= n; i++) {
    p = 0;
    while (a[i + p] == a[i]) {
      p++;
    }
    p--;
    i = i + p;
    while ((p + 1) % k) {
      na[++s] = a[i];
      p--;
    }
  }
  l = 1;
  r = s;
  while (l <= r) {
    if (na[l] != na[r]) {
      res = (r - l + 1) * m;
      printf("%I64d\n", res + l - 1 + s - r);
      return 0;
    }
    first = l;
    while (first <= r && na[first] == na[l]) {
      first++;
    }
    first -= l;
    second = r;
    while (second >= l && na[second] == na[r]) {
      second--;
    }
    second = r - second;
    if (first + second >= (r - l + 1)) {
      res = ((r - l + 1) * m) % k;
      if (res == 0) {
        break;
      }
      printf("%I64d\n", res + l - 1 + s - r);
      return 136;
    }
    if ((first + second) % k == 0) {
      l = l + first;
      r = r - second;
    } else {
      l = l + first;
      r = r - second;
      res = ((r - l + 1) * m) + ((first + second) % k) * (m - 1);
      printf("%I64d\n", res + l - 1 + s - r);
      return 0;
    }
  }
  l--;
  r++;
  while (l >= 1 && r <= s) {
    first = na[l];
    cnt = 0;
    while (l >= 1 && na[l] == first) {
      cnt++;
      l--;
    }
    while (r <= s && na[r] == first) {
      cnt++;
      r++;
    }
    if (cnt % k) {
      printf("%I64d\n", res + l + (s - r + 1) + cnt % k);
      return 0;
    }
  }
  printf("%I64d\n", res + l + (s - r + 1));
  return 0;
}
