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 (int i = 0; i < z - 1; i++)
      if (n % (i + 2) == 0) return false;
    return true;
  }
}
long long ans = 0;
int frnt = 0, bck = 0;
vector<int> z;
void solve(vector<int> &a, int k, int m) {
  stack<pair<int, int> > s;
  z.clear();
  int n = (int)a.size();
  for (int i = 0; i < n; i++) {
    int 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();
    }
    int left = cnt - (cnt / k) * k;
    if (left > 0) s.push(make_pair(a[i], left));
    idx--;
    i = idx;
  }
  if (s.empty()) {
    a = z;
    return;
  }
  bool one = false;
  if ((int)s.size() == 1) one = true;
  while (!s.empty()) {
    pair<int, int> cur = s.top();
    s.pop();
    for (int i = 0; i < cur.second; i++) z.push_back(cur.first);
  }
  reverse(z.begin(), z.end());
  if (one) {
    long long total = (int)z.size() * 1LL * m;
    ans += (total - (total / k) * k);
    z.clear();
    a = z;
    return;
  } else {
    if (m == 1) {
      ans += (m * 1LL * (int)z.size());
      z.clear();
      a = z;
      return;
    } else if (z[0] == z[(int)z.size() - 1]) {
      int idx = 0;
      int cnt1 = 0;
      while (idx < (int)z.size() && z[idx] == z[0]) {
        idx++;
        cnt1++;
      }
      idx = (int)z.size() - 1;
      int cnt2 = 0;
      while (idx >= 0 && z[idx] == z[(int)z.size() - 1]) {
        idx--;
        cnt2++;
      }
      int cnt = cnt1 + cnt2;
      if (cnt % k == 0) {
        frnt += cnt1;
        bck += cnt2;
        while (cnt2--) z.pop_back();
        reverse(z.begin(), z.end());
        while (cnt1--) z.pop_back();
        reverse(z.begin(), z.end());
        a = z;
        int st = 0, en = (int)a.size() - 1;
        while (true) {
          if (en - st + 1 == 0)
            break;
          else if (en - st + 1 == 1) {
            a.clear();
            ans += (m - (m / k) * k);
            break;
          } else {
            if (a[st] == a[en]) {
              int CNT1 = 0, CNT2 = 0;
              int IDX = 0;
              while (IDX <= en && a[IDX] == a[st]) {
                IDX++;
                CNT1++;
              }
              if (CNT1 == en - st + 1) {
                long long total = m * 1LL * (en - st + 1);
                ans += (total - (total / k) * k);
                a.clear();
                break;
              } else {
                IDX = en;
                while (IDX >= st && a[idx] == a[en]) {
                  IDX--;
                  CNT2++;
                }
                int CNT = CNT1 + CNT2;
                if (CNT % k == 0) {
                  ans += (CNT);
                  st += CNT1;
                  en -= CNT2;
                } else {
                  ans += (CNT + m * 1LL * (en - st + 1 - CNT) +
                          (CNT - (CNT / k) * k) * 1LL * (m - 1));
                  a.clear();
                  break;
                }
              }
            } else {
              ans += (m * 1LL * (int)a.size());
              a.clear();
              break;
            }
          }
        }
        return;
      } else {
        ans += (cnt + m * 1LL * ((int)z.size() - cnt) +
                (cnt - (cnt / k) * k) * 1LL * (m - 1));
        z.clear();
        a = z;
        return;
      }
    } else {
      ans += (m * 1LL * (int)z.size());
      z.clear();
      a = z;
      return;
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tests = 1, Tests;
  Tests = tests;
  while (tests--) {
    int n, k, m;
    cin >> n >> k >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    solve(a, k, m);
    if (ans == 0) {
      int cnt = frnt + bck;
      cnt = cnt - (cnt / k) * k;
      ans += cnt;
    } else {
      ans += (frnt + bck);
    }
    cout << ans << endl;
  }
  return 0;
}
