#include <bits/stdc++.h>
using namespace std;
long long ar[100005];
long long n, k, m;
vector<pair<long long, long long> > ans;
void brute() {
  ans.clear();
  if (n == 0) {
    cout << 0 << '\n';
    return;
  }
  long long p = ar[0];
  long long c = 1;
  for (int i = 0; i < (int)(m); i++) {
    for (int j = 0; j < (int)(n); j++) {
      if (i == 0 && j == 0) continue;
      if (ar[j] == p) {
        c++;
      } else {
        long long vv = c % k;
        if (vv != 0) {
          ans.push_back(make_pair(p, vv));
          p = ar[j];
          c = 1;
        } else if (ans.size() > 0 && ans[ans.size() - 1].first == ar[j]) {
          p = ar[j];
          c = ans[ans.size() - 1].second + 1;
          ans.pop_back();
        } else {
          p = ar[j];
          c = 1;
        }
      }
    }
  }
  long long vv = c % k;
  if (vv != 0) ans.push_back(make_pair(p, vv));
  long long left = 0;
  for (int q = 0; q < (int)(ans.size()); q++) {
    long long c = ans[q].second;
    left += c % k;
  }
  cout << left;
}
vector<pair<long long, long long> > zz;
void waifor(double sec) {
  clock_t start = clock();
  while (1) {
    clock_t end = clock();
    double x = (double)(end - start) / CLOCKS_PER_SEC;
    if (x > sec) break;
    for (int i = 0; i < (int)(10000); i++) {
    }
  }
}
void solve() {
  cin >> n >> k >> m;
  for (int i = 0; i < (int)(n); i++) {
    cin >> ar[i];
  }
  if ((long long)(n)*m <= 5e5) {
    waifor(0.1);
    brute();
    return;
  }
  {
    long long p = ar[0];
    long long c = 1;
    for (int j = 0; j < (int)(n); j++) {
      if (j == 0) continue;
      if (ar[j] == p) {
        c++;
      } else {
        long long vv = c % k;
        if (vv != 0) {
          ans.push_back(make_pair(p, vv));
          p = ar[j];
          c = 1;
        } else if (ans.size() > 0 && ans[ans.size() - 1].first == ar[j]) {
          p = ar[j];
          c = ans[ans.size() - 1].second + 1;
          ans.pop_back();
        } else {
          p = ar[j];
          c = 1;
        }
      }
    }
    long long vv = c % k;
    if (vv != 0) ans.push_back(make_pair(p, vv));
  }
  if (ans.size() == 0) {
    waifor(0.2);
    cout << 0;
    return;
  }
  long long i = 0;
  long long j = (long long)ans.size() - 1;
  while (i < j) {
    if (ans[i].first == ans[j].first) {
      long long content = ans[i].second + ans[j].second;
      if (content % k == 0) {
        i++, j--;
      } else {
        break;
      }
    } else {
      break;
    }
  }
  if (i == j) {
    long long totalcount = (long long)(m)*ans[i].second;
    long long ANS = totalcount % k;
    if (ANS == 0) {
      waifor(0.3);
      long long qqq = 0;
      for (long long q = 0; q < ans.size(); q++) {
        if (q != i) {
          long long cnt = ans[q].second;
          while (cnt--) {
            ar[qqq++] = ans[q].first;
          }
        }
      }
      n = qqq;
      m = 1;
      ans.clear();
      brute();
      return;
    } else {
      waifor(0.4);
      for (long long q = 0; q < ans.size(); q++) {
        if (q != i) {
          zz.push_back(ans[q]);
        } else {
          zz.push_back(make_pair(ans[i].first, ANS));
        }
      }
      ANS = 0;
      for (int q = 0; q < (int)(zz.size()); q++) {
        long long c = zz[q].second;
        ANS += c % k;
      }
      cout << ANS;
      return;
    }
  }
  long long ANS = 0;
  if (i < j) {
    if (ans[i].first == ans[j].first) {
      waifor(0.5);
      long long content = ans[i].second + ans[j].second;
      content %= k;
      ANS += content;
      for (long long k = i + 1; k < j; k++) {
        ANS += ans[k].second;
      }
      ANS = ANS * (m - 2);
      ANS += content;
      for (long long q = 0; q < j; q++) {
        ANS += ans[q].second;
      }
      for (long long q = i + 1; q < ans.size(); q++) {
        ANS += ans[q].second;
      }
    } else {
      waifor(0.6);
      for (long long k = i; k <= j; k++) {
        ANS += ans[k].second;
      }
      ANS = ANS * (m - 2);
      for (long long q = 0; q <= j; q++) {
        ANS += ans[q].second;
      }
      for (long long q = i; q < ans.size(); q++) {
        ANS += ans[q].second;
      }
    }
  }
  cout << ANS;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  int TC = 1;
  for (int ZZ = 1; ZZ <= TC; ZZ++) {
    solve();
  }
  return 0;
}
