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;
long long i, j, temp;
long long n, k, m, len;
long long a[100010], b[100010];
long long 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 = 0;
    bool all = true;
    long long e;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (all) {
        if (i == 0)
          e = a[i];
        else {
          if (e != a[i]) all = false;
        }
      }
    }
    if (all) {
      cout << (long long)(n * m % k) << endl;
      continue;
    }
    if (k <= n) {
      stack<long long> s, num;
      long long number = 1, cha = a[0];
      for (i = 1; i < n; i++) {
        if (a[i] == cha)
          number++;
        else {
          number %= k;
          if (number != 0) {
            num.push(number);
            s.push(cha);
            number = 1;
            cha = a[i];
          } else {
            if (s.empty() || s.top() != a[i]) {
              cha = a[i];
              number = 1;
            } else {
              cha = s.top();
              s.pop();
              number = num.top();
              num.pop();
              number++;
            }
          }
        }
      }
      number %= k;
      num.push(number);
      s.push(cha);
      while (!s.empty()) {
        cha = s.top();
        s.pop();
        number = num.top();
        num.pop();
        for (i = 0; i < number; i++) {
          b[len++] = cha;
        }
      }
    } else {
      len = n;
      for (i = 0; i < n; i++) b[i] = a[i];
    }
    long long l = 0, r = len - 1;
    long long ln = -1, rn = len;
    if (len > 0) {
      while (b[l] == b[r] && l < r) {
        temp = b[r];
        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;
      }
      long long len1 = 0;
      for (i = ln + 1; i < rn; i++) {
        mid[len1++] = b[i];
      }
      for (i = 0; i < len1 - 1; i++)
        if (mid[i + 1] != mid[i]) break;
      if (i == len1 - 1) {
        long long aa = (long long)(len1 * m % k);
        if (aa == 0) {
          ans = 0;
        } else
          ans = (long long)((ln + 1) + aa + (len - rn));
      } else
        ans = (long long)((ln + 1) + len1 * m + (len - rn));
    } else {
      ans = (long long)(len * m);
    }
    cout << ans << endl;
  }
  return 0;
}
