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;
int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &k, &m);
  int a[100005];
  int same = 1;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (i != 0 && a[i] != a[i - 1]) same = 0;
  }
  if (same) {
    printf("%I64d\n", (long long)n * m % k);
  } else if (n < k) {
    printf("%I64d\n", (long long)n * m);
  } else {
    vector<pair<int, int> > re, re2;
    vector<pair<int, int> > v;
    int size[15];
    int sum = 0;
    for (int t = 0; t < 10; t++) {
      for (int i = 0; i < n; i++) {
        if (v.empty())
          v.push_back(make_pair((a[i]), (1)));
        else {
          if (v.back().first == a[i])
            v.back().second++;
          else
            v.push_back(make_pair((a[i]), (1)));
          v.back().second %= k;
          if (v.back().second == 0) v.pop_back(), sum -= k;
        }
        sum++;
      }
      if (t == 0) re = v;
      if (t == 1) re2 = v;
      size[t] = sum;
    }
    if (size[1] == 0) {
      printf("%d\n", m % 2 ? size[0] : 0);
    } else {
      int index = 0;
      int num[100005];
      for (int i = 0; i < re.size(); i++) {
        while (re[i].second != 0) {
          re[i].second--;
          num[index++] = re[i].first;
        }
      }
      int r = 0, l = index - 1, now = 0;
      vector<pair<int, int> > temp = re2;
      for (; r < index; r++) {
        if (re2[now].first != num[r]) {
          break;
        }
        re2[now].second--;
        if (re2[now].second == 0) {
          now++;
        }
      }
      re2 = temp;
      now = re2.size() - 1;
      for (; l >= 0; l--) {
        if (re2[now].first != num[l]) {
          break;
        }
        re2[now].second--;
        if (re2[now].second == 0) {
          now--;
        }
      }
      l++;
      r--;
      int ss = 1;
      for (int i = l + 1; i <= r; i++) {
        if (a[i] != a[i - 1]) ss = 0;
      }
      if (ss == 0) {
        printf("%I64d\n", size[1] + (long long)(r - l + 1) * (m - 2));
      } else {
        vector<pair<long long, long long> > res;
        res.clear();
        for (int i = 0; i < index; i++) {
          if (i == l) {
            if (res.back().first == a[l]) {
              res.back().second += (long long)(r - l + 1) * m;
            } else
              res.push_back(make_pair((a[l]), ((long long)(r - l + 1) * m)));
            res.back().second %= k;
            if (res.back().second == 0) res.pop_back();
            i = r;
            continue;
          }
          if (res.empty())
            res.push_back(make_pair((num[i]), (1)));
          else {
            if (res.back().first == num[i])
              res.back().second++;
            else
              res.push_back(make_pair((num[i]), (1)));
            res.back().second %= k;
            if (res.back().second == 0) res.pop_back();
          }
        }
        long long ans = 0;
        for (int i = 0; i < res.size(); i++) ans += res[i].second;
        printf("%I64d\n", ans);
      }
    }
  }
}
