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 n, k, m;
void pseq(list<int>& seq) {
  for (int a : seq) {
    cout << a << " ";
  }
  cout << endl;
}
bool _end = false;
int rem(list<int>& seq) {
  if (seq.size() == 0) {
    return 0;
  }
  int ret = 0;
  for (auto it = seq.begin(); it != seq.end(); it++) {
    int count = 0;
    for (auto jt = it; jt != seq.end(); jt++) {
      if (*jt == *it) {
        count++;
      } else {
        break;
      }
    }
    while (count >= k) {
      for (int i = 0; i < k; i++) {
        it = seq.erase(it);
      }
      count -= k;
      ret++;
    }
  }
  return ret;
}
int rem2(list<int>& seq1, list<int>& seq2, list<int>& seq3) {
  if (seq1.size() == 0 || seq2.size() <= 1 || seq3.size() == 0) {
    return 0;
  }
  auto it1 = seq1.end();
  it1--;
  auto it2 = seq2.begin();
  if (*it1 != *it2) {
    return 0;
  }
  int val = *it1;
  int count1 = 1;
  int count2 = 1;
  while (count1 + count2 < k) {
    if (it1 != seq1.begin() && *it1 == val) {
      it1--;
      if (*it1 == val) {
        count1++;
      }
    } else if (it2 != seq2.end() && *it2 == val) {
      it2++;
      if (it2 != seq2.end() && *it2 == val) {
        count2++;
      }
    } else {
      break;
    }
  }
  if (count1 + count2 == k) {
    for (int i = 0; i < count1; i++) {
      seq1.pop_back();
      seq2.pop_back();
    }
    for (int i = 0; i < count2; i++) {
      seq2.pop_front();
      seq3.pop_front();
    }
    return 1;
  } else {
    return 0;
  }
}
int rem3(list<int>& seq1, list<int>& seq2, list<int>& seq3) {
  if (seq1.size() == 0 || seq2.size() == 0 || seq3.size() == 0) {
    return 0;
  }
  int vals = seq2.front();
  for (auto it = seq2.begin(); it != seq2.end(); it++) {
    if (*it != vals) {
      return 0;
    }
  }
  auto it1 = seq1.end();
  int count1 = 0;
  while (true) {
    it1--;
    if (*it1 == vals) {
      count1++;
      if (it1 == seq1.begin()) {
        break;
      } else {
        it1--;
      }
    } else {
      break;
    }
  }
  auto it3 = seq3.begin();
  int count3 = 0;
  while (true) {
    if (*it3 == vals) {
      count3++;
      it3++;
      if (it3 == seq3.end()) {
        break;
      }
    } else {
      break;
    }
  }
  int sum = (count1 + seq2.size() * (m - 2) + count3);
  if (sum % k == 0) {
    _end = true;
    while (count1 > 0) {
      seq1.pop_back();
      count1--;
    }
    while (count3 > 0) {
      seq3.pop_front();
      count3--;
    }
  }
  return sum / k;
}
int rem4(list<int>& seq1, list<int>& seq2) {
  if (seq1.size() == 0 || seq2.size() == 0) {
    return 0;
  }
  int val = seq2.front();
  int count = 1;
  seq2.pop_front();
  while (seq1.size() > 0 && seq1.back() == val && count < k) {
    seq1.pop_back();
    count++;
  }
  while (seq2.size() > 0 && seq2.front() == val && count < k) {
    seq2.pop_front();
    count++;
  }
  if (count == k) {
    return 1;
  } else {
    return 0;
  }
}
int main() {
  cin >> n >> k >> m;
  bool bad_test = false;
  if (n == 3 && k == 2 && m == 10) {
    bad_test = true;
  }
  list<int> f_seq;
  list<int> m_seq;
  list<int> b_seq;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    f_seq.push_back(a);
    m_seq.push_back(a);
    b_seq.push_back(a);
  }
  long long ans = 0;
  while (true) {
    long long pans = ans;
    ans += rem(f_seq);
    ans += rem(m_seq) * (m - 2);
    ans += rem(b_seq);
    ans += rem2(f_seq, m_seq, b_seq) * (m - 1);
    if (pans == ans) {
      break;
    }
  }
  if (bad_test) {
    cout << ans << endl;
    pseq(f_seq);
    pseq(b_seq);
    cout << endl;
  }
  ans += rem3(f_seq, m_seq, b_seq);
  if (bad_test) {
    cout << ans << endl;
    pseq(f_seq);
    pseq(b_seq);
    cout << endl;
  }
  if (_end) {
    while (true) {
      long long pans = ans;
      ans += rem4(f_seq, b_seq);
      if (pans == ans) {
        break;
      }
    }
  }
  cout << n * m - ans * k << endl;
  return 0;
}
