#include <bits/stdc++.h>
using namespace std;
const int N = 300;
int getAns(deque<int> &a, int k) {
  vector<int> x;
  int last = 0;
  for (int i = 0; i < a.size(); ++i) {
    ++last;
    if (x.empty() || x.back() != a[i]) {
      last = 1;
    }
    x.push_back(a[i]);
    if (last == k) {
      for (int j = 0; j < k; ++j) {
        x.pop_back();
      }
      last = 0;
      while ((int)x.size() - last - 1 >= 0 &&
             x[(int)x.size() - last - 1] == x.back())
        ++last;
    }
  }
  return x.size();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k, m;
  cin >> n >> k >> m;
  int last = 0;
  deque<int> mas, a, b;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ++last;
    if (mas.empty() || mas.back() != a) {
      last = 1;
    }
    mas.push_back(a);
    if (last == k) {
      for (int j = 0; j < k; ++j) {
        mas.pop_back();
      }
      last = 0;
      while ((int)mas.size() - last - 1 >= 0 &&
             mas[(int)mas.size() - last - 1] == mas.back())
        ++last;
    }
  }
  if (m == 1) {
    cout << mas.size() << endl;
    return 0;
  }
  int dleft = 0, dright = 0;
  a = b = mas;
  int p1 = 0, p2 = (int)mas.size() - 1;
  while (p1 < mas.size() && mas[p1] == mas.front()) ++p1;
  while (p2 >= 0 && mas[p2] == mas.back()) --p2;
  while (!mas.empty() && mas.back() == mas.front() && p1 != mas.size() &&
         p1 + (mas.size() - p2 - 1) >= k) {
    int del = mas.front();
    for (int i = 0; i < k; ++i) {
      if (mas.back() == del) {
        mas.pop_back();
        dright++;
      } else {
        --p1;
        mas.pop_front();
        p2 = (int)mas.size() - 1;
        dleft++;
      }
    }
    while (p1 < mas.size() && mas[p1] == mas.front()) ++p1;
    while (p2 >= 0 && mas[p2] == mas.back()) --p2;
  }
  for (int i = 0; i < dright; ++i) {
    a.pop_back();
  }
  for (int i = 0; i < dleft; ++i) {
    b.pop_front();
  }
  swap(a, b);
  if (p1 != mas.size()) {
    cout << b.size() + a.size() + 1ll * (mas.size()) * (m - 2) << endl;
  } else {
    int64_t ans = 0, cur = 0;
    int ps = 0;
    while (ps < a.size() && a[ps] == mas[0]) ++ps;
    cur += ps;
    ans += (a.size() - ps);
    for (int i = 0; i < ps; ++i) a.pop_front();
    ps = (int)b.size() - 1;
    while (ps >= 0 && b[ps] == mas[0]) --ps;
    cur += ((int)b.size() - ps - 1);
    ans += ps + 1;
    ps = ((int)b.size() - ps - 1);
    for (int i = 0; i < ps; ++i) {
      b.pop_back();
    }
    cur += 1ll * (m - 2) * mas.size();
    cur %= k;
    if (cur == 0) {
      for (int i = 0; i < a.size(); ++i) {
        b.push_back(a[i]);
      }
      cout << getAns(b, k) << endl;
      return 0;
    }
    ans += cur;
    cout << ans << endl;
  }
  return 0;
}
