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 N, K, M;
pair<int, int> A[100100];
int sz = 0;
int main() {
  ios::sync_with_stdio(0);
  cin >> N >> K >> M;
  int curE = 0, cnt = 0;
  for (int i = 0, a; i < N; i++) {
    cin >> a;
    if (a != curE) {
      if (curE != 0 && cnt > 0) {
        if (sz > 0 && curE == A[sz - 1].first) {
          A[sz - 1].second = (A[sz - 1].second + cnt) % K;
          if (A[sz - 1].second == 0) sz--;
        } else
          A[sz++] = make_pair(curE, cnt);
      }
      curE = a;
      cnt = 1;
    } else
      cnt = (cnt + 1) % K;
  }
  if (cnt > 0) A[sz++] = make_pair(curE, cnt);
  int idx = 0;
  long long rem = 0;
  for (; idx < sz / 2; idx++) {
    if (A[idx].first != A[sz - 1 - idx].first) break;
    if ((A[idx].second + A[sz - 1 - idx].second) % K != 0) {
      rem = (A[idx].second + A[sz - 1 - idx].second) % K;
      break;
    }
  }
  if (idx < sz / 2) {
    if (rem > 0) idx++;
    long long sum = 0;
    for (int i = 0; i < idx; i++) sum += A[i].second + A[sz - 1 - i].second;
    for (int i = idx; i <= sz - 1 - idx; i++) sum += (long long)M * A[i].second;
    sum += (M - 1) * rem;
    cout << sum << "\n";
  } else {
    if (sz % 2 == 0) {
      if (M > 1)
        cout << "0\n";
      else {
        long long sum = 0;
        for (int i = 0; i < sz; i++) sum += A[i].second;
        cout << sum << "\n";
      }
    } else {
      if ((long long)M * A[idx].second % K == 0)
        cout << "0\n";
      else {
        long long sum = (long long)M * A[idx].second % K;
        for (int i = 0; i < idx; i++) sum += A[i].second + A[sz - 1 - i].second;
        cout << sum << "\n";
      }
    }
  }
  return 0;
}
