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, len;
int a[1000005], v[1000005];
int main() {
  int i, j, cnt = -1;
  cin >> len >> k >> m;
  for (i = 1; i <= len; ++i) cin >> v[i];
  int l = 1;
  for (i = 2; i <= len; ++i) {
    if (v[i] == v[i - 1])
      ++l;
    else {
      for (j = 1; j <= l % k; ++j) a[++n] = v[i - 1];
      l = 1;
    }
  }
  for (j = 1; j <= l % k; ++j) a[++n] = v[len];
  if (m == 1) {
    cout << n << "\n";
    return 0;
  }
  int st = 1, dr = n;
  while (st <= dr && a[st] == a[dr]) {
    for (i = dr; i >= st && a[i] == a[dr]; --i)
      ;
    ++i;
    if (i == st) {
      cnt = dr - st + 1;
      break;
    } else {
      for (j = st; j <= i && a[j] == a[st]; ++j)
        ;
      --j;
      if ((dr - i + 1 + j - st + 1) % k == 0) {
        dr = i - 1;
        st = j + 1;
      } else {
        if (dr - i + 1 + j - st + 1 > k) {
          int t = dr - i + 1, ck = k;
          dr -= min(t, k);
          ck -= min(t, k);
          t = j - st + 1;
          st += min(t, ck);
        } else
          break;
      }
    }
  }
  if (cnt == -1)
    cout << st - 1 + 1LL * (dr - st + 1) * m + n - dr << "\n";
  else {
    if ((1LL * (dr - st + 1) * m) % k == 0) {
      cout << "0\n";
    } else
      cout << st - 1 + n - dr + (1LL * (dr - st + 1) * m) % k << "\n";
  }
  return 0;
}
