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;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, k, m;
  cin >> n >> k >> m;
  long long at = 0;
  vector<long long> a(n);
  deque<pair<long long, long long>> x;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == at) {
      x.back().second++;
      if (x.back().second == k) {
        x.pop_back();
        if (x.empty())
          at = 0;
        else
          at = x.back().first;
      }
    } else {
      x.push_back({a[i], 1});
      a[i] = at;
    }
  }
  while (x.size() > 1) {
    if (x.front().first == x.back().first) {
      long long qq = x.front().second + x.back().second;
      if (qq % k == 0) {
        x.pop_front();
        x.pop_back();
      } else {
        x.pop_back();
        x.front().second = qq % k;
      }
    } else
      break;
  }
  long long rimasti = 0;
  for (auto u : x) {
    rimasti += u.second;
  }
  if (x.size() == 1)
    cout << (rimasti * m) % k << "\n";
  else {
    cout << rimasti * m + n - rimasti << "\n";
  }
}
