#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const long long big = 1000000007ll;
const long long big2 = 1000000009ll;
long long n, m, k, q, w, h, T;
vector<long long> A;
vector<long long> B;
int main() {
  long long a, b, c, d;
  cin >> n >> k >> m;
  long long prev = -1;
  long long same = 1;
  for (long long c1 = 0; c1 < n; c1++) {
    cin >> a;
    A.push_back(a);
    if (a == prev) {
      same++;
    } else {
      same = 1;
    }
    B.push_back(same);
    if (same == k) {
      for (long long c2 = 0; c2 < k; c2++) {
        A.pop_back();
        B.pop_back();
      }
    }
    prev = -1;
    same = 1;
    if ((int)(A).size() != 0) {
      prev = A[(int)(A).size() - 1];
      same = B[(int)(B).size() - 1];
    }
  }
  n = (int)(A).size();
  long long r = n - 1;
  long long l;
  long long c1 = 0;
  while (c1 < n) {
    l = c1;
    if (r - l + 1 < k) {
      break;
    } else {
      long long r2 = r;
      bool fail = 0;
      long long amt = 1;
      for (long long c2 = 0; c2 < k - 1; c2++) {
        if (A[l] != A[r2]) {
          break;
        }
        amt++;
        r2--;
      }
      long long t = A[l];
      long long oldl = l;
      if (amt < k) {
        l++;
        while (A[l] == t) {
          l++;
          amt++;
          if (amt == k) break;
        }
        l--;
      }
      if (amt < k) {
        l = oldl;
        break;
      }
      if (fail) break;
      r = r2;
    }
    c1 = l;
    c1++;
  }
  if (l >= r + 1) {
    cout << "0\n";
  } else {
    bool sim = 1;
    long long one = A[l];
    for (long long c1 = l; c1 <= r; c1++) {
      if (A[c1] != one) sim = 0;
    }
    if (sim) {
      vector<long long> A2;
      vector<long long> A1;
      c = ((m - 2) * (r - l + 1)) % k;
      long long k1 = 0;
      long long k2 = 0;
      for (long long c1 = r; c1 >= 0; c1--) {
        if (A[c1] != one) break;
        k1++;
        c++;
      }
      for (long long c1 = l; c1 < n; c1++) {
        if (A[c1] != one) break;
        k2++;
        c++;
      }
      c %= k;
      for (long long c1 = 0; c1 <= r - k1; c1++) {
        A1.push_back(A[c1]);
      }
      for (long long c1 = l + k2; c1 < n; c1++) {
        A2.push_back(A[c1]);
      }
      if (c != 0) {
        cout << (int)(A1).size() + (int)(A2).size() + c << "\n";
      } else {
        A.clear();
        B.clear();
        vector<long long> AA;
        for (long long c1 = 0; c1 < (int)(A1).size(); c1++) {
          AA.push_back(A1[c1]);
        }
        for (long long c1 = 0; c1 < (int)(A2).size(); c1++) {
          AA.push_back(A2[c1]);
        }
        n = (int)(AA).size();
        prev = -1;
        same = 1;
        for (long long c1 = 0; c1 < n; c1++) {
          a = AA[c1];
          A.push_back(a);
          if (a == prev) {
            same++;
          } else {
            same = 1;
          }
          B.push_back(same);
          if (same == k) {
            for (long long c2 = 0; c2 < k; c2++) {
              A.pop_back();
              B.pop_back();
            }
          }
          prev = -1;
          same = 1;
          if ((int)(A).size() != 0) {
            prev = A[(int)(A).size() - 1];
            same = B[(int)(B).size() - 1];
          }
        }
        cout << (int)(A).size() << "\n";
      }
    } else {
      cout << m * n - (m - 1) * (l + (n - 1 - r)) << "\n";
    }
  }
  return 0;
}
