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;
long long M;
int A[100004];
struct IdCount {
  int id, cnt;
};
long long solve() {
  if (M <= 3) {
    vector<IdCount> B;
    for (int m = 0, _n = (M); m < _n; ++m) {
      for (int i = 0, _n = (N); i < _n; ++i) {
        if (B.empty() || A[i] != B.back().id)
          B.push_back({A[i], 1});
        else
          B.back().cnt = (B.back().cnt + 1) % K;
        if (B.back().cnt == 0) B.pop_back();
      }
    }
    long long res = 0;
    for (auto x : B) res += x.cnt;
    return res;
  }
  vector<IdCount> B;
  for (int i = 0, _n = (N); i < _n; ++i) {
    if (B.empty() || A[i] != B.back().id)
      B.push_back({A[i], 1});
    else
      B.back().cnt = (B.back().cnt + 1) % K;
    if (B.back().cnt == 0) B.pop_back();
  }
  if (1) {
    for (auto x : B) fprintf(stderr, "%d,%d ", x.id, x.cnt);
    fprintf(stderr, "\n");
  }
  if (int((B).size()) == 0) return 0;
  if (int((B).size()) == 1) {
    return (B[0].cnt * M) % K;
  }
  if (int((B).size()) == 2) {
    long long res = 0;
    for (auto x : B) res += x.cnt;
    res *= M;
    return res;
  }
  long long res = 0;
  int L = 0, R = int((B).size()) - 1;
  for (; L < R; ++L, --R) {
    if (B[L].id != B[R].id) {
      long long sum_mid = 0;
      for (int i = (L), _b = (R); i <= _b; ++i) {
        sum_mid += B[i].cnt;
      }
      res += sum_mid * M;
      long long sum_ext = 0;
      for (int i = (0), _b = (L - 1); i <= _b; ++i) sum_ext += B[i].cnt;
      res += sum_ext * 2;
      return res;
    }
    long long sum = B[L].cnt + B[R].cnt;
    sum %= K;
    if (sum != 0) {
      res += sum * (M - 1);
      long long sum_mid = 0;
      for (int i = (L + 1), _b = (R - 1); i <= _b; ++i) {
        sum_mid += B[i].cnt;
      }
      res += sum_mid * M;
      long long sum_ext = 0;
      for (int i = (0), _b = (L); i <= _b; ++i) sum_ext += B[i].cnt;
      res += sum_ext * 2;
      return res;
    }
  }
  return 0;
}
int main(int argc, char* argv[]) {
  scanf("%d %d %lld", &N, &K, &M);
  for (int i = 0, _n = (N); i < _n; ++i) scanf("%d", A + i);
  long long res = solve();
  printf("%lld\n", res);
  return 0;
}
