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;
long long n, m, k;
int a[100005];
deque<pair<int, long long> > s[2];
int main() {
  cin >> n >> k >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  long long remain;
  for (int j = 0; j <= 1; j++) {
    remain = 0LL;
    for (int i = 1; i <= n; i++) {
      if (s[j].empty()) {
        s[j].push_back(pair<int, long long>(a[i], 1));
        remain++;
      } else {
        if (s[j].back().first == a[i]) {
          pair<int, long long> t = s[j].back();
          s[j].pop_back();
          if (t.second + 1LL != k) {
            s[j].push_back(pair<int, long long>(t.first, t.second + 1LL));
            remain++;
          } else
            remain -= (k - 1);
        } else {
          s[j].push_back(pair<int, long long>(a[i], 1));
          remain++;
        }
      }
    }
  }
  if ((int)s[0].size() == 0)
    printf("0\n");
  else if ((int)s[0].size() == 1)
    cout << (s[0].back().second * m) % k << endl;
  else if (s[0].front().first != s[0].back().first)
    cout << remain * m << endl;
  else {
    remain *= m;
    while (!s[0].empty()) {
      pair<int, long long> t1 = s[0].back(), t2 = s[1].front();
      if (t1.first != t2.first) {
        cout << remain << endl;
        break;
      }
      if ((int)s[0].size() == 2) {
        assert(t1.second == t2.second);
        long long lost = m * t1.second - (m * t1.second) % k;
        remain -= lost;
        if (lost == m * t1.second) {
          t1 = s[0].front();
          t2 = s[1].back();
          cout << (t1.second + t2.second) % k << endl;
        } else
          cout << remain << endl;
        break;
      } else {
        if (t1.second + t2.second == k) {
          remain -= k * (m - 1);
          s[0].pop_back();
          s[1].pop_front();
        } else if (t1.second + t2.second > k) {
          remain -= k * (m - 1);
          cout << remain << endl;
          break;
        } else {
          cout << remain << endl;
          break;
        }
      }
    }
  }
  return 0;
}
