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 ar[100005];
long long n, k, m;
vector<pair<long long, long long> > ans;
void brute() {
  ans.clear();
  long long p = ar[0];
  long long c = 1;
  for (int i = 0; i < (int)(m); i++) {
    for (int j = 0; j < (int)(n); j++) {
      if (i == 0 && j == 0) continue;
      if (ar[j] == p) {
        c++;
      } else {
        long long vv = c % k;
        if (vv != 0) {
          ans.push_back(make_pair(p, vv));
          p = ar[j];
          c = 1;
        } else if (ans.size() > 0 && ans[ans.size() - 1].first == ar[j]) {
          p = ar[j];
          c = ans[ans.size() - 1].second + 1;
          ans.pop_back();
        } else {
          p = ar[j];
          c = 1;
        }
      }
    }
  }
  long long vv = c % k;
  ans.push_back(make_pair(p, vv));
  long long left = 0;
  for (int q = 0; q < (int)(ans.size()); q++) {
    long long c = ans[q].second;
    left += c % k;
  }
  cout << left;
}
vector<pair<long long, long long> > zz;
void solve() {
  cin >> n >> k >> m;
  for (int i = 0; i < (int)(n); i++) {
    cin >> ar[i];
  }
  if ((long long)(n)*m <= 5e5) {
    brute();
    return;
  }
  {
    long long p = ar[0];
    long long c = 1;
    for (int j = 0; j < (int)(n); j++) {
      if (j == 0) continue;
      if (ar[j] == p) {
        c++;
      } else {
        long long vv = c % k;
        if (vv != 0) {
          ans.push_back(make_pair(p, vv));
          p = ar[j];
          c = 1;
        } else if (ans.size() > 0 && ans[ans.size() - 1].first == ar[j]) {
          p = ar[j];
          c = ans[ans.size() - 1].second + 1;
          ans.pop_back();
        } else {
          p = ar[j];
          c = 1;
        }
      }
    }
    long long vv = c % k;
    ans.push_back(make_pair(p, vv));
  }
  long long i = 0;
  long long j = (long long)ans.size() - 1;
  while (i < j) {
    if (ans[i].first == ans[j].first) {
      long long content = ans[i].second + ans[j].second;
      if (content % k == 0) {
        i++, j--;
      } else {
        break;
      }
    } else {
      break;
    }
  }
  if (i == j) {
    long long totalcount = (long long)(m)*ans[i].second;
    long long ANS = totalcount % k;
    if (ANS == 0) {
      long long qqq = 0;
      for (long long q = 0; q < ans.size(); q++) {
        if (q != i) {
          long long cnt = ans[q].second;
          while (cnt--) {
            ar[qqq++] = ans[q].first;
          }
        }
      }
      n = qqq;
      m = 1;
      ans.clear();
      brute();
      return;
    } else {
      for (long long q = 0; q < ans.size(); q++) {
        if (q != i) {
          zz.push_back(ans[q]);
        } else {
          zz.push_back(make_pair(ans[i].first, ANS));
        }
      }
      ANS = 0;
      for (int q = 0; q < (int)(zz.size()); q++) {
        long long c = zz[q].second;
        ANS += c % k;
      }
      cout << ANS;
      return;
    }
  }
  long long ANS = 0;
  if (i < j) {
    if (ans[i].first == ans[j].first) {
      long long content = ans[i].second + ans[j].second;
      content %= k;
      ANS += content;
      for (long long k = i + 1; k < j; k++) {
        ANS += ans[k].second;
      }
      ANS = ANS * (m - 2);
      ANS += content;
      for (long long q = 0; q < j; q++) {
        ANS += ans[q].second;
      }
      for (long long q = i + 1; q < ans.size(); q++) {
        ANS += ans[q].second;
      }
    } else {
      for (long long k = i; k <= j; k++) {
        ANS += ans[k].second;
      }
      ANS = ANS * (m - 2);
      for (long long q = 0; q <= j; q++) {
        ANS += ans[q].second;
      }
      for (long long q = i; q < ans.size(); q++) {
        ANS += ans[q].second;
      }
    }
  }
  cout << ANS;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  int TC = 1;
  for (int ZZ = 1; ZZ <= TC; ZZ++) {
    solve();
  }
  return 0;
}
