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 long long inf = 9.2e18;
const int maxn = 2e5 + 70;
const int INF = 2.1e9;
const int maxm = 1e6 + 70;
const int MOD = 1e9 + 7;
const double eps = 1e-7;
const double PI = acos(-1.0);
int n, m, k;
int a[maxn], pre[maxn], nxt[maxn];
bool vis[maxn];
int main() {
  while (cin >> n >> k >> m) {
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i <= n; i++) {
      pre[i] = i - 1;
      nxt[i] = i + 1;
    }
    pre[0] = n;
    nxt[n] = 0;
    a[0] = -1;
    for (int i = 1; i <= n; i++) cin >> a[i];
    long long ans, sz = n;
    queue<int> Q;
    int p1 = 1, p2 = 1;
    while (p1 != 0) {
      int cnt = 0;
      while (a[p2] == a[p1]) {
        cnt++;
        p2 = nxt[p2];
        if (cnt == k) break;
      }
      if (cnt == k) {
        nxt[pre[p1]] = p2;
        pre[p2] = pre[p1];
        sz -= k;
        if (pre[p1] != 0) Q.push(pre[p1]);
        if (p2 != 0) Q.push(p2);
        while (p1 != p2) {
          vis[p1] = 1;
          p1 = nxt[p1];
        }
      }
      p1 = p2;
    }
    while (!Q.empty()) {
      p1 = Q.front();
      Q.pop();
      if (vis[p1]) continue;
      p2 = p1;
      int cnt = 0;
      while (a[p2] == a[p1]) {
        cnt++;
        p2 = nxt[p2];
        if (cnt == k) break;
      }
      if (cnt == k) {
        nxt[pre[p1]] = p2;
        pre[p2] = pre[p1];
        sz -= k;
        if (pre[p1] != 0) Q.push(pre[p1]);
        if (p2 != 0) Q.push(p2);
        while (p1 != p2) {
          vis[p1] = 1;
          p1 = nxt[p1];
        }
      }
    }
    if (m == 1)
      cout << sz << endl;
    else {
      long long t = 0;
      while (sz) {
        p1 = nxt[0];
        p2 = p1;
        int cnt = 0;
        while (a[p2] == a[p1]) {
          cnt++;
          p2 = nxt[p2];
        }
        if (cnt == sz) {
          ans = (sz * m) % k ? (sz * m) % k + t : 0;
          break;
        } else if (a[pre[0]] != a[nxt[0]]) {
          ans = sz * m + t;
          break;
        } else {
          int p3 = pre[0];
          int p4 = p3;
          int cnt2 = 0;
          while (a[p4] == a[p3]) {
            cnt2++;
            p4 = pre[p4];
          }
          if ((cnt + cnt2) % k) {
            ans = (sz * m + t) - ((long long)(cnt + cnt2) / k) * k * (m - 1);
            break;
          } else {
            sz -= (cnt + cnt2);
            t += (cnt + cnt2);
            nxt[0] = p2;
            pre[p2] = 0;
            pre[0] = p4;
            nxt[p4] = 0;
          }
        }
      }
      if (!sz) ans = 0;
      cout << ans << endl;
    }
  }
  return 0;
}
