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 int N = 100010;
int n, k, m, a[N], b[N * 2];
void get(int *a, int n, stack<pair<int, long long> > &q) {
  int nown = -1;
  long long now = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != nown) {
      if (nown != -1) q.push({nown, now});
      nown = a[i];
      now = 1;
    } else {
      now++;
      if (now % k == 0) {
        if (!q.empty()) {
          pair<int, long long> tp = q.top();
          q.pop();
          nown = tp.first;
          now = tp.second;
        } else {
          nown = -1;
          now = 0;
        }
      }
    }
  }
  if (nown != -1) q.push({nown, now});
  long long ans = 0;
  while (!q.empty()) {
    ans += q.top().second;
    q.pop();
  }
  printf("%lld\n", ans);
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  stack<pair<int, long long> > q;
  if (m == 1)
    get(a, n, q);
  else if (m == 2) {
    for (int i = 0; i < 2 * n; i++) b[i] = a[i % n];
    get(b, 2 * n, q);
  } else {
    deque<pair<int, int> > dq;
    long long tt = 0;
    int nown = -1;
    long long now = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] != nown) {
        if (nown != -1) q.push({nown, now});
        nown = a[i];
        now = 1;
      } else {
        now++;
        if (now % k == 0) {
          if (!q.empty()) {
            pair<int, long long> tp = q.top();
            q.pop();
            nown = tp.first;
            now = tp.second;
          } else {
            nown = -1;
            now = 0;
          }
        }
      }
    }
    if (nown != -1) q.push({nown, now});
    while (!q.empty()) {
      dq.push_front(q.top());
      tt += q.top().second;
      q.pop();
    }
    deque<pair<int, long long> > q1, q2;
    while (dq.size() > 1) {
      pair<int, long long> t1 = dq.front();
      pair<int, long long> t2 = dq.back();
      if (t1.first == t2.first) {
        dq.pop_back();
        dq.pop_front();
        if ((t1.second + t2.second) % k) {
          t1.second = (t1.second + t2.second) % k;
          dq.push_front(t1);
          break;
        } else {
          q1.push_back(t1);
          q2.push_front(t2);
        }
      } else
        break;
    }
    if (dq.size() == 1) {
      long long t = 0;
      t = dq.front().second;
      t *= m;
      t %= k;
      if (t) q1.push_back({dq.front().first, t});
      while (!q2.empty()) {
        q1.push_back(q2.front());
        q2.pop_front();
      }
      while (!q1.empty()) {
        q2.push_back(q1.front());
        q1.pop_front();
      }
      stack<pair<int, long long> > s;
      int nown = -1;
      long long now = 0;
      while (!q2.empty()) {
        if (q2.front().first == nown) {
          now = now + q2.front().second;
          now %= k;
          if (now == 0) {
            if (!q1.empty()) {
              nown = q1.back().first;
              now = q1.back().second;
              q1.pop_back();
            } else {
              nown = -1;
              now = 0;
            }
          }
        } else {
          if (nown != -1) q1.push_back({nown, now});
          nown = q2.front().first;
          now = q2.front().second;
        }
        q2.pop_front();
      }
      if (nown != -1) q1.push_back({nown, now});
      nown = -1;
      now = 0;
      while (!q1.empty()) {
        if (q1.front().first == nown) {
          now++;
          if (now % k == 0) {
            if (!s.empty()) {
              nown = s.top().first;
              now = s.top().second;
              s.pop();
            } else {
              nown = -1;
              now = 0;
            }
          }
        } else {
          if (nown != -1) s.push({nown, now});
          nown = q1.front().first;
          now = q1.front().second;
        }
        q1.pop_front();
      }
      if (nown != -1) s.push({nown, now});
      long long ans = 0;
      while (!s.empty()) {
        ans += s.top().second;
        s.pop();
      }
      printf("%lld\n", ans);
    } else {
      long long t = 0;
      while (!dq.empty()) {
        t += dq.front().second;
        dq.pop_front();
      }
      printf("%lld\n", tt + t * (m - 1));
    }
  }
}
