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;
void print(vector<pair<long long, deque<pair<int, long long> > > > &g) {
  for (auto &i : g) {
    cout << i.first << " = {";
    for (auto &j : i.second) {
      cout << "(" << j.first << ", " << j.second << ") ";
    }
    cout << "}\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  long long n, k, m;
  cin >> n >> k >> m;
  deque<pair<int, long long> > a;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (!a.size() || a.back().first != x)
      a.push_back({x, 1LL});
    else
      a.back().second++;
    if (a.size() && a.back().second == k) a.pop_back();
  }
  if (a.size() == 0) a.push_back({0, 0});
  if (a.size() == 1) {
    cout << 1LL * a.back().second * m % k << "\n";
    return 0;
  }
  if (m == 1) {
    long long ans = 0;
    for (auto i : a) ans += i.second;
    cout << ans;
    return 0;
  }
  vector<pair<long long, deque<pair<int, long long> > > > g;
  if (m == 2) {
    g.push_back({1LL, a});
    g.push_back({1LL, a});
    bool was = 1;
    while (was && g[0].second.size() && g[1].second.size()) {
      was = 0;
      if (g[0].second.back().first == g[1].second.front().first &&
          g[0].second.back().second + g[1].second.front().second >= k) {
        g[0].second.back().second += g[1].second.front().second;
        g[1].second.pop_front();
        g[0].second.back().second -= k;
        if (g[0].second.back().second == 0) g[0].second.pop_back();
        was = 1;
      }
    }
  } else {
    g.push_back({1, a});
    g.push_back({m - 2, a});
    g.push_back({1, a});
    bool was = 1;
    while (was && g[0].second.size() >= 1 && g[1].second.size() > 1 &&
           g[2].second.size() >= 1) {
      was = 0;
      if (g[0].second.back().first == g[1].second.front().first &&
          g[0].second.back().second + g[1].second.front().second >= k) {
        g[0].second.back().second += g[1].second.front().second;
        g[1].second.back().second += g[1].second.front().second;
        g[2].second.pop_front();
        g[1].second.pop_front();
        g[0].second.back().second -= k;
        g[1].second.back().second -= k;
        if (g[0].second.back().second == 0) g[0].second.pop_back();
        if (g[1].second.back().second == 0) g[1].second.pop_back();
        was = 1;
      }
    }
    if (g[1].second.size() == 1) {
      g[0].second.push_back(g[1].second[0]);
      g[0].second.back().second *= g[1].first;
      g.erase(g.begin() + 1);
    }
  }
  if (g.size() == 2) {
    for (int i = 0; i < g[1].second.size(); i++) {
      g[0].second.push_back(g[1].second[i]);
    }
    g.pop_back();
  }
  if (g.size() == 1) {
    vector<pair<int, long long> > ans;
    for (int i = 0; i < g[0].second.size(); i++) {
      if (ans.size() && ans.back().first == g[0].second[i].first)
        ans.back().second += g[0].second[i].second;
      else
        ans.push_back(g[0].second[i]);
      ans.back().second %= k;
      if (ans.back().second == 0) ans.pop_back();
    }
    long long answ = 0;
    for (auto &i : ans) answ += i.second;
    cout << answ << "\n";
  } else if (g.size() == 3) {
    long long answ = 0;
    for (auto &i : g[0].second) answ += g[0].first * i.second;
    for (auto &i : g[1].second) answ += g[1].first * i.second;
    for (auto &i : g[2].second) answ += g[2].first * i.second;
    cout << answ << "\n";
  }
  return 0;
}
