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;
vector<pair<int, int> > solve(vector<int> v, int K) {
  int N = v.size();
  vector<pair<int, int> > seq;
  for (int i = 0; i < N; ++i) {
    if (seq.empty() || seq.back().first != v[i]) {
      seq.push_back(make_pair(v[i], 1));
    } else {
      ++seq.back().second;
      if (seq.back().second == K) seq.pop_back();
    }
  }
  return seq;
}
vector<int> repeat(vector<int> v, int n) {
  vector<int> ans(v.size() * n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < v.size(); ++j) {
      ans[i * v.size() + j] = v[j];
    }
  }
  return ans;
}
int getsum(vector<pair<int, int> > v) {
  int sum = 0;
  for (pair<int, int> i : v) {
    sum += i.second;
  }
  return sum;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N, K, M;
  cin >> N >> K >> M;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  if (M == 1) {
    vector<pair<int, int> > res = solve(A, K);
    int sum = getsum(res);
    cout << sum << endl;
  } else {
    vector<pair<int, int> > res2 = solve(repeat(A, 2), K);
    vector<pair<int, int> > res3 = solve(repeat(A, 3), K);
    long long s2 = getsum(res2);
    long long s3 = getsum(res3);
    if (res2 == res3) {
      cout << s2 << endl;
    } else if (res2.size() == 1) {
      cout << ((s3 - s2 + K) * (M - 2) + s2) % K << endl;
    } else {
      int L = 0, R = 0;
      while (L != res2.size() && L != res3.size() && res2[L] == res3[L]) {
        ++L;
      }
      if (R != res2.size() && R != res3.size() &&
          res2[res2.size() - R - 1] != res3[res3.size() - R - 1]) {
        ++R;
      }
      if (L + R + 1 >= res2.size() && L + R + 1 >= res3.size()) {
        long long m2 = (res2.size() == L + R ? 0 : res2[L].second);
        long long m3 = (res3.size() == L + R ? 0 : res3[L].second);
        long long other = s2 - m2;
        cout << other + ((m3 - m2 + K) * (M - 2) + m2) % K << endl;
      } else {
        cout << (s3 - s2) * (M - 2) + s2 << endl;
      }
    }
  }
  return 0;
}
