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;
int num[123456], stk[123456], sum[123456];
int main() {
  long long n, k, m;
  while (scanf("%lld%lld%lld", &n, &k, &m) != EOF) {
    for (int i = 0; i < n; i++) scanf("%d", &num[i]);
    bool flag = 1;
    for (int i = 1; i < n && flag; i++) {
      if (num[i] != num[i - 1]) flag = 0;
    }
    if (flag) {
      printf("%lld\n", n * m % k);
      continue;
    }
    int top = 0;
    for (int i = 0; i < n; i++) {
      stk[++top] = num[i];
      if (top - 1 > 0 && stk[top] == stk[top - 1])
        sum[top] = sum[top - 1] + 1;
      else
        sum[top] = 1;
      if (sum[top] >= k) top -= k;
    }
    if (!top) {
      printf("0\n");
      continue;
    }
    for (int i = 1; i <= top; i++) num[i - 1] = stk[i];
    int left = 0, right = top - 1, key = 0;
    while (left < right) {
      int l = left, r = right;
      while (num[left] == num[r] && l < r && key < k) r--, key++;
      while (num[right] == num[l] && l < r && key < k) l++, key++;
      if (key == k) {
        key = 0;
        left = l;
        right = r;
      } else
        break;
    }
    flag = 1;
    for (int i = left + 1; i <= right && flag; i++) {
      if (num[i] != num[i - 1]) flag = 0;
    }
    long long len = right - left + 1;
    if (flag) {
      if (len * m % k == 0)
        printf("0\n");
      else
        printf("%lld\n", len * m % k + top - len);
    } else {
      printf("%lld\n", top - len + len * m);
    }
  }
}
