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 ans;
int n, k, m, len;
int a[100010], b[10010];
int mid[100010];
int main() {
  while (cin >> n >> k >> m) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(a));
    memset(mid, 0, sizeof(a));
    len = n;
    for (int i = 0; i < n; i++) cin >> a[i];
    if (k <= n) {
      bool judge = true;
      while (judge) {
        judge = false;
        int q = 0;
        int temp, j;
        for (int i = 0; i < n; i++) {
          temp = a[i];
          for (j = 0; j < k; j++)
            if (temp != a[i + j]) break;
          ;
          if (j == k) {
            i += k;
            i--;
            len -= k;
            judge = true;
          } else {
            for (int p = 0; p < j; p++) b[q++] = a[i++];
            i--;
          }
        }
        for (int i = 0; i < len; i++) {
          a[i] = b[i];
        }
        n = len;
      }
    }
    int l = 0, r = len - 1;
    int ln = -1, rn = len;
    if (len > 0 && b[l] == b[r]) {
      while (1) {
        int temp = b[r];
        int i = 1;
        for (i = 2; i < k; i++) {
          if (l + 1 >= r) break;
          if (b[r - 1] == temp) {
            r--;
            continue;
          } else if (b[l + 1] == temp) {
            l++;
            continue;
          } else
            break;
        }
        if (i == k) {
          ln = l;
          rn = r;
          l++;
          r--;
        } else
          break;
        if (l + 1 >= r) break;
      }
      int j = 0, len1 = 0, q = 0;
      for (int i = ln + 1; i < rn; i++) {
        mid[len1++] = b[i];
      }
      ans = (ln + 1) + len1 * m + (len - rn);
      int i;
      for (i = 1; i < len1; i++) {
        if (mid[i] != mid[i - 1]) break;
      }
      if (i == len1) {
        long long aa = len1 * m / k;
        ans -= aa * k;
      }
      if (ans == (ln + 1) + (len - rn)) {
        while (b[ln] == b[rn]) {
          int l = ln, r = rn;
          int i;
          for (i = 2; i < k; i++) {
            if (l <= 0 && r >= len - 1) break;
            if (r >= len - 1 && b[r + 1] == b[ln]) {
              r++;
              continue;
            } else if (l <= 0 && b[l - 1] == b[ln]) {
              l--;
              continue;
            } else
              break;
          }
          if (i == k) {
            l--;
            r++;
            ln = l;
            rn = r;
          } else
            break;
          if (l < 0 && r > len - 1) break;
        }
        ans = (ln + 1) + (len - rn);
      }
    } else {
      ans = len * m;
    }
    cout << ans << endl;
  }
  return 0;
}
