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 double pi = acos(-1.0);
const double eps = 1e-12;
const int MOD = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e3 + 4;
const int maxm = 1e3 + 4;
inline long long rule(long long x) { return (x %= MOD) += x < 0 ? MOD : 0; }
vector<int> v;
int same(vector<int>& v) {
  for (int i = 1; i < v.size(); ++i)
    if (v[i] != v[0]) return -1;
  return v[0];
}
long long n, K, m, a, b, c, d;
vector<int> solve(vector<int> v) {
  stack<int> kind, cnt;
  int tmp = 0;
  a = 0, c = 0;
  for (int i = 0; i < v.size(); ++i) {
    a++;
    if (kind.size() == 0) {
      kind.push(v[i]);
      tmp = 1;
    } else if (kind.top() == v[i]) {
      tmp++;
      if (tmp == K) {
        c += K;
        if (c >= n) continue;
        kind.pop();
        a -= K;
        b = a;
        if (kind.size()) {
          tmp = cnt.top();
          cnt.pop();
        } else
          tmp = 0;
      }
    } else {
      cnt.push(tmp);
      kind.push(v[i]);
      tmp = 1;
    }
  }
  if (tmp != 0) cnt.push(tmp);
  v.clear();
  while (kind.size()) {
    int tmp = cnt.top();
    for (int i = 0; i < tmp; ++i) v.push_back(kind.top());
    kind.pop();
    cnt.pop();
  }
  reverse(v.begin(), v.end());
  return v;
}
int main() {
  int ik, i, j, k, kase;
  scanf("%lld%lld%lld", &n, &K, &m);
  for (int i = 0; i < n; ++i) {
    int j;
    scanf("%d", &j);
    v.push_back(j);
  }
  if (same(v) != -1) {
    printf("%lld\n", n * m % K);
    return 0;
  }
  if (K >= n) {
    printf("%lld\n", n * m);
    return 0;
  }
  v = solve(v);
  if (v.size() == 0) {
    puts("0");
    return 0;
  }
  long long tot = 1LL * v.size() * m;
  vector<int> vv = v;
  for (int i = 0; i < v.size(); ++i) vv.push_back(v[i]);
  n = v.size();
  if (same(v) != -1) {
    printf("%lld\n", n * m % K);
    return 0;
  }
  vv = solve(vv);
  if ((vv.size() == 2 * v.size()) || m == 1) {
    printf("%lld\n", tot);
    return 0;
  }
  if (vv.size() == 0) {
    if (m & 1)
      printf("%lld\n", 1LL * v.size());
    else
      puts("0");
    return 0;
  }
  tot -= (1LL * 2 * v.size() - vv.size()) * (m - 1);
  long long len = vv.size();
  a = len - b;
  c = 1LL * v.size() - b;
  d = a - c;
  vector<int> v1, v2, v3;
  for (int i = 0; i < b - d; ++i) v1.push_back(vv[i]);
  for (int i = b - d; i < b + d; ++i) v2.push_back(vv[i]);
  for (int i = b + d; i < vv.size(); ++i) v3.push_back(vv[i]);
  if (same(v2) != -1) {
    long long tmp = d * m;
    long long e = tmp % K;
    for (int i = 0; i < e; ++i) v1.push_back(v2[0]);
    for (int i = 0; i < v3.size(); ++i) v1.push_back(v3[i]);
    v1 = solve(v1);
    printf("%lld\n", 1LL * v1.size());
  } else {
    printf("%lld\n", tot);
  }
  return 0;
}
