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;
const long long int mod = 1e9 + 7;
long long int k;
void push(vector<pair<int, long long int> > &target, const vector<int> &a) {
  int n = a.size();
  for (int i = (int)(0); i < (int)(n); i++) {
    if (target.size() == 0 || target.back().first != a[i]) {
      target.push_back(pair<int, long long int>(a[i], 1));
    } else {
      target.back().second++;
      if (target.back().second >= k) {
        target.pop_back();
      }
    }
  }
}
vector<pair<int, long long int> > mul(
    const vector<pair<int, long long int> > &s,
    const vector<pair<int, long long int> > &t) {
  vector<pair<int, long long int> > ret(s);
  for (int i = (int)(0); i < (int)(t.size()); i++) {
    int kind = t[i].first;
    long long int num = t[i].second;
    if (num == 0) continue;
    if (ret.size() == 0 || ret.back().first != kind) {
      ret.push_back(pair<int, long long int>(kind, num));
    } else {
      ret.back().second += num;
      ret.back().second %= k;
      if (ret.back().second == 0) {
        ret.pop_back();
      }
    }
  }
  return ret;
}
bool is_two_streaks_with_possible_reduction(
    const vector<pair<int, long long int> > &x) {
  if (x.size() != 3) return false;
  assert(x.size() == 3);
  return x[0].first == x[2].first;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long int m;
  cin >> n >> k >> m;
  vector<int> a(n);
  for (int i = (int)(0); i < (int)(n); i++) cin >> a[i];
  vector<pair<int, long long int> > one;
  push(one, a);
  if (m == 1) {
    long long int ans = 0;
    for (pair<int, long long int> x : one) ans += x.second;
    cout << ans << "\n";
    return 0;
  }
  if (one.size() == 1) {
    cout << one[0].second * m % k << "\n";
    return 0;
  }
  if (is_two_streaks_with_possible_reduction(one)) {
    if ((one[0].second + one[2].second) % k == 0) {
      vector<pair<int, long long int> > res;
      res = mul(res, vector<pair<int, long long int> >(1, one[0]));
      res = mul(res, vector<pair<int, long long int> >(
                         1, pair<int, long long int>(one[1].first,
                                                     one[1].second * m % k)));
      res = mul(res, vector<pair<int, long long int> >(1, one[2]));
      long long int ans = 0;
      for (pair<int, long long int> x : res) ans += x.second;
      cout << ans << "\n";
      return 0;
    }
  }
  vector<pair<int, long long int> > two(one);
  push(two, a);
  long long int s = 0, t = 0;
  for (pair<int, long long int> x : one) s += x.second;
  for (pair<int, long long int> x : two) t += x.second;
  cout << s + (t - s) * (m - 1) << "\n";
}
