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 gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = ((res % p) * (x % p)) % p;
    y = y >> 1;
    x = ((x % p) * (x % p)) % p;
  }
  return res;
}
long long raichu(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = ((res) * (x));
    y = y >> 1;
    x = ((x) * (x));
  }
  return res;
}
bool isprime(long long n) {
  if (n < 2)
    return false;
  else if (n == 2)
    return true;
  else if (n % 2 == 0)
    return false;
  else {
    long long z = sqrt(n);
    for (long long i = 0; i < z - 1; i++)
      if (n % (i + 2) == 0) return false;
    return true;
  }
}
long long ans = 0;
vector<long long> F, B;
vector<long long> z;
void solve(vector<long long> &a, long long k, long long m) {
  stack<pair<long long, long long> > s;
  z.clear();
  F.clear();
  B.clear();
  long long n = (long long)a.size();
  for (long long i = 0; i < n; i++) {
    long long cnt = 0, idx = i;
    while (idx < n && a[i] == a[idx]) {
      idx++;
      cnt++;
    }
    if (!s.empty() && s.top().first == a[i]) {
      cnt += s.top().second;
      s.pop();
    }
    long long left = cnt - (cnt / k) * k;
    if (left > 0) s.push(make_pair(a[i], left));
    idx--;
    i = idx;
  }
  if (s.empty()) {
    return;
  }
  while (!s.empty()) {
    pair<long long, long long> cur = s.top();
    s.pop();
    for (long long i = 0; i < cur.second; i++) z.push_back(cur.first);
  }
  reverse(z.begin(), z.end());
  long long st = 0, en = (long long)z.size() - 1;
  if (m == 1) {
    ans += ((long long)z.size());
    return;
  }
  while (true) {
    if (en - st + 1 == 0)
      return;
    else if (en - st + 1 == 1) {
      ans += (m - (m / k) * k);
      return;
    } else {
      if (z[st] == z[en]) {
        long long cnt1 = 0, cnt2 = 0;
        long long idx = st;
        while (idx <= en && z[idx] == z[st]) {
          idx++;
          cnt1++;
        }
        if (cnt1 == en - st + 1) {
          long long total = m * 1LL * (en - st + 1);
          ans += (total - (total / k) * k);
          return;
        } else {
          idx = en;
          while (idx >= st && z[idx] == z[en]) {
            idx--;
            cnt2++;
          }
          long long cnt = cnt1 + cnt2;
          if (cnt % k == 0) {
            for (long long i = 0; i < cnt1; i++) F.push_back(a[st]);
            for (long long i = 0; i < cnt2; i++) B.push_back(a[en]);
            st += cnt1;
            en -= cnt2;
          } else {
            ans += (cnt + m * 1LL * (en - st + 1 - cnt) +
                    (cnt - (cnt / k) * k) * 1LL * (m - 1));
            return;
          }
        }
      } else {
        ans += (m * 1LL * (en - st + 1));
        return;
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tests = 1, Tests;
  Tests = tests;
  while (tests--) {
    long long n, k, m;
    cin >> n >> k >> m;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    solve(a, k, m);
    vector<long long> P = F;
    reverse(B.begin(), B.end());
    for (long long i = 0; i < (long long)B.size(); i++) P.push_back(B[i]);
    if (ans == 0)
      solve(P, k, 1);
    else
      ans += (long long)P.size();
    cout << ans << endl;
  }
  return 0;
}
