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, a[101000], g, c[101000], l, x, ans, all;
int main() {
  cin >> n >> k >> m;
  for (int o = n; o--;) {
    cin >> x;
    if (x == a[g] && g) {
      c[g]++;
    } else {
      a[++g] = x;
      c[g] = 1;
    }
    if (c[g] == k) g--;
  }
  for (int i = 1; i <= g; i++) all += c[i];
  for (l = 1; l * 2 <= g; l++) {
    if (a[l] != a[g + 1 - l]) break;
    if (c[l] = (c[l] + c[g + 1 - l]) % k) {
      c[g + 1 - l] = 0;
      break;
    }
  }
  if (l * 2 <= g) {
    for (int i = l; i <= g + 1 - l; i++) ans += c[i];
    ans = ans * (m - 1) + all;
  } else if (c[l] * m % k) {
    ans = all - c[l] + c[l] * m % k;
  }
  cout << ans;
}
